I'm not familiar with the game, but read the wiki link.Basially you need to construct a Board and write a method for the move. I just started the code with basic building blocks. The move method should be something similar. Again I'm not familiar with the game and I have not applied all rules, if I get time tommorrow morning I will add more. This is just to give you an idea
#include<iostream>
#include<vector>
usingnamespace std;
enum player{LP=0,RP};
struct Board
{
int left_pits[7]; // left side pits - seven
int right_pits[7]; //right side pits
int right_store;
int left_store;
//ctor
Board();
void Move(int player_turn,int pit_seleced,int stone_count); // It should follow all the rules and make one move and update the board
// put Move in a loop until the game finishes
};
Board::Board()// initialize all
{
for(int i=0;i<7;i++)
{
left_pits[i]=7; // starting position
right_pits[i]=7;
}
left_store=0;
right_store=0;
}
void Board::Move(int player_turn,int pit_selected,int stone_count)
{// player_seletcted= LP or RP, LP starts at left side RP statrs at right side
// move is always from left to right
/*
left side
6(7) 5(7) 4(7) 3(7) 2(7) 1(7) 0(7)
right_store(0) left_store(0)
0(7) 1(7) 2(7) 3(7) 4(7) 5(7) 6(7)
right side
*/
int i;
int stones_left=stone_count;
if( player_turn == LP)
{// he starts from the left side and goes to right dropping one stone at a time
for(i=pit_selected; stones_left>0 && i<7 ; i++)
{ // apply rules
left_pits[i]++;
stones_left--;
}
// pass right_store
//Move to right_pits, will work only if stones left
for(i=0;stones_left>0 && i<7 ; i++)
{
right_pits[i]++;
stones_left--;
}
// if more stones left, //drop one in the left store
if(stones_left>0)
{
left_store++;
stones_left--;
}
//if more stones left call the function again
if(stones_left>0)
this->Move(LP,0,stones_left);
}
if( player_turn == RP)
{// he starts from the right side and goes to the left dropping one stone at a time
for(i=pit_selected; stones_left>0 && i<7 ; i++)
{ // apply rules
right_pits[i]++;
stones_left--;
}
// pass left_store
//Move to left_pits, will work only if stones left
for(i=0;stones_left>0 && i<7 ; i++)
{
left_pits[i]++;
stones_left--;
}
// if more stones left, //drop one in the right store
if(stones_left>0)
{
right_store++;
stones_left--;
}
//if more stones left call the function again
if(stones_left>0)
this->Move(RP,0,stones_left);
}
}
int main(){
return 0;
}
Did some more coding today and made this basic Sangka game working. Two players can play. The playes are named as Left and Right. The game starts with Left player, insert a pit number of your row(Left is top).
It completes one move and displays the board. It also tells who has the next move. During current move if he gets a bonus, then the current player gets an additional move.
Caution: You may come across many pitfalls
I have never played this game, got the rules from the wiki link. My interpretation of the rules can be wrong. For example, when a move ends in his own row, the player can grab all the stones from pit across of the other row, I took the pit close to it, but it can be diagonally across also. In my case if it ends left_row[2] then it grabs stones from right_row[4] , but it can be, when left_row[2] grab right_row[2].
But I think one can modify the move method and make necessary adjustments. Another issue when a pit contains 14 stones it will end up in an infinite loop, I have no idea how to fix that.
Hope some one who knows the game test it and give a feed back.
thanks guys for the ideas,...just got logged in today, been busy with the project myself,.. gathering ideas, anyway,
heres how the rules applied:
from what i gathered(from locals who played it, here in Philippines,..): if a player lands in his own domain(either house or pit), he gets another turn, if not, the next player gets to take the turn,.
*note: there is a special condition when a player lands on his own domain, where, if there is nothing in there, 0 to be exact, he gets the tiles across it, *note if there is something across it,
and add it to his own house(total score) and when all domains from 0-6(1-7) of left and right players are zero(0) then they start to count to see who wins, if left player gets higher score than right, he wins, or the other way around.
*note that there are 7 tiles for each pits, so there are 98 tiles all in all.
thanks
to anilpanicker (93) - still i got to check and update your codes applying the rules
to Fenor (6) - i really like the code, but to be fair, i have trouble looking at the output, lol, but thanks anyway,...
and i really want to make this one a short project, in terms of lines, thanks guys,
if you still got some ideas, feel free to share,
i was wondering if we can make an AI out of this,...
using randomizations on structures or pointers,..
whatever useful,
help me out on this one guys,.. thanks in advance
At each turn a player empties one of his small pits and then distributes its contents in a counterclockwise direction, one by one, into the following pits including his own store, but passing the opponents store.
If the last stone falls into a non-empty small pit, its contents are lifted and distributed in another lap. Q: Is this in the same turn or another turn after the other player is moved?
If the last stone is dropped into the player's own store, the player gets a bonus move.
If the last stone is dropped into an empty, the move ends.
> If the last stone falls into a non-empty small pit, its contents are lifted and distributed in another lap?
> answer: no, if the last stone falls into a non empty small pit, (if the last stone falls into your own pit, you have another move, if it falls into the opponents pit, the turn ends)
> a players turn will consist of passing his own pit and store as well as the opponent's pit, but not the opponent's store,..
i've copied the program by fenor,
and i had few little ideas about it,
since sungka is a 7 stone 7 pit and 2 house game,
and the moves goes clock wise(not counter clockwise)
it seems there are minor errors,
thanks for the code fenor,
we can use this but i have to admit,
this is a high-level language we are using,
and thanks to anilpanicker for the code fragments and ideas