Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++. i have the first phase, im just not sure how to implement the second phase. Create a program to play three mens morris.

in c++. i have the first phase, im just not sure how to implement the second phase.

Create a program to play three mens morris. The program should use a two dimensional vector, to display a 3x3 grid of zeros.

a b c

1: 0 0 0

2: 0 0 0

3: 0 0 0

In the main function:

Print the board

For phase 1:

1) Prompt user to enter row and column in form a1, b2

2) Parse the string and change the letter into a number a=0, b=1, c=3, and change the rows into 1=0, 2=1, 3=2(subtract 1), change into indices

3) Check if the move entered is valid (check bounds, and if another player is on it)

4) Get the computers moves (dont just use random, use logic)

5) Loop through this 3 times.

For phase 2:

1) Prompt the user to enter where they would like to move from and too (a2b2)

2) Parse the string and repeat the same as the other, just give an origin of move and location in form of pair< , >

3) Check if the move is valid (if in bounds, if another player on it, and if its adjacent to the origin.)

4) Get the computer moves (use logic, if theres a way for the computer to win, make it or if they can lose stop them from losing)

5) Loop until someone wins. (check to see if game is over. In function set conditions for win, if it returns -1 game isnt over yet, if 1 player 1 won, if 2 the computer won)

Use these:

typedef std::vector> Board;

typedef std::pair Index; // pair of indices on board. First element is row, second is column.

typedef std::pair Move; // A move from one place to another on the board.

A pair of board indices. The first element of the pair is the source. The second element of the pair is the destination. During phase 1 of the game, only the destination matters.

void PrintBoard(Board board);

//prints the board

Index ParseIndicies(const string &space); //space is the a1, b1 user input

// converts the users input into a pair of row, column indices.

// //split the string into the letter and number, then change letter to a number for column, and then subtract 1 for the row. //returns row,column indices vector

Move Computer(const Board board)

//generates computer move(be smart)

//returns the move the computer will make, in form of pair< , >.

int PlayerAtSpace(const Board board, const Index space);

//determine which player is on a space. Return 0 for unoccupied, 1 for player 1, 2 for computer

void SetPlayerAtSpace(Board &board, const int player, const Index space);

//change the number on the board to the player moving there.

bool ValidMove(int phase, int player, const Board board, Move move);

//check if the move is valid. For phase 1: if in bounds, if no other player on space(if space is 0). For phase 2: same except check if its their piece they are moving, and if its adjacent to their origin.

Move ParseMove(int phase, const string move);

Move spacer

//parse the input move of the second phase a1b2, similar to other function.

Return spacer // a move type with origin and destination.

int GameOver(const Board board);

//determine if the game is over and who won

// return -1 if it isnt, 1 if player 1 won, 2 if computer won.

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 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago