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

One boy has to climb steps. He can climb 1 or 2 steps at a time. Write a function that will returns number of way a boy can climb the steps. Int WaytoSteps(int n) (eg:- suppose number of steps is n=4 ,the function will return 5 (one-one-one-one ,one-one-two, one-two-one-,two-one-one, two-two)

3001


how to remove header and footer in jcl using sort utility

5105


1.what is the vesition managment.

1686


I want Ada programming language books. Could anyone post me any link for that?

2954


is it acceptable if we declare multiple exceptions in same overridden method.

2113






what are the things i had to say in personal introduction in hr round mail me to prasanna.1867@rediff.com

1683


when we use mantis? how learn mantis?

1693


can we allocate memory for interface? if no then why?

1470


Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad

1849


Colors specified with the notation

1813


what will we require to build project with the help of oracle

1390


How to print No.of.rows affected after updation using ADO.Net

2481


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??/

1623


Please forward important interview and basic questions in VB6 on my email id: usneha_16@yahoo.co.in

1580


It is possible to take number of controls added to form at run-time.ex-when user enter 6, 6 text boxes get added to form,next time number of controls get change as per user number enter. What is code for that?

1511