Create a board class

Assignment Help Other Subject
Reference no: EM131103075

Create a Board class using the following code and change the main function so that it uses your class instead of the data and functions it currently uses.

You should not include game-specific code (i.e. TicTacToe code) in your Board class. Your Board class should only include the actual board data (char **data) and the size of the board (int rows, cols) and the functions that operate only on that data. That way, we can reuse our board class for another game.

#include <iostream>
#include <iomanip>
usingnamespacestd;

voidset(char**data,introw,intcol,charvalue)
{
data[row][col]=value;
}

charget(char**data,introw,intcol)
{
returndata[row][col];
}

voidprintLine(intcols)
{
cout<<" ";
for(size_ti=0;i<cols;i++)
{
cout<<"+---";
}
cout<<"+n";
}

voidprint(char**data,introws,intcols)
{
cout<<" ";
for(size_ti=0;i<cols;i++)
{
cout<<" "<<char('A'+i)<<" ";
}
cout<<"n";
for(size_ti=0;i<rows;i++)
{
printLine(cols);
cout<<setw(2)<<i+1<<" ";
for(size_tj=0;j<cols;j++)
{
cout<<"| "<<data[i][j]<<" ";
}
cout<<"|n";
}
printLine(cols);
}

// assumes a 3x3 board
boolcheckGameOverTicTacToe(char**board,charplayer)
{
boolhasEmpty=false;
for(size_ti=0;i<3;i++)
{
for(size_tj=0;j<3&&!hasEmpty;j++)
{
if(get(board,i,j)==' ')
hasEmpty=true;
}
if((get(board,i,0)!=' '&&get(board,i,0)==get(board,i,1)&&get(board,i,1)==get(board,i,2))||(get(board,0,i)!=' '&&get(board,0,i)==get(board,1,i)&&get(board,1,i)==get(board,2,i)))
{
print(board,3,3);
cout<<player<<" wins!n";
returntrue;
}
}
if((get(board,0,0)!=' '&&get(board,0,0)==get(board,1,1)&&get(board,1,1)==get(board,2,2))||(get(board,2,0)!=' '&&get(board,2,0)==get(board,1,1)&&get(board,1,1)==get(board,0,2)))
{
print(board,3,3);
cout<<player<<" wins!n";
returntrue;
}
if(!hasEmpty)
{
print(board,3,3);
cout<<"Tie!n";
returntrue;
}
returnfalse;
}

intmain()
{
// board properties
introws=3;
intcols=3;
// construct the board
char**data=newchar*[rows];
for(inti=0;i<rows;i++)
{
data[i]=newchar[cols];
for(intj=0;j<cols;j++)
data[i][j]=' ';
}
// game loop
charplayer='o';
while(!checkGameOverTicTacToe(data,player))
{
if(player=='x')
player='o';
else
player='x';
print(data,rows,cols);
size_t row,col;
cout<<player<<", enter a row and col: ";
cin>>row>>col;
while(row>2||col>2||get(data,row,col)!=' ')
{
cout<<"Please enter a valid row and col: ";
cin>>row>>col;
}
set(data,row,col,player);
}
return0;
}

Reference no: EM131103075

Questions Cloud

What are the distinctions among them : Revenues, gains, and investments by owners are all increases in net assets. What are the distinctions among them?
Developing the project plan and determining critical path : Using the District4WarehouseMove WBS.xls provided, create a project plan for the District 4 Warehouse Move project. Use the PDF document, Project Plan Check - District4Move, to check your work to be sure you have created your starting project plan..
What is the output of the given program : What is the output of the following program
What are the distinctions among them : Expenses, losses, and distributions to owners are all decreases in net assets. What are the distinctions among them?
Create a board class : Create a Board class using the following code and change the main function so that it uses your class instead of the data and functions it currently uses.
Five years minimum experience working in the business : Interview and write a paper on someone who has five years minimum experience working in the business world and who is a leader and has direct reports (people they manage) so that you can question them on their development and how they develop other..
Why is it necessary to develop a definitional framework : Why is it necessary to develop a definitional framework for the basic elements of accounting?
Why did the artist use these materials or techniques : A description of the materials, media, or techniques used by the artists; why did the artist use these materials or techniques? What is the overall effect of the artwork?
Analyze the behavior of spam-oriented botnets : BotLab is a platform at the University of Washington that continually monitors and analyzes the behavior of spam-oriented botnets. There are many other locations on the Internet that keep real-time activities of botnets across the globe.

Reviews

Write a Review

Other Subject Questions & Answers

  Innovations is a producer of electronic circuits

Innovations is a producer of electronic circuits that power a variety of technological devices  produced by other companies. Innovations sells its products to ________ markets.

  What types of recreational programs

Rebecca was hired to determine what types of recreational programs teenagers wanted and would use in the town of Methods, U.S.A. Rebecca was hired to conduct a?

  Difference between emotional and successful intelligence

Write down the difference between emotional intelligence and successful intelligence? Explain if it was a lack of emotional intelligence, successful intelligence, or both which caused his or her lack of judgment.

  The founders attitude toward government and power and what

the people who wrote the u.s. constitution the founders had definite ideas in mind in regard to power its potential for

  The class average on a statistics test is 60 with a

the class average on a statistics test is 60 with a standard deviation of 6. what minimum grade must a student obtain

  Watch beibut shumenov vs bernard hopkins live boxing

WaTcH Beibut Shumenov vs Bernard Hopkins Live Boxing

  What the critical success factor for custom living furniture

What are the critical success factors (CSF) for Custom Living Furniture? Place yourself in the owner's position based upon the facts of this case

  Discuss specific plans to terminate an unsuccessful solution

Nursing Research Utilization Project Proposal: Poster Presentation-Discuss methods and specific plans to revise an unsuccessful project solution. Discuss methods and specific plans to terminate an unsuccessful solution

  Rationale and purpose of the exclusionary rule

Write a 700- to 1,400-word paper in which you analyze the rationale and purpose of the Exclusionary Rule, as well as identify the exceptions to the Exclusionary Rule.

  Segment and list three specific businesses

Explain why you chose this segment and list three specific businesses that fall into this segment. Why might people be attracted to this segment over another?

  Research credit default swaps

Research credit default swaps.Write a one paragraph summary describing these instruments. Also, do you think they were the number one cause of the Financial Crisis of 2007? Write one paragraph supporting your opinion.

  Volcanic eruptions can melt snow and ice and

question 1 volcanic eruptions can melt snow and ice and causepyroclastic flows volcanic ash lahars laccolithsquestion 2

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd