Question: Im doing this assignment in c++ and need help Implement a program to solve a solitaire version of a board game. 1 Overview Mancala is
Im doing this assignment in c++ and need help
Implement a program to solve a solitaire version of a board game.
1 Overview
Mancala is played with 6 holes arranged in a circle. One hole is designated bank. Each
hole contains some number of stones. In our simplified version, the player starts a move by
picking up all the stones in one hole (but not the bank); she then proceeds clockwise (starting
in the next hole) placing the stones one in each hole, until all the stones are placed. Note
that the player gets to choose which of the 5 holes to start with; after that the process is
mechanical.
Here is an example where the 7 stones are picked up from hole 3 and then redistributed. We
will write this as
[0.3.7.2.4]
goes to
[1.4.1.4.5]
bank
0
3
7
2
4
=
?
bank
1
4
1
4
5
The objective is to get all the stones into the bank. The game is usually played as a race
between two players, and there are rules allowing interaction. But here we consider a single-
player solitaire version. Your task is:
Design and implement a C++ program that, given any initial configuration of
stones, determines the minimum number of moves to the goal-state, and the se-
quence of moves required.
2 Initial Position Class
Create a class Position(in files of the same name) that stores, displays, and manipulates
positions. Specifically the class must have at least:
constructor Position(vector) takes 5-element int vector
bool method isDone() indicates doneness (no stone outside bank)
method Position * afterMove(int) returns the result of move starting with specified pick-up hole (holes numbered 15). (It returns nullptr if no stone initially in that hole.)
Stream insertion operator.
Equality tester
3 Driver: mancala.cpp
Create a driver mancala.cpp that uses breadth-first-search to find the minimum number of moves from the start-state to the goal-state. This should use an instance of queue from the STL. You might also need an instance of stack. You will probably need to add member functions and member variables to your Position class.
The driver program takes 5 integer values on the command-line, representing the contents of the 5 holes in clockwise after the bank. It should print out in order a shortest sequence of Positions from start to goal.
For example:
Running: Mancala 2 2 2 2 0
Positions Found: 153459
NUMBER OF MOVES: 11
[2.2.2.2.0]
Move:1 yields [0.3.3.2.0]
Move:3 yields [0.3.0.3.1]
Move:4 yields [1.3.0.0.2]
Move:5 yields [2.3.0.0.0]
Move:1 yields [0.4.1.0.0]
Move:2 yields [0.0.2.1.1]
Move:5 yields [0.0.2.1.0]
Move:3 yields [0.0.0.2.1]
Move:5 yields [0.0.0.2.0]
Move:4 yields [0.0.0.0.1]
Move:5 yields [0.0.0.0.0]
4 Enhancements
As an improvement, you must use a Dictionary data structure to record positions reached, in
order to avoid duplicate searching. (Hint: it is enough just to know whether a position has
been seen.) You should print out a count of the number of positions looked at. This version
usage: same driver except command-line arguments X1 X2 X3 X4 X5 Hash
For this you might consider using an instance of unordered_set from the STL. However, you are also welcome to use/adapt (your or my) code from elsewhere in the course.
Further, you should ensure that, at the end, all instances of Position ever created are destructed. For this, you should include two static counters inside Position that keep track of the number of instances constructed and destructed, and the last line of your driver should print these counters out
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
