本文整理汇总了C++中TicTacToe类的典型用法代码示例。如果您正苦于以下问题:C++ TicTacToe类的具体用法?C++ TicTacToe怎么用?C++ TicTacToe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TicTacToe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: error_check
int error_check( int x, int y, TicTacToe board1 ) {
int err = 0 ;
err = board1.checkBoundry( x, y ) ;
if( err == 2 ) {
cout << "ERROR : The X coordinate you specified is out of the board." << endl ;
return 1 ;
}
if( err == 3 ) {
cout << "ERROR : The Y coordinate you specified is out of the board." << endl ;
return 2 ;
}
else {
err = board1.checkSpace( x, y ) ; //Check to see if a move is already there
if( err == 1 ) {
cout << "ERROR : There is already a move there." ;
return 3 ;
}
}
return 0 ;
}
示例2: main
int main()
{
TicTacToe g; // creates object g of class TicTacToe
g.makeMove(); // invokes function makeMove
system("pause");
return 0;
} // end main
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TicTacToe w;
w.show();
return a.exec();
}
示例4: main
int main(int argc, char *argv[])
{
Application app(argc, argv);
TicTacToe toe;
toe.setObjectName("toe");
app.setTicTacToe(&toe);
toe.show();
return app.exec();
}
示例5: info
/**
* @brief Función para consultar visualmente el estado de una partida
* @param ttt Referencia a la partida de la que se obtiene la información
* @return Un texto con los jugadores, a quién le toca el siguiente turno, y
* una representación en modo texto del estado del tablero, en la que
* las posiciones libres están señaladas con '-', las ocupadas por el
* jugador 1 con 'X', y las ocupadas por el jugador 2 con 'O'
*/
string t33_utils::info ( TicTacToe& ttt )
{
std::stringstream aux;
aux << "Jugador 1 (X): " << ttt.getJugador1 () << ".\t"
<< "Jugador 2 (O): " << ttt.getJugador2 () << std::endl
<< "Estado actual del tablero:" << std::endl
<< info ( ttt.getTablero () );
return ( aux.str () );
}
示例6: manualTesting
void manualTesting( NeuralNetAI& ai )
{
TicTacToeHuman human( 9, 9, 1, 1 );
TicTacToe game;
const int NUM_OF_GAMES = 10;
for( int i = 0; i < NUM_OF_GAMES; i++ )
{
TicTacToe::Token winner = game.match(ai, human );
verboseEndGame( winner );
}
}
示例7: main
int main()
{
TicTacToe game;
char player = 'X';
while(game.DetermineDraw() == false)
{
game.DrawBoard();
game.GetMove(player);
game.TogglePlayer(player);
}
system("pause");
}
示例8: main
int main()
{
/// Initialization
const unsigned int NUMBER_OF_GAMES = 1000; //-1 to play an infinite number of games
const std::string SAVE_FILE_X = "TicTacToeX.save";
const std::string SAVE_FILE_O = "TicTacToeO.save";
const bool VERBOSE_ENABLED = false; // if( VERBOSE_ENABLED ): the stats are calculated for playerO. Use with small NUMBER_OF_GAMES or with a human player
TicTacToe game;
CaseBasedAI playerX( 9, 9, 1, 1 );
TicTacToeHuman playerO( 9, 9, 1, 1 );
// CaseBasedAI playerO( 9, 9, 1, 1 );
std::cout << "start load" << std::endl;
GeneralAI::load< CaseBasedAI >( playerX, SAVE_FILE_X );
// GeneralAI::load< NeuralNetAI >( playerO, SAVE_FILE_O );
// GeneralAI::load< CaseBasedAI >( playerO, SAVE_FILE_O );
std::cout << "load completed" << std::endl;
std::cout << "start games" << std::endl;
/// Play games
for( unsigned int i = 0; i != NUMBER_OF_GAMES; i++ )
{
TicTacToe::Token winner;
winner = game.match( playerX, playerO );
if( VERBOSE_ENABLED )
{
if (!verboseEndGame( winner ) ) // false if must stop for some reason
{
break;
}
}
}
std::cout << "games completed" << std::endl;
std::cout << "start save" << std::endl;
GeneralAI::save< CaseBasedAI >( playerX, SAVE_FILE_X );
// GeneralAI::save< NeuralNetAI >( playerO, SAVE_FILE_O );
// GeneralAI::save< CaseBasedAI >( playerO, SAVE_FILE_O );
std::cout << "save completed" << std::endl;
return 0;
}
示例9: main
int main()
{
bool winner=false;//bool to assist with running the loop
TicTacToe grid;//construct
grid.print();
//runs the program continuously until someone has won or game is tied
while(winner==false)
{
grid.play_by_user();
grid.print();
//interprets the return value of win_check to see if anyone has won or not
if (grid.win_check()=='U')
{
cout<<"Congratulation! You won!";
winner=true;
}
if (grid.win_check()=='N')
{
cout<<"Game is over with no winner!"<<endl;
winner=true;
}
//if the user has won the the computer continues to play
if(winner==false)
{
grid.play_by_computer();
grid.print();
//interprets the return value of win_check to see if anyone has won or not
if (grid.win_check()=='C')
{
cout<<"Sorry, you lost!";
winner=true;
}
if (grid.win_check()=='N')
{
cout<<"Game is over with no winner!"<<endl;
winner=true;
}
}
}
system("pause");
return 0;
}
示例10: main
int main ()
{
//Create menu variable
int menuChoice = PLAY;
//Create turn variables
TicTacToe game;
char turn = PLAYER1;
int totalTurns = 0;
//Scoreboard tally
int xWin = 0;
int oWin = 0;
int tie = 0;
//Clear the Screen
clearScreen ();
while (menuChoice < QUIT && menuChoice >= PLAY) {
//Display Welcome Message
menuChoice = welcome ();
switch (menuChoice) {
case (PLAY):
totalTurns = 0;
while (!game.checkWinner (PLAYER1) & !game.checkWinner (PLAYER2)
& (totalTurns < SIZE * SIZE)) {
//Display Board
game.printBoard ();
//Take a Turn
takeTurn (game, turn);
totalTurns++;
//Switch turns
changeTurns (turn);
}
//Update Scoreboard and Display Victory Message
scoreUpdate (turn, totalTurns, xWin, oWin, tie);
//Clear the board for new game
game.resetBoard ();
case (SCORE):
displayScore (xWin, oWin, tie);
break;
case (QUIT):
goodbye ();
}
}
return 0;
}
示例11: doCompMove
void doCompMove( TicTacToe & t, bool firstMove )
{
static int gameNum = 0;
int bestRow, bestCol, bestVal;
if( !firstMove )
t.chooseMove( TicTacToe::COMPUTER, bestRow, bestCol );
else
{
gameNum++;
bestRow = gameNum % 3; bestCol = gameNum / 3;
}
cout << "Transposition table size is: " << t.getTransSize( ) << endl;
cout << "Computer plays: ROW = " << bestRow << " COL = " << bestCol << endl;
t.playMove( TicTacToe::COMPUTER, bestRow, bestCol );
}
示例12: main
//actual program
int main()
{
TicTacToe ttt;
const char players[2] = { 'X', 'O' };
int player = 1;
bool win = false;
bool full = false;
while (!win && !full)
{
player = 1 - player;
ttt.Display();
ttt.Turn(players[player]);
win = ttt.Win(players[player]);
full = ttt.Full();
}
ttt.Display();
if (win)
{
std::cout << "\n" << players[player] << " is the winner.\n";
}
else
{
std::cout << "Tie game.\n";
}
return 0;
}
示例13: playGame
void playGame( bool compGoesFirst )
{
TicTacToe t;
char compSide, humanSide;
int row, col;
if( compGoesFirst )
{
compSide = 'x'; humanSide = 'o';
doCompMove( t, true );
}
else
{
compSide = 'o'; humanSide = 'x';
}
while( !t.boardIsFull( ) )
{
do
{
printBoard( t, compSide, humanSide );
cout << endl << "Enter row and col (starts at 0): ";
cin >> row >> col;
} while( !t.playMove( TicTacToe::HUMAN, row, col ) );
cout << endl;
printBoard( t, compSide, humanSide );
cout << endl;
if( t.isAWin( TicTacToe::HUMAN ) )
{
cout << "Human wins!!" << endl;
break;
}
if( t.boardIsFull( ) )
{
cout << "Draw!!" << endl;
break;
}
doCompMove( t, false );
if( t.isAWin( TicTacToe::COMPUTER ) )
{
cout << "Computer wins!!" << endl;
break;
}
if( t.boardIsFull( ) )
{
cout << "Draw!!" << endl;
break;
}
}
printBoard( t, compSide, humanSide );
}
示例14: fitnessEval
// Task: Play TicTacToe
virtual double fitnessEval( NeuralNetAI& ai )
{
TicTacToe game;
double score = 0;
const int NUM_OF_GAMES = 10;
RandomAI opponent( INPUT_SIZE, OUTPUT_SIZE, INPUT_AMPLITUDE, OUTPUT_AMPLITUDE );
for( int i = 0; i < NUM_OF_GAMES; i++ )
{
TicTacToe::Token winner = game.match( ai, opponent );
if( winner == TicTacToe::Token::X )
{
score += 1;
}
else if( winner == TicTacToe::Token::O )
{
score -= 1;
}
}
return score;
}
示例15: comp_move_easy
void comp_move_easy( int &x, int &y, TicTacToe board1 ) {
int err ;
srand( time( NULL ) ) ;
while( 1 ) {
x = 1 + ( rand() % 3 ) ;
y = 1 + ( rand() % 3 ) ;
err = board1.checkBoundry( x, y ) ;
if( err == 0 ) break ;
}
return ;
}