// Tic-Tac-Toe
// Plays the game of tic-tac-toe against a human opponent
#include
<iostream>
#include
<string>
#include
<vector>
#include
<algorithm>
using
namespace std;
// global constants
const
char X = 'X';
const
char O = 'O';
const
char EMPTY = ' ';
const
char TIE = 'T';
const
char NO_ONE = 'N';
void
instructions();
char
askYesNo(string question);
int
askNumber(string question, int high, int low = 0);
char
humanPiece();
char
opponent(char piece);
void
displayBoard(const vector<char>* const pBoard);
char
winner(const vector<char>* const pBoard);
bool
isLegal(const vector<char>* const pBoard, int move);
int
humanMove(const vector<char>* const pBoard, char human);
int
computerMove(vector<char> board, char computer);
void
announceWinner(char winner, char computer, char human);
// main function
int
main()
{
int
move;
const
int NUM_SQUARES = 9;
vector
<char> board(NUM_SQUARES, EMPTY);
instructions();
char
human = humanPiece();
char
computer = opponent(human);
char
turn = X;
displayBoard(&board);
while
(winner(&board) human;
board
[move] = EMPTY;
}
if
(!found)
{
++move;
}
}
}
if
(!found)
{
move = 0;
unsigned
int i=0;
const
int BEST_MOVES[] = {4, 0, 2, 6, 8, 1, 3, 5, 7};
while
(!found && i< board.size())
{
move = BEST_MOVES[i];
if
(isLegal(move, &board))
{
found =
true;
}
++i;
}
}
cout <<
" I Shall take square number" << move << endl;
return
move;
}
void
announceWinner(char winner, char computer, char human)
{
if
(winner == computer)
{
cout <<
winner << "'s won!\n";
cout <<
"As I predicted, human, I am triumphant once more - proof\n";
cout <<
"that computers are superior to humans in all regards.\n";
}
else
if (winner == human)
{
cout <<
winner << "'s won!\n";
cout <<
"No, no! It cannot be! Somehow you tricked me, human.\n";
cout <<
"But never again! I, the computer, so swear it!\n";
}
else
{
cout <<
"It's a tie.\n";
cout <<
"You were most lucky, human, and somehow managed to tie me.\n";
cout <<
"Celebrate... for this is the best you will ever achieve.\n";
}
}
No, you cannot achieve a 5 in a row in a game of tic-tac-toe.
We also call it tic tac toe!
Kyper - Tic Tac Toe D Cole - Tic Tac toe still looking for a 3rd for a hiphop dance
The game Tic Tac Toe is originally from ancient Egypt. http://theeasyanswers.com
9 Squares in Tic Tac Toe
O = tic, X = tac, a line aka win = toe
A game of tic-tac-toe uses nine pieces.
tic tac toe was invented in stamford Connecticut, man it was the easiest thing. they played a game and called it ticdas to but the Americans borrowed it and named it tic tac toe and know it is fdamouse around the whole world
ME!!
Of Course Not!!
Ultimate tic-tac-toe is a variation of the classic game where each square on the board is actually a smaller game of tic-tac-toe. Players must win three smaller games in a row to win the overall game. The main difference from traditional tic-tac-toe is that players must think strategically about which smaller game to play in, adding an extra layer of complexity to the game.
"Three in a row, tic tac toe!" - It's short, sweet, and to the point, just like the game itself. Just make sure you don't end up with a stalemate, that's a snooze fest.