Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me to solve this assignment in C++. #include #include using namespace std; void displayBoard(char b[3][3]); void getUserChoice(int &r, int &c); void getCompChoice(char b[3][3], int

image text in transcribedimage text in transcribedimage text in transcribed

help me to solve this assignment in C++.

#include #include using namespace std;

void displayBoard(char b[3][3]); void getUserChoice(int &r, int &c); void getCompChoice(char b[3][3], int &r, int &c); bool hasWinner(char b[3][3], char &winner);

int main() { char board[3][3]; /* TODO: Initialize board */ char winner = ' '; bool userTurn = true;

while (!(hasWinner(board, winner) || /* TODO: isDraw */ false)) { int r, c; do { displayBoard(board); if (userTurn) getUserChoice(r, c); else getCompChoice(board, r, c); if (/* TODO: ! isOpen */ false) cout

cout

return 0; }

void displayBoard(char b[3][3]) { /* TODO: Fill in this function */ }

void getUserChoice(int &r, int &c) { r = 0; c = 0; /* TODO: Fill in this function*/ }

void getCompChoice(char b[3][3], int &r, int &c) { /* You are welcome to change this function * This is a simple AI function that finds the first available position */

for (r = 0; r

bool hasWinner(char b[3][3], char &winner) { char tmp;

/* Verticals */ for (int i = 0; i

/* Horizontal */ for (int i = 0; i

/* Diagonal #1 */ tmp = b[1][1]; if (tmp != ' ' && tmp == b[0][0] && tmp == b[2][2]) { winner = tmp; return true; } if (tmp != ' ' && tmp == b[2][0] && tmp == b[0][2]) { winner = tmp; return true; }

return false; }

Description Write a Tic-Tac-Toe game, using the provided framework. You will ill in the functions (as noted), as well as create two functions: isOpen and isDraw Sample Outputs Choose a row (1-3) 1 Choose a column (1-3) 1 Choose a row (1-3) 2 Choose a column (1-3) 2 Choose a row (1-3) 3 Choose a column (1-3): 3 WINNER: Player Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

List different probability sampling techniques.

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago