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

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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