Create a class TicTacToe that will enable you to write a
complete program to play the
game of Tic-Tac-Toe. The class contains as private data a 3-
by-3 double array of integers. The constructor
should initialize the empty board to all zeros. Allow two
human players. Wherever the first
player moves, place a 1 in the specified square; place a 2
wherever the second player moves. Each
move must be to an empty square. After each move determine
whether the game has been won and
whether the game is a draw. If you feel ambitious, modify
your program so that the computer makes
the moves for one of the players automatically. Also, allow
the player to specify whether he or she
wants to go first or second. If you feel exceptionally
ambitious, develop a program that will play
three-dimensional Tic-Tac-Toe on a 4-by-4-by-4
Answer Posted / usman ahmed
#include <iostream>
using namespace std;
const int boardSize = 3;
const int masksCounter = 8;
const bool mask[masksCounter][boardSize][boardSize] = {
{
{1, 1, 1},
{0, 0, 0},
{0, 0, 0}
},
{
{0, 0, 0},
{1, 1, 1},
{0, 0, 0}
},
{
{0, 0, 0},
{0, 0, 0},
{1, 1, 1}
},
{
{1, 0, 0},
{1, 0, 0},
{1, 0, 0}
},
{
{0, 1, 0},
{0, 1, 0},
{0, 1, 0}
},
{
{0, 0, 1},
{0, 0, 1},
{0, 0, 1}
},
{
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
},
{
{0, 0, 1},
{0, 1, 0},
{1, 0, 0}
}
};
enum {
None = 0,
Player1 = 1,
Player2 = 2,
Draw = 3
};
class TicTacToe {
public:
friend class Player; // Make Player class able to search in board field
TicTacToe();
bool set(int x, int y, int p);
int getStatus();
void displayBoard();
private:
// The class contains as private data a 3-by-3 two-dimensional array
// of integers.
int board[boardSize][boardSize];
}obj;
class Player {
public:
Player(int i, bool a = false) : id(i), artificial(a) {}
void move(TicTacToe & game);
private:
int id;
bool artificial;
};
void main()
{
obj.displayBoard();
system("pause");
}
| Is This Answer Correct ? | 13 Yes | 13 No |
Post New Answer View All Answers
Write a program to create a process in UNIX
WHAT IS THE MEANING OF CONSTANT ...EXEEDS LENGTH LIMIT WHILE COPYING FROM PS FILE TO KSDS
< DL Compact > tag is used for
hii I inntrested abt scjp certification but i dont knw abt scjp plz send details abt scjp exam and syllabus.
What is autocall macro and how to create autocall macro? what is the use of it?
Need provab technical test questions
what is difference between input parameter and output parameter.
What is the difference beween joblib and steplib statements
we create a pf with 3 fields.2 is defined as keyfields.we lock it with alcobj command.how we find out whether the file is locked or not?is it dspfd??/
code for connection from windows forms to sql server
Is buffer size and file block size is similar? If similar,at which case it will be same size?
differences between qtp10.0 and 11.0 ?
What is the difference between COM and CORBA?
10.Define filters,binary to hexadecimal,hexadecimal to decimal?
Iam using Microsoft Visual Studio to create a system for mobile store I want to know how to calculate mobile price that the customer buy and how to reduce quantity from the data base that we have for mobile .And also how to calculate revnue for each mobile and revnue for the total mobile