Selaa lähdekoodia

added isMoveRepresentedInDie function in game.cpp. added Moves struct and CollectionOfMoves struct in game.h.

wes 4 vuotta sitten
vanhempi
commit
8402012533
4 muutettua tiedostoa jossa 111 lisäystä ja 18 poistoa
  1. 89 16
      Qwixx/game.cpp
  2. 16 0
      Qwixx/game.h
  3. 1 0
      Qwixx/qwixx.h
  4. 5 2
      Qwixx/toDo.md

+ 89 - 16
Qwixx/game.cpp

@@ -163,28 +163,93 @@ void Game::receive(std::string userInput)
  * 
  * ## Things we need to know ##
  * sum of both white die
- * 8 sums of each of the white die and all of the colored die
- * who is the active player for this turn
+ * sums of 8 dice
+ * who is active player
  * 
  * ## How to do ##
  * on a given turn, sum the white die and sum each of the white die and all of the colored die
  * check to see if each players' requested move is valid
- *      does the player's requested move match the sum of the white die "satisfies all players can do white die combination"
- *      if the active player, check both white die and the color die they requested for move
- *      TODO: deal with subtley of active player not being able to re-use dice
- *      record if active player took at least a white dice move, a colored die move, or both
- * if it is valid, add it to player card
+ *      - does their input match the sum of the white die
+ * check to see if active player requested move is valid
+ *      - for the active player check white die sum if one input. if it fails then check each white die + color die sums add item to scoresheet
+ *      - for the active player if two inputs are passsed, check white die sum first if it passes, add to scoresheet. then check the second input with white die + colored die
+ * if it is valid, add it to player card 
  * if it is not valid, return an error to player
+ * 
+ * ## players' move 
+ * // this function has access to diceRoll and player input
+ * // is the players' input a valid move <- what does valid mean? (is it represented in die, does it follow left to right, does it follow lockout, does it fit within the confines of a move)
+ * // the confines of a move for non-actie player is (0 or one white die move)
+ * // the confines of a move for active palyer is (penalty or (one or two die moves))
+ * 
+ * // 
  */
-void Game::addX(int player, int color, int index)
+
+bool Game::isMoveRepresentedInDie(int player, CollectionOfMoves collectionOfMoves)
+{
+    // is this the non-active player
+    if(player != activePlayer) 
+    {
+        // if the move equals the sum of the two white die return true, if not return false
+        return (collectionOfMoves.white.index == (dice.dice[white1] + dice.dice[white2])) ?  true : false;
+    }
+    // otherwise this is the active player
+    else
+    {
+        // if one move
+        if(1 == collectionOfMoves.numberOfMoves)
+        { 
+            // check sum of white die
+            if(collectionOfMoves.white.index != (dice.dice[white1] + dice.dice[white2]))
+            {
+                int c = collectionOfMoves.color.color;
+                // if any white die plus the colored die equals the move
+                if(collectionOfMoves.color.index == (dice.dice[white1] + dice.dice[c]) || collectionOfMoves.color.index == (dice.dice[white2] + dice.dice[c]))
+                {
+                    return true;
+                }
+                // colored die plus either white die was not a move
+                else {return false;}
+            }
+            // otherwise the white sum die was a move
+            else {return true;}
+        }
+        // if two move 
+        else if(2 == collectionOfMoves.numberOfMoves)
+        {            
+            // check first input with white die sum
+            if(collectionOfMoves.white.index != (dice.dice[white1] + dice.dice[white2]))
+            {
+                // white die sum was not a move
+                return false;
+            }
+            else
+            {
+                    int c = collectionOfMoves.color.color;
+                // check to see if color die + either white die sum equals a move
+                if(collectionOfMoves.color.index == (dice.dice[white1] + dice.dice[c]) || collectionOfMoves.color.index == (dice.dice[white2] + dice.dice[c]))
+                {
+                    return true;
+                }
+                else {return false;}
+            }           
+                
+        }           
+    }      
+};
+
+
+
+
+
+
+
+
+
+
+void Game::lockOutRule(int player, int color, int index)
 {
-    /* TODO: check that index and color match rolled die
-    * ## Rule Check ##
-    * if index is not the sum of two dice throw an error
-    * if index is a sum AND color is correct allow it
-    */
-    
-    // player can add an x to olok in last column if there are 5 x
+ // player can add an x to olok in last column if there are 5 x
     if(lastColumnIndex == index)
     {
         if(LOCKOUT_QUALIFIER >= players[player].cumulativeOlok.getXCount(color))
@@ -193,10 +258,18 @@ void Game::addX(int player, int color, int index)
         }
         else{fprintf(stdout, "Player[%d] %s tried to check off column 12 without minimum X\n", player, players[player].savedName);}
     }
-    // player must add an x to olok from left to right
+}
+
+void Game::leftToRightRule(int player, int color, int index)
+{
+     // player must add an x to olok from left to right
     if(players[player].cumulativeOlok.getLastIndex(color) > index)
     {
         fprintf(stdout,"Player[%d] %s not following left to right rule X\n", player, players[player].savedName);
     }
     else{players[player].currentTurnOlok.addX(color, index);}
+}
+
+void Game::addX(int player, int color, int index)
+{
 }

+ 16 - 0
Qwixx/game.h

@@ -4,6 +4,19 @@
     #include "dice.h"
     #include "ScoreSheet.h"
     #include <windows.h>
+    struct Move 
+    {
+        int index;
+        int color;
+    };
+    struct CollectionOfMoves 
+    {
+        Move white;
+        Move color;
+        // this can be zero, one or two
+        int numberOfMoves = 0; 
+        bool penalty;
+    };
     class Game {
         public:
         std::vector<ScoreSheet> players;
@@ -22,6 +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
+        void lockOutRule(int player, int color, int index);
+        void leftToRightRule(int player, int color, int index);
+        bool Game::isMoveRepresentedInDie(int player, CollectionOfMoves collectionOfMoves);
         /*  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

+ 1 - 0
Qwixx/qwixx.h

@@ -7,6 +7,7 @@
     enum {red = 9, yellow = 19, green = 0, blue = 55, white1 = 4, white2, colors};
     // checkboxes represents the count of the sample space of the sum of rolling 2 dice
     #define CHECKBOXES 11
+    #define NOTSET -1
     #define CHECKBOX_COUNT (CHECKBOXES*white1)
     #define PENALTY_VALUE 5
     #define MAX_PENALTY 4

+ 5 - 2
Qwixx/toDo.md

@@ -28,8 +28,11 @@
 - (20AUG04) Started working on send function, come back and finish it to denote a 4x12 grid to save checkboxes per row
 - ~~(20AUG06) come back to `// add selection to players' cards` (kyle-plain it) to continue with `send/receive`~~
     - before writing received create the rules that will affect receive function (e.g. which checkboxes are allowed to be clicked)
-    - (20AUG09) TODO: check that index and color, match rolled die (this will help finish addx) then continue work on send/receive
-    - (20AUG11) TODO: write psuedo code for line 170-175 (174 specifically) in game.cpp
+    - ~~(20AUG09) TODO: check that index and color, match rolled die (this will help finish addx) then continue work on send/receive~~
+    - ~~(20AUG11) TODO: write psuedo code for line 170-175 (174 specifically) in game.cpp~~
+    - (20AUG13) TODO: fix the leftToRightRule and the lockoutRule functions to return bools and change parameters so they use collectionOfMoves. create master function for to call all rules - remove addx dependencies from currentTurnOlok
+    - (20AUG13) TODO: refactor dice so it is not vector of ints and add different property to access the die
+    - (20AGU13) TODO: receive should parse input and create a collectionOfMoves from it
 - current make process involves compiling all object files from dice, game, playercard to create main.exe which has to be manually linked to these objects. update makefile to support object file code
 - what comes in from players: newest item checked off on row&column (maybe 2) or penalty