Browse Source

refactored leftToRightRule.

wes 4 years ago
parent
commit
514630997f
2 changed files with 12 additions and 8 deletions
  1. 9 5
      Qwixx/game.cpp
  2. 3 3
      Qwixx/game.h

+ 9 - 5
Qwixx/game.cpp

@@ -253,14 +253,18 @@ bool Game::lockOutRule(int player, Turn turn)
     return true;
 }
 
-void Game::leftToRightRule(int player, int color, int index)
+bool Game::leftToRightRule(int player, Turn turn)
 {
-     // player must add an x to olok from left to right
-    if(players[player].cumulativeOlok.getLastIndex(color) > index)
+    for(int i = 0; i<turn.moves.size(); i++)
     {
-        fprintf(stdout,"Player[%d] %s not following left to right rule X\n", player, players[player].savedName);
+        // player must add an x to olok from left to right
+        if(players[player].cumulativeOlok.getLastIndex(turn.moves[i].color) > turn.moves[i].index)
+        {
+            fprintf(stdout,"Player[%d] %s not following left to right rule X\n", player, players[player].savedName);
+            return false;
+        }
     }
-    else{players[player].currentTurnOlok.addX(color, index);}
+    return true;
 }
 
 void Game::addX(int player, int color, int index)

+ 3 - 3
Qwixx/game.h

@@ -35,9 +35,9 @@
         // rule for lockout to populate a locked out row so score function can check for locked rows
         void addX(int player, int color, int index);
         // rule for being able to lockout a row, check for last box marked off and set condition where the next box has to be higher than that previous box check
-        bool Game::lockOutRule(int player, Turn turn);
-        void leftToRightRule(int player, int color, int index);
-        bool Game::isMoveRepresentedInDie(int player, Turn turn);
+        bool lockOutRule(int player, Turn turn);
+        bool leftToRightRule(int player, Turn turn);
+        bool isMoveRepresentedInDie(int player, Turn turn);
         /*  TODO: generate a set of all possible moves a player can take given a: ScoreSheet & diceRoll
          *  1. one good reason to do this would be to check if a player can make a given move
          *  2. if you give this set of moves to an AI, it could pick a move