answersLogoWhite

0

How do you beat first gym diamond?

User Avatar

Anonymous

12y ago
Updated: 8/20/2019

// 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';

// function prototypes

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>& board);

char winner(const vector<char>& board);

bool isLegal(const vector<char>& board, int move);

int humanMove (const vector<char>& board, 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)

{

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";

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?