本文整理汇总了C++中TicTacToe类的典型用法代码示例。如果您正苦于以下问题:C++ TicTacToe类的具体用法?C++ TicTacToe怎么用?C++ TicTacToe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TicTacToe类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 ;
}
开发者ID:ABZaxxon,项目名称:CS-School-Work,代码行数:29,代码来源:prog915.cpp
示例2: main
int main()
{
TicTacToe g; // creates object g of class TicTacToe
g.makeMove(); // invokes function makeMove
system("pause");
return 0;
} // end main
开发者ID:AlterTiton,项目名称:bcit-courses,代码行数:7,代码来源:Ex09_15.cpp
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TicTacToe w;
w.show();
return a.exec();
}
开发者ID:kcomputer,项目名称:homework,代码行数:8,代码来源:main.cpp
示例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();
}
开发者ID:GaoHongchen,项目名称:CPPGUIProgrammingWithQt4,代码行数:9,代码来源:main.cpp
示例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 () );
}
开发者ID:POOUJA,项目名称:teoria,代码行数:18,代码来源:utils.cpp
示例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 );
}
}
开发者ID:WebF0x,项目名称:StrongAI,代码行数:12,代码来源:main.cpp
示例7: main
int main()
{
TicTacToe game;
char player = 'X';
while(game.DetermineDraw() == false)
{
game.DrawBoard();
game.GetMove(player);
game.TogglePlayer(player);
}
system("pause");
}
开发者ID:bjonke,项目名称:tictactoe,代码行数:13,代码来源:main.cpp
示例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;
}
开发者ID:WebF0x,项目名称:StrongAI,代码行数:49,代码来源:main.cpp
示例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;
}
开发者ID:TannerW,项目名称:Some-School-Programs,代码行数:47,代码来源:Source.cpp
示例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;
}
开发者ID:,项目名称:,代码行数:46,代码来源:
示例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 );
}
开发者ID:anilpawar-pd,项目名称:Eclipse-for-Java,代码行数:17,代码来源:TicTac.cpp
示例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;
}
开发者ID:GokuMizuno,项目名称:TicTacToe,代码行数:30,代码来源:main.cpp
示例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 );
}
开发者ID:anilpawar-pd,项目名称:Eclipse-for-Java,代码行数:54,代码来源:TicTac.cpp
示例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;
}
开发者ID:WebF0x,项目名称:StrongAI,代码行数:24,代码来源:main.cpp
示例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 ;
}
开发者ID:ABZaxxon,项目名称:CS-School-Work,代码行数:15,代码来源:prog915.cpp
示例16: main
int main(int argc, char const* argv[])
{
using namespace std;
char answer;
cout << "Player 1 [circle] begins, should it be human (enter h) or computer (enter c): ";
cin >> answer;
while (!(answer == 'h' || answer == 'c')){
cout << "Wrong answer, try again: ";
cin >> answer;
}
Player p1(Player1, (answer == 'c' ? true : false));
cout << "Player 2 [cross], should it be human (enter h) or computer (enter c): ";
cin >> answer;
while (!(answer == 'h' || answer == 'c')){
cout << "Wrong answer, try again: ";
cin >> answer;
}
Player p2(Player2, (answer == 'c' ? true : false));
TicTacToe game;
while (!game.getStatus()){ // until nobody won and there are still empty fields
game.displayBoard();
p1.move(game);
if (game.getStatus() != None) // if sb. won or there is a draw
break;
game.displayBoard();
p2.move(game);
if (game.getStatus() != None) // if sb. won or there is a draw
break;
}
game.displayBoard();
switch (game.getStatus()) {
case Player1:
cout << "Player 1 won!\n";
break;
case Player2:
cout << "Player 2 won!\n";
break;
default:
cout << "Draw!\n";
break;
}
return 0;
}
开发者ID:palkakrzysiek,项目名称:IT-class,代码行数:45,代码来源:main.cpp
示例17: takeTurn
void takeTurn (TicTacToe& game, char turn)
{
bool mark = false;
int row;
int col;
//Ask player to make a move and check if they can go there
while (!mark) {
cout << "\n\n";
cout << turn << ": Where would you like to go? (Row Column): ";
cin >> row >> col;
if (game.placeMark (row, col, turn))
mark = true;
else
cout << "That is an invalid move, try again please. \n";
}
}
开发者ID:,项目名称:,代码行数:16,代码来源:
示例18: main
int main()
{
TicTacToe t;
// Movement variables
uint8_t x, y;
// BOOST Random generation support
//boost::mt19937 gen;
// Get current microseconds
struct timeval tv;
gettimeofday(&tv, NULL);
boost::mt19937 gen(tv.tv_usec);
boost::uniform_int<> dist(1, 3);
boost::variate_generator<boost::mt19937&,
boost::uniform_int<> > roll(gen, dist);
while(1) {
// Until we finish a game
while(false == t.finished())
{
do
{
// Move with PRNG
x = roll();
y = roll();
// Keep rolling until a proper space is found
if(t.occupied(x, y))
{
continue;
}
// Make a move
}
while(!t.move(x,y));
// A move succeeded!
// Print the board
t.printBoard();
}
// Game is finished. Who won?
t.printResult();
// Continue?
std::cout << "Press Enter to play again!\n";
// Get a single character from the keyboard
// If it's not a newline, break out of the while loop
if(std::cin.get() != '\n') break;
// Otherwise, clear the board and continue to the next game
t.clearBoard();
}
return EXIT_SUCCESS;
}
开发者ID:hank,项目名称:life,代码行数:49,代码来源:tic_random.cpp
示例19: printBoard
// From here downward, we have non-class functions to play the game.
void printBoard( const TicTacToe & obj, char compSide, char humanSide )
{
const matrix<int> & b = obj.getBoard( );
cout << "---" << endl;
for( int row = 0; row < 3; row++ )
{
for( int col = 0; col < 3; col++ )
if( b[ row ][ col ] == TicTacToe::COMPUTER )
cout << compSide;
else if( b[ row ][ col ] == TicTacToe::HUMAN )
cout << humanSide;
else
cout << ' ';
cout << endl;
}
cout << "---" << endl;
}
开发者ID:anilpawar-pd,项目名称:Eclipse-for-Java,代码行数:18,代码来源:TicTac.cpp
示例20: move
void Player::move(TicTacToe & game) {
using namespace std;
if (!artificial) {
int x = 0, y = 0;
do {
cout << "Enter position [row column] to which you want to insert a " <<
(id == Player1 ? "circle" : "cross" ) << ": ";
cout << "X coordinate: ";
while (!(cin >> x)) {
cout << "Wrong x coordinate, try again: ";
cin.clear();
while (cin.get() != '\n') {continue;}
}
cout << "Y coordinate: ";
while (!(cin >> y)) {
cout << "Wrong y coordinate, try again: ";
cin.clear();
while (cin.get() != '\n') {continue;}
}
#ifndef _NDEBUG
std::cout << "\nx = " << x << " y = " << y << std::endl;
#endif
} while (!game.set(x, y, id) && (std::cout << "Wrong coordinates\n"));
}
开发者ID:palkakrzysiek,项目名称:IT-class,代码行数:24,代码来源:TicTacToe.cpp
注:本文中的TicTacToe类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论