62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#include <cmath>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
int main (void)
|
|
{
|
|
int player1Position = 4; //This is for both test and true input
|
|
int player1Score = 0;
|
|
int player2Position = 8; //This is 5 for true, 8 for test
|
|
int player2Score = 0;
|
|
int dieRoll = 1;
|
|
int turnAdd = 0;
|
|
int rollCount = 0;
|
|
bool player1Add = true;
|
|
|
|
//Run the game loop until someone has the highest score
|
|
while (player1Position < 1000 || player2Position < 1000)
|
|
{
|
|
//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++;
|
|
}
|
|
}
|
|
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;
|
|
}
|