diff --git a/day21/day21Part1 b/day21/day21Part1 new file mode 100755 index 0000000..b510681 Binary files /dev/null and b/day21/day21Part1 differ diff --git a/day21/day21Part1.cpp b/day21/day21Part1.cpp index a806480..ef6f36b 100644 --- a/day21/day21Part1.cpp +++ b/day21/day21Part1.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; @@ -8,28 +9,54 @@ int main (void) int player1Score = 0; int player2Position = 8; //This is 5 for true, 8 for test int player2Score = 0; - int dieRoll = 0; - int dieRollover = 0; + int dieRoll = 1; int turnAdd = 0; + int rollCount = 0; bool player1Add = true; - // - while (player1Position >= 1000 || player2Position >= 1000) + //Run the game loop until someone has the highest score + while (player1Position < 1000 || player2Position < 1000) { - if ((dieRoll % 3) == 0) + //If there's three values in the roll + if ((rollCount % 3) == 0) { + //If its player 1s turn, add their score if (player1Add) { - // player1Position = player1Position + turnAdd; + player1Position = ((player1Position - 1) % 10) + 1; player1Score += player1Position; } + //It its player 2s turn, add their score else { + player2Position = player2Position + turnAdd; + player2Position = ((player2Position - 1) % 10) + 1; + player2Score += player2Position; } } + //Add until 3 values have been rolled + else + { + rollCount++; + //Implement rollover + if(dieRoll > 100) dieRoll = 1; + turnAdd += dieRoll; + dieRoll++; + } } - - // TODO : Multiply loserScore by (100 * dieRollover) + dieRoll + if(player1Add) + { + bool test; + test = (player1Position >= 1000 || player2Position >= 1000); + cout << player1Position << endl; + cout << player2Position << endl; + cout << test << endl; + } + else + { + cout << "Player 2 Wins" << endl; + } + // TODO : Multiply loserScore by rollCount return 0; }