TicTacToe_Example.cpp
#include "tictactoe.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
void HumanPlayer(TicTacToe *Game);
void RandomPlayer(TicTacToe *Game);
int main(int argc, char *argv[])
{
TicTacToe *Game=new TicTacToe;
srand ( time(NULL) );
Game->DrawGame();
while (Game->GameOver()==0) {
if (Game->CurrentPlayer()==CROSS) {
cout << "\n ::: Player 1 (Crosses) :::\n";
HumanPlayer(Game);
Game->DrawGame();
}
else {
cout << "\n::: Player 2 (Circles) :::\n";
RandomPlayer(Game);
Game->DrawGame();
}
}
std::cout << "\n ::: Game Over ::: \n\n";
Game->DrawGame();
switch (Game->GameOver()) {
case CROSS : cout << "\nCe sont les croix qui gagnent\n"; break;
case CIRCLE : cout << "\nCe sont les ronds qui gagnent\n"; break;
case DRAW : cout << "\nMatch nul !\n";
}
}
void RandomPlayer(TicTacToe *Game)
{
int Cell=-1;
do
Cell=random()%9+1;
while (Game->Play(Cell)==0);
}
void HumanPlayer(TicTacToe *Game)
{
int Cell=10;
do
{
cout << "Dans quelle case jouez-vous : ";
std::cin >> Cell;
}
while (Game->Play(Cell)==0);
}