Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ ## Rules of Tic Tac Toe Player `x` and player `o` alternately place their symbols on a `3x3` board, starting with `x`. The

In C++

## Rules of Tic Tac Toe

Player `x` and player `o` alternately place their symbols on a `3x3` board, starting with `x`. The first player to get three symbols in a row wins, and the game is over. If all nine squares are full and no player has three symbols in a row, the game ends in a tie.

# Tic Tac Toe Analyser

Summary: write functions for analysing a tic-tac-toe game inside a C++ program called `tttanalyzer.cpp`

## String-representation `tttresult`

Write a function with the following signature:

```cpp char tttresult(string tttboard,bool * perror); ```

The string `tttboard` has nine characters representing the current situation in a game of tic tac toe:

x represents x o represents o # represents an unplayed space

The first three characters are the top row, the next three the middle row, and the last three are the bottom row.

So the line:

xox#x#xox

represents the board

x | o | x | | ---+-----+----- | x | ---+-----+----- | | x | o | x

The program should classify the board as one of the following:

- t: tie game and no spaces left - x: valid, x has won - o: valid, o has won - c: valid, game continues - i: invalid

The error condition should be set `true` when the input board does not conform to the specifications above.

An invalid game board is one in which there was a rule violation. A game can be invalid for many reasons, such as too many winners, unbalanced number of x's and o's, etc.

Do not "anticipate" tie games: a game is considered a tie only if all the spaces are filled.

## Example

`tttresult("xox#x#xox",&error)` returns `i`

It is invalid because x played 5 times and o only played 2 times.)

## Vector-representation `tttresult`

Write a function with the following signature:

```cpp char tttresult(vector board, bool *perror); ```

struct Move { int r; int c; char player; }

Move m;

m.r = 0 m.player = 'x';

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

Students also viewed these Databases questions