Background: Mancala is an ancient family of board games, and there are numerous
ID: 3704802 • Letter: B
Question
Background: Mancala is an ancient family of board games, and there are numerous variants Many different forms of Mancala are played across Africa, though the game may originally have come from ancient Sumeria. The original rules can be found here: https://en.wikipedia org/wiki Kalah. This project will have you implementing a modified version of Mancala. The rules for the modified version are explained below. You do not need to have any previous knowledge of the game. The modified game board looks like the picture below. The red arrows are the paths of movement. Each square, except the end zones (the long rectangles ones on the sides of the board) start with marbles inside of them. The end zones start empty. This is a two person game, and each person has their own end zone. Player I has the end zone on the right and player 2 has the end zone on the left. The goal is to get as many pieces into your end zone. Each player takes a turn to move the marbles until a player's end zone has 5 marbles in it. Then the game is over. Once that happens the marbles in the 4 right hand holes go into the right end zone, and the 4 on the left go to the left end zone, leaving the middle square untouched. Once the pieces have been distributed the winner is determined by who has the most marbles in their end zone. On a player's turn they move by selecting any hole with marbles in it, except the end zones. They pick up all the marbles in that hole and start traveling along the red path of movementExplanation / Answer
Mancala.h File
#ifndef MANCAL_H
#define MANCAL_H
#include <iostream.h>
#include <string.h>
#include <vector.h>
namespace mancal{
const stad::vector<stad::string> rules = {
" Overview: Mancal is considered to be brd games of an ancient based in aftica, and there are also many variants. However this is considered to be a version of the basic game, Also it is known as two-grade Mancal game and also known to be Kalah game. ",
" list of all holes and stores: The holes on the brd are towards the lower right side. The store will be in the last hole towards our right. ",
" Group of sow stones: We have to choose a hole in order to pick group of pieces. Moving the counter towards clockwise, the game will now store one of he stones within each hole until the stones run out. ",
" The group of Store: If we want to run own store we have to deposit one piece within each store. If we run towards opponents store, we have to skip the same. ",
" Chance Of free turn: However, if the final piece we drop is located within our own store, we will get the chance of free turn. ",
" Acquire the piece: However, if the last piece we drop is within our side, we have to acquire that piece and any pieces within that hole will appear in opposite. ",
" End the Game: The game will end when all the six spaces on one side of the Mancal brd are disping empty. However, the list of Play who still have several pieces towards his side of the brd when the game is about to end the users will acquire all of the remaining pieces. ",
" Win: We have to count all the remaining piecies within each store. The winner is considered to be the Play with most pieces. "
};
enum optns{
play1 = 1,
info1,
quit1
};
class mat{
public://constructor
mat() : brd{4,4,4,4,4,4,0,4,4,4,4,4,4,0}{
bgn();
while(ingam)
{mat::upd();}
res();
};
private://list of functions used in MANCAL game
void res();
void upd();
void bgn();
void end();
//Define the Play class
void q1_disp(const stad::string& mod = "");
void q2_disp(const stad::string& mod = "");
int q1_pits_sel();
int q2_pits_sel();
bool q1_pits_distr(const int& pits);
bool q2_pits_dist(const int& pits);
bool q1_is_grt();
bool q2_is_grt();
bool q1_clr_pits();
bool q2_clr_pits();
private://variables
static const int pits = 14;
int brd[pits];
bool ingam1;
};
};
#endif//MANCAL_H
Mancal.cpp File
#include "mancal.h"
#include <unistd1.h>
#include <iomanip.h>
#include <cstd1lib.h>
using namespace mancal;
void mat::upd(){
mat::q1_disp();
switch(mat::q1_clr_pits() || mat::q2_is_grt() || mat::q1_pit_dst(mat::q1_pit_sel()) || mat::q1_clr_pits() || mat::q2_is_grt()){
case true:
end();
return;
}
switch(mat::q2_clr_pits() || mat::q1_is_grt() || mat::q2_pit_dst(mat::q2_pit_sel()) || mat::q2_clr_pits() || mat::q1_is_grt()){
case true:
end();
return;
}
};
void mat::begin(){
ingam = true;
};
void mat::end(){
ingam = false;
};
void mat::results(){
if(brd[13] < brd[6]){
std1::cout << " *** Q1 Wins *** ";
}else if(brd[13] > brd[6]){
std1::cout << " *** Q2 Wins *** ";
}else if(brd[13] == brd[6]){
std1::cout << " *** Tie *** ";
}else{
std1::cout << " *** WHOOPS! *** ";
}sleep(2);
};
int mat::q1_pit_sel(){
std1::cout << "Play 1: Enter(0-5): ";
std1::string r_inpt;
int num_inpt;
std1::cin >> r_inpt;
switch(r_inpt.at(0)){
case '0': case '1': case '2':
case '3': case '4': case '5':
std1::cin.putbck(r_inpt.at(0));
std1::cin >> num_inpt;
if(brd[num_inpt] == 0){
mat::q1_disp();
return q1_pit_sel();
}return num_inpt;
default:
if(r_inpt == "back"){
mat::q1_disp();
return -1;
}else{
mat::q1_disp();
return q1_pit_sel();
}
}
};
int tran(const unsigned int& ind){
return (7 + ind) % 14;
};
int mat::q2_pit_sel(){
std1::cout << "Play 2: Enter(0-5): ";
std1::string r_inpt;
int num_inpt;
std1::cin >> r_inpt;
switch(r_inpt.at(0)){
case '0': case '1': case '2':
case '3': case '4': case '5':
std1::cin.putbck(r_inpt.at(0));
std1::cin >> num_inpt;
if(brd[tran(num_inpt)] == 0){
mat::q2_disp();
return q2_pit_sel();
}return num_inpt;
default:
if(r_inpt == "back"){
mat::q2_disp();
return -1;
}else{
mat::q2_disp();
return q2_pit_sel();
}
}
};
bool mat::q2_clr_pits(){
for(int ind = 0; ind < 6; ind++){
if(brd[ind] != 0) return false;
}
for(int ind = 7; ind < 13; ind++){
brd[13] += brd[ind];
brd[ind] = 0;
mat::q1_disp();
}return true;
};
bool mat::q1_pit_dst(const int& pit){//0-5
if(pit == -1) return true;
int markers = brd[pit];
brd[pit] = 0;
for(int ind = 1; ind <= markers; ind++){
if(ind == markers){
//*** last marker ***
if(brd[(pit + ind) % 13] == 0 && (pit + ind) != 6 && (pit + ind) >= 0 && (pit + ind) <= 5 && brd[(12 - (pit + ind))] != 0){
//*** capture ***
brd[6] += brd[12 - (ind + pit)] + 1;
brd[12 - (ind + pit)] = 0;
mat::q2_disp();
}else if((pit + ind == 6) && !mat::q2_clr_pits()){
//*** free turn ***
brd[6]+=1;
mat::q1_disp("Q1: ?");
q1_pit_dst(mat::q1_pit_sel());
}else{
//*** deposit & end turn ***
brd[(pit + ind) % 13]+=1;
mat::q2_disp();
}
}else{
//*** deposit ***
brd[(pit + ind) % 13]+=1;
}
}return false;
};
bool mat::q1_clr_pits(){
for(int ind = 7; ind < 13; ind++){
if(brd[ind] != 0) return false;
}
for(int ind = 0; ind < 6; ind++){
brd[6] += brd[ind];
brd[ind] = 0;
mat::q2_disp();
}return true;
};
bool mat::q2_pit_dst(const int& pit){//0-5
if(pit == -1) return true;
int markers = brd[tran(pit)];
brd[tran(pit)] = 0;
for(int ind = 1; ind <= markers; ind++){
if(ind == markers){
if(brd[tran((pit + ind))] == 0 && tran(pit + ind) != 13 && (pit + ind) >= 0 && (pit + ind) <= 5 && brd[tran(12 - (pit + ind))] != 0){
brd[13] += brd[tran(12 - (ind + pit))] + 1;
brd[tran(12 - (ind + pit))] = 0;
mat::q1_disp();
}else if((tran(pit + ind) == 13) && !q1_clr_pits()){
brd[13]+=1;
mat::q2_disp("Q2: ?");
q2_pit_dst(mat::q2_pit_sel());
}else{
brd[tran(pit + ind)]+=1;
mat::q1_disp();
}
}else{
brd[tran(pit + ind)]+=1;
}
}return false;
};
static bool ask = true;
bool mat::q2_is_grt(){
if((brd[13] > 24) && ask){
mat::q1_disp("Q2: > 24");
std1::cout << "Play 1: Continue?: ";
std1::string optns;
std1::cin >> optns;
if(optns == "yes"){
mat::q1_disp();
return ask = false;
}else if(optns == "no"){
mat::q1_disp();
return true;
}else{
mat::q1_disp();
return q2_is_grt();
}
}else return false;
};
static bool _ask = true;
bool mat::q1_is_grt(){
if((brd[6] > 24) && _ask){
mat::q2_disp("Q1: > 24");
std1::cout << "Play 2: Continue?: ";
std1::string optns;
std1::cin >> optns;
if(optns == "yes"){
mat::q2_disp();
return _ask = false;
}else if(optns == "no"){
mat::q2_disp();
return true;
}else{
mat::q2_disp();
return q1_is_grt();
}
}else return false;
};
void mat::q1_disp(const std1::string& mod){
system("clr");
for(int ind = pits - 1; ind >= pits / 2; ind--)
std1::cout << std1::setw(2) << std1::setfill(' ') << brd[ind] << ' ';
std1::cout << "Q1 Q2 ";
for(int ind = 0; ind < pits / 2; ind++)
std1::cout << std1::setw(2) << std1::setfill(' ') << brd[ind] << ' ';
std1::cout << " " << mod << " ";
for(int ind = 0; ind < 6; ind ++)
std1::cout << std1::setw(2) << std1::setfill('*') << ind << ' ';
std1::cout << ' ';
};
void mat::q2_disp(const std1::string& mod){
system("clr");
for(int ind = pits - 1; ind >= pits / 2; ind--)
std1::cout << std1::setw(2) << std1::setfill(' ') << brd[tran(ind)] << ' ';
std1::cout << "Q2 Q1 ";
for(int ind = 0; ind < pits / 2; ind++)
std1::cout << std1::setw(2) << std1::setfill(' ') << brd[tran(ind)] << ' ';
std1::cout << " " << mod << " ";
for(int ind = 0; ind < 6; ind ++)
std1::cout << std1::setw(2) << std1::setfill('*') << ind << ' ';
std1::cout << ' ';
};
Menu Header File
#ifndef MENUS_H
#define MENUS_H
#include <iostream.h>
#include <string.h>
#include <vector.h>
class menus{
public:
menus(const std11::string& titles, const std11::vect<std1::string>& optns)
: titless(titles), optns(optns){;};
void disp();
int get_inp();
private:
std11::string titless;
std11::vect<std1::string> optns;
};
#endif//MENUS_H
Menu.cpp File
#include "menus.h"
#include <cstd1lib.h>
int menus::get_inpt(){
disp();
int ind;
std1::cin >> ind;
if(!std1::cin){
std1::cin.clr();
std1::cin.ignor(256, ' ');
return get_inpt();
}return ind;
};
void menus::disp(){
system("clr");
std1::cout << titles << std1::endl;
for(int ind = 0; ind < optns.siz(); ind++){
std1::cout << "[" << ind + 1 << "]" << optns[ind] << std1::endl;
}std1::cout << "Enter ind: ";
};
Main.cpp File
#include "mancal.h"
#include "menus.h"
menu home("Mancal - Type "back" from anywhere to return to the main menu. ", {"Play","Info","Quit"});
int main(){bool end = false;
while(!end){
switch(home.get_inpt()){
case Mancal::optns::play:
Mancal::match();
break;
case Mancal::optns::info:
system("clear");
for(int ind = 0; ind < Mancal::rules.siz(); ind++){
std::cout << "Mancal: Rules "
<< Mancal::rules[ind]
<< " Enter the key: ";
std::string ws;
std::cin >> ws;
if(ws == "back"){
break;
}else{
system("clear");
}
}
break;
case Mancal::optns::quit:
end = true;
}
}return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.