Shogi(Japnese Chess) in C++

I am done with promotion of pieces.
bool promotion(char CB[9][9], int EC[2], char &turn) //EC-endcoordinate
{
if((CB[EC[0]][EC[1]]=='p','s','n','l') && turn=='b')
return (CB[EC[0]][EC[1]]=='g');
else if((CB[EC[0]][EC[1]]=='P','S','N','L') && turn=='a')
return (CB[EC[0]][EC[1]]=='G');
else if((CB[EC[0]][EC[1]]=='r') && turn=='b')
return (CB[EC[0]][EC[1]]=='k' || 'r');
else if ((CB[EC[0]][EC[1]]=='R') && turn=='a')
return (CB[EC[0]][EC[1]]=='K' || 'R');
else if ((CB[EC[0]][EC[1]]=='b') && turn=='b')
return (CB[EC[0]][EC[1]]=='k' || 'b');
else if ((CB[EC[0]][EC[1]]=='B') && turn=='a')
return (CB[EC[0]][EC[1]]=='K' || 'B');
}
But i didnot understand what is drop,stalemate and checkmate in shogi. Need some help in writing code of these?
You don't understand the rules, or you don't understand how to implement the rules?
The OP could do with a refresher on the rules of C++ also.

 
if((CB[EC[0]][EC[1]]=='p','s','n','l') && turn=='b')

The comma operator doesn't work that way.

 
return (CB[EC[0]][EC[1]]=='k' || 'r');

C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example:
if (ans == 'Y' || 'y') evaluates as if ((ans == 'Y') || ('y'))

('y') always evaluates to 1 (true), therefore the if statement is always true.
I don't understand how to implement the rules?
Last edited on
Thank you AbstractionAnon.
Please post what you have and we can suggest changes or ways to implement the additional rules.
When a player's move threatens to capture the opposing king on the next turn, the move is said to give check to the king means the king is said to be in check. If a player's king is in check that player's responding move must remove the check if possible if no such move exists, the checking move is also checkmate and immediately wins the game.
I have made check function and through this check function I have to made checkmate function.But don't understand how to write it

void check(char CB[9][9], int SC[2], int EC[2], char turn)
{
if(Isvalidmove(CB, SC, EC, turn)==true) \\I have Isvalidmove
return true;
else
return false;
}
> I have made check function ... I have to made checkmate function ... I have Isvalidmove

1
2
3
4
5
6
7
8
bool checkmate:

     if the king is not in check return false 

     for each square adjacent to the king 
          if there is a valid move (or capture) to that square && king is not in check in that square return false
     
     return true (king is in check and there is no adjacent square to which it can move to escape the check)
Last edited on
Topic archived. No new replies allowed.