Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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<: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.

image text in transcribed
in c++ please
Rules for Three Men's Morris 1. Three men's morris is played by two players, with pieces placed on the points of the lined board shown in the diagram. 2. The board starts empty, each player holding all his pieces in hand. 3. At first, each player in turn puts one piece on the board, at any vacant point. 4. Once all pieces are on the board, a player instead moves one of his pieces along a marked line to an adjacent empty point. Rules for Three Men's Morris 5. If a piece placed or moved as in rules 3 or 4 forms a row of three along a marked line (called a mill), he wins the game. Strategy in Three Men's Morris The standard game can be won by the first player, as pointed out in the Libro de los Juegos, or "Book of Games", of 1283. There are two possible victories, depending upon the second player's moves, the first being: 1. b2, a3; 2. b1,b3; 3. c1, a1; 4. b1-c1, any: 5. b2-c2. The second is 1. b2, b3; 2. a1.c3.3. a3, a2: 4. a1-b1, any: 5. b1-c1

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_2

Step: 3

blur-text-image_3

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions