Code programming language assignment

computer science

Description

<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#include

&lt;iostream&gt;

#include &lt;cassert&gt;

#include "ticTacToeBoard.h"

using namespace std;

int main() {

ticTacToeBoard b1;

initBoard(b1);

printBoard(b1);

int x, y;

//while board not full

while (!boardFull(b1)) {

//Ask for current player to make move

if (b1.curr_player == 1) cout &lt;&lt; "Player X";

else cout &lt;&lt; "Player O";

cout &lt;&lt; ", what is your move?\n";

//loop to get valid move.

do {

cin &gt;&gt; x; cin &gt;&gt; y;

//if move out of bound, get input agin

if ( !((1&lt;=x)&amp;&amp;(x&lt;=4)&amp;&amp;(1&lt;=y)&amp;&amp;(y&lt;=4)) ) {

cout &lt;&lt; "Out of bounds.\n";

continue;

}

//If empty make move

if (isEmpty(b1,x,y)) {

mark(b1,x,y);

break; //done with this move

} else {

cout &lt;&lt; "You can't play there.\n";//get input again

}

} while(true);

printBoard(b1);

if (winner(b1)!=0) break;//if there is a winner, exit

//Swap player

b1.curr_player *= -1;

}

//We're done either because there's a winner

//or because the board is full.

if (winner(b1)==1)

cout &lt;&lt; "X is the winner!\n";

else if (winner(b1)==-1)

cout &lt;&lt; "O is the winner!\n";

else

cout &lt;&lt; "The game is a tie!\n";

}

</pre></body></html>


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.