I am trying to write a function that checks for a winner in the game Quarto. The game is kind of like connect four or tic tac toe. The game consist of 16 unique piece each having four characteristics. White “W”, Black “B”, Long “L”, Short “S”, Square “R”, Circle “C”, Hollow “H”, Filled “F” So for example,the White Long Circle Hollow piece == “WLCH”. One player selects a piece and the other places that piece on a 16x16 board. If four characteristics are aligned vertically, horizontally or diagonally the last player to place a piece wins.
At first I thought about using switch statements but apparently you can't use pass in strings, only an interger,char or a enumeration.
So I am trying to us multiple IF statements starting with a four White pieces aligned horizontally in the first row. I thought this would be easy ... however the function determines a winner every time.
This is what I have so far:
bool checkWinner(string board[ROWS][COLS])
{
if( (board[0][0]== ("WSHR")||("WTHR")||("WTFR")||("WSHC")||("WTFC")||("WSFR")||("WTHC")||("WTFC"))
&&(board[0][1]== ("WSHR")||("WTHR")||("WTFR")||("WSHC")||("WTFC")||("WSFR")||("WTHC")||("WTFC"))
&&(board[0][2]== ("WSHR")||("WTHR")||("WTFR")||("WSHC")||("WTFC")||("WSFR")||("WTHC")||("WTFC"))
&&(board[0][3]== ("WSHR")||("WTHR")||("WTFR")||("WSHC")||("WTFC")||("WSFR")||("WTHC")||("WTFC")))
{
cout << "\nWinner!!!!!\n";
return true;
}
return false;
}
I added parentheses around every string after the function didn't work the first time.
I know it has to be something simple but I can't see it, I would appreciate any help on this problem.
Aucun commentaire:
Enregistrer un commentaire