Browse Source

created new method translateToMove. expanded on the receive method in game.cpp.

wes 4 years ago
parent
commit
d3414aecb7
3 changed files with 38 additions and 54 deletions
  1. 34 53
      Qwixx/game.cpp
  2. 2 1
      Qwixx/game.h
  3. 2 0
      Qwixx/toDo.md

+ 34 - 53
Qwixx/game.cpp

@@ -128,63 +128,34 @@ std::string Game::send()
 // " 1143"
 // emma's intention is to take a penalty
 // "1"
-void Game::receive(std::string userInput)
+// convert a user string into a turn
+struct Turn Game::receive(std::string userInput)
 {
     players[0].currentTurnOlok.clear();
-    // penalties are marked to card if user string = 1
-    // did the user send a number?
-    // ## Range Check to go into Receive ##
-    #ifdef WORKING_ON_RANGE_CHECK
-    // if index is too high or too low, throw an error
-    if(CHECKBOXES > index || 0 < index){fprintf(stdout,"Player[%d] %s index is too high or too low X\n", player, players[player].savedName);}
-    // if color is not valid throw an error
-    players[0].cumulativeOlok.isColor(red);
-    if(color){fprintf(stdout,"Player[%d] %s invalid color selected X\n", player, players[player].savedName);}
-    #endif
-    // if a user did not send a number no changes take place
-    // take the userinput (string) and parse it into parts
-    // what is the length of the userInput? length of 2, 4? (boxes 0-9 are represented as 00,01,02...)
-
-    // convert userInput into number
-    // user number to change the boolean on corresponding spot on ScoreSheet
+    Turn turn;
+    // userinput is one, add a penalty
+    if(1 == userInput.size())
+    {
+        turn.penalty = 1;
+    }
+    // userinput size is two, add one moves
+    else if(2 == userInput.size())
+    {
+        turn.moves[0] = translateToMove(userInput);
+        turn.numberOfMoves = 1;
+    }
+    // userinput size is four, add two moves
+    else if(4 == userInput.size())
+    {
+        turn.moves[0] = translateToMove(userInput.substr(0,2));
+        turn.moves[1] = translateToMove(userInput.substr(2,2));
+        turn.numberOfMoves = 2;
+    }
+    else {fprintf(stdout, "Form an opinion: WRONG!");}
+    // check the rules to make sure turn is valid
+    // add turn to currentTurnOlok if the turn is valid
 }
 
-/* add a checkbox to a specified players scoresheet user specifies player's: XXXX, the color, and index of the checkbox on the colored row
- * dont know what XXXX is yet - but it will be used to find correct player
- * 
- * 
- * 
- * the white die and color combo must match the corresponding RowColor and index
- * 
- */
-
-/* 
- * all players can do white die combination, active player can do a colored + white die combination. 
- * 
- * ## Things we need to know ##
- * sum of both white die
- * 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 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))
- * 
- * // 
- */
-
 bool Game::isMoveRepresentedInDie(int player, Turn turn)
 {
     // is this the non-active player
@@ -275,4 +246,14 @@ bool Game::checkTurn (int player, Turn turn)
 
 void Game::addX(int player, int color, int index)
 {
+}
+struct Move Game::translateToMove(std::string temp)
+{
+    int temp2 = stoi(temp);
+    struct Move newMove;
+    // find the color
+    newMove.color = (temp2/colors);
+    // find the index, subtracted 1 from checkboxes because it is lockout bonus box - only interested in scored boxes
+    newMove.index = (temp2%(CHECKBOXES-1));
+    return newMove;
 }

+ 2 - 1
Qwixx/game.h

@@ -29,7 +29,7 @@
         void round();
         void score();
         std::string send();
-        void receive(std::string userInput);
+        struct Turn receive(std::string userInput);
         // rules as methods of game
         bool addPlayer(std::string name);
         // rule for lockout to populate a locked out row so score function can check for locked rows
@@ -39,6 +39,7 @@
         bool lockOutRule(int player, Turn turn);
         bool leftToRightRule(int player, Turn turn);
         bool isMoveRepresentedInDie(int player, Turn turn);
+        struct Move Game::translateToMove(std::string temp);
         /*  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

+ 2 - 0
Qwixx/toDo.md

@@ -34,6 +34,8 @@
         1. ~~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 (20AUG18, collectionOfMoves has been refactored to Turn) from it
+    - (20AUG20) TODO: only the active player can take two turns
+    - (20AUG20) TODO: refer to line 155/156 figure out functions and parameters needed for the pseudocode
 - 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