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


Please Help Members By Posting Answers For Below Questions

I have try to write a record in a TDQ from a fle.... what are the steps to do... can anybody plz come with a solution

2209


What do you understand by modular programming?

670


How to connect to ms word wit VB ojective is to prepare s/w to generate question paper , selects questions randomly from the ms access , database

2014


How do i find out the number of parameters passed into function?

2215


how to display xisheet in list box in c# .net

1627






what are resources in case of Threads

1665


what is the difference between uservariables and systemvariables (in Environmental variables)???

1938


why we use abstract word in abstract window toolkit in java language.

1767


When we use Windows authentication mode

1580


SELECT A~FTRMI A~AUFNR B~MATNR D~MAKTX B~PSMNG B~WEMNG C~MTART E~CHARG C~MATKL C~SPART R~BWART R~CHARG R~MATNR E~BWART R~BDMNG INTO TABLE ITAB FROM AFKO AS A INNER JOIN AFPO AS B ON A~AUFNR = B~AUFNR * INNER JOIN AFVC AS A1 ON A~AUFPL = A1~AUFPL AND B~DWERK = A1~WERKS INNER JOIN MARA AS C ON B~MATNR = C~MATNR INNER JOIN MAKT AS D ON C~MATNR = D~MATNR INNER JOIN MSEG AS E ON B~MATNR = E~MATNR AND A~AUFNR = E~AUFNR AND B~DWERK = E~WERKS INNER JOIN RESB AS R ON A~AUFNR = R~AUFNR AND E~AUFNR = R~AUFNR AND R~RSNUM = A~RSNUM AND R~WERKS = E~WERKS AND R~BAUGR = E~MATNR INNER JOIN MARA AS C1 ON R~MATNR = C1~MATNR WHERE A~FTRMI IN S_DATE AND A~AUFNR IN S_AUFNR AND C~MTART IN S_TYPE AND C~MATKL = 'T' AND R~BWART ='261' AND E~BWART = '101' AND R~XWAOK ='X' AND B~DWERK = '2000' AND R~XLOEK EQ SPACE AND E~KZBEW ='F' AND D~SPRAS = 'E' AND R~KZEAR = 'X' AND C~MATNR IN S_MATNR. This query gives repetative records from RESB.There must be some common field which i am not taking thats why its giving repetative records. If u find any solution pls lety me know ASAP. Thanks Swati Ghadge

2836


In mainframe SDSF, Can we copy the list of jobs currently executing in SDSF in to a seperate DATASET...?

1848


what is difference between object oriented programming structure and object oriented programming system?

1446


Find out the roles which gives access to all tables in SAP? Thanks in advance.

1562


what is difference between kpo and it industry? that is in terms of work, package etc

1538


iam confused among testing ,.net and java. can anybody help me.

1578