I am working on a program for the game Scattegories. In the program there is a table that the player inputs the words while a timer thread is working in the background. I would that when the time is over, the player won't be able to input anymore and for his turn to end.
How can I make that happen?
The table and the timer:
void timer()
{
cout << "You got 2 minutes to finish\n"; //Changing the duration of the timer is done by changing the value of 'i' in the "for" loop
for (int i = 120; i > 0; i--)
{
sleep_for(1s);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}
void table(int plr)
{
string ctr[12] = { "A cuntry", "A city", "An animal", "A plant", "An object", "A name", "Food", "Drink", "A game", "A movie", "A book", "A famous person" };
string lst[6][12]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
std::thread t1(timer); //gives time to write the words. Optimaly it would finish the round for player when time is up
t1.detach();
cout << "When the timer ends please enter '0' in the remaining catagories\n";
for (int i = 0; i<12; i++) //changing catagory
{
cout << ctr[i] << ": ";
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next player\n";
}
}
Full code:
// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
#include <chrono>
#include <thread>
using std::cout;
using std::cin;
using std::string;
using std::getline;
using namespace std::chrono_literals;
using std::this_thread::sleep_for;
void ltr() //gives a random letter
{
char letter;
letter = rand() % 26 + 65; //assigns a random letter in ascii code to a char (resulting in a random letter)
cout << "The letter is " << letter << "\n";
}
void timer()
{
cout << "You got 2 minutes to finish\n"; //Changing the duration of the timer is done by changing the value of 'i' in the "for" loop
for (int i = 120; i > 0; i--)
{
sleep_for(1s);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}
void table(int plr)
{
string ctr[12] = { "A cuntry", "A city", "An animal", "A plant", "An object", "A name", "Food", "Drink", "A game", "A movie", "A book", "A famous person" };
string lst[6][12]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
std::thread t1(timer); //gives time to write the words. Optimaly it would finish the round for player when time is up
t1.detach();
cout << "When the timer ends please enter '0' in the remaining catagories\n";
for (int i = 0; i<12; i++) //changing catagory
{
cout << ctr[i] << ": ";
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next player\n";
}
for (int x = 0; x<plr; x++) //this part (the whole "for" loop) is for confirming evreything is writen down
{
cout << "Player number " << x + 1 << ": ";
for (int i = 0; i<12; i++)
{
cout << lst[x][i] << " ";
}
cout << "\n";
}
sleep_for(5s);
}
int points() //points gained per round
{
int a, b, c, sum;
cout << "How many sections only you got?\n"; //worth 15 points
cin >> a;
cout << "How many words only you got?\n"; //worth 10 points
cin >> b;
cout << "How many words you and another person got?\n"; //worth 5 points
cin >> c;
sum = a * 15 + b * 10 + c * 5;
return sum; //Note: It doesn't matter how many sections there are.
}
int act() //running the program
{
int Players, Points[6];
cout << "How many people are playing? (Up to six players)";
cin >> Players;
ltr();
table(Players);
//Points = points();
cout << "You have earned " << Points << " this round\n\n";
return 1;
}
int main()
{
auto start = std::chrono::high_resolution_clock::now();
srand(time(NULL)); //gives a differant pattern of letters every time
int Points;
Points = act();
for (;;) //inf loop
{
int ph;
cout << "Press 1 to continue or anything else to stop\n";
cin >> ph;
if (ph == 1)
{
Points += act(); //keeping score of the rounds
}
else
{
auto end = std::chrono::high_resolution_clock::now();
break;
}
}
cout << "You have earned a total of " << Points << " great job!";
sleep_for(5s); //time to read the last text
return 0;
}
/*
To do list:
-Make timer stop the table when time is up
-Check if words in the table (for differant players) are the same and give points accordingly
-Check if words are actual words (connect an online dictonary?)
-Make interface? (if possible and I have time to learn how)
-Comment rest of the code
*/
P.S
I'm tying to keep this code portable so I preffer sugestions that will keep it this way. But I would appreciate any suggestion.
I'm using windows 10 (but I'm writing console aplications) I have access to c++11 and c++14
A non-portable solution
bool getUserInput(string &result, Time deadline) // pick a timer, any timer
{
while(deadline > Time::now()) // assuming your timer has a now function
{
if(kbhit()) // THIS IS NOT PORTABLE. On windows it's called _kbhit()
{
char key = getch(); //read the key (also non-portable)
if(key == '\n' or key == '\r')
{
return true;
}
else
{
string += key;
}
}
}
return false;
}
Related
My program will repeat output: "You are currently on the 2 floor out of 5
The sum of the codes is: 7 and the product of the codes is: 12
Try again before he catches onto you!"
Based on how many wrong characters are added how can I fix this? I have inserted the cin.clear and cin.ignore but it will repeat the part above.
i.e. if I type wasds it will repeat 5x. Any other notes are also appreciated.
#include <iostream>
#include <ctime>
using namespace std;
int PlayerLevel = 0;
int MaxLevel = 5;
bool GamePlay ()
{
srand(time(NULL));
int PlayerGuessA, PlayerGuessB, PlayerGuessC;
int CodeA = rand() % PlayerLevel + PlayerLevel;
int CodeB = rand() % PlayerLevel + PlayerLevel;
int CodeC = rand() % PlayerLevel + PlayerLevel;
int SumofCodes = CodeA + CodeB + CodeC;
int ProductofCodes = CodeA * CodeB * CodeC;
cout << "You are currently on the " << PlayerLevel << " floor out of 5" << endl;
cout << "The sum of the codes is: " << SumofCodes << " and the product of the codes is: " << ProductofCodes << endl;
cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;
int PlayerProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;
int PlayerSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
if (PlayerProduct == ProductofCodes && SumofCodes == PlayerSum) {
cout << "Great Job you got this!!!\n" << endl;
++PlayerLevel;
return true;
}
else
{
cout << "Try again before he catches onto you!\n" << endl;
return false;
}
}
int GameStart()
{
string Introduction = "Welcome to your worst nightmare. You are trapped in a murderer's house. You are on the 5th floor and need to get to the first floor to escape.\n";
string Instructions = "He has each door locked behind a security system that requires a 3 number code to disarm it.\nEnter the codes and move foward. Each level will the code will be harder to figure out.\n";
string PlayerStart;
cout << Introduction << endl;
cout << Instructions << endl;
cout << "Would you like to escape? Yes or No" << endl;
cin >> PlayerStart;
if (!(PlayerStart != "Yes" && PlayerStart != "yes")) {
++PlayerLevel;
}
return 0;
}
int main ()
{
if (PlayerLevel == 0) {
GameStart();
}
while (PlayerLevel <= MaxLevel)
{
bool bLevelComplete = GamePlay();
cin.clear ();
cin.ignore();
}
cout << "You Made it out! Now run before he finds out!" << endl;
return 0;
}
When the type of the input doesn't match the type of the variable that it is being extracted to, cin sets the fail bit. Once this happens, all subsequent reads fail until the stream is reset. The offending characters are still left in the buffer, so that needs to be cleared out as well.
Your usage of cin.clear() and cin.ignore() meant that the fail bit was getting reset, but only one offending character was being removed (cin.ignore() ignores one character by default). This is why you saw the output repeating x times for x erroneous characters.
You could do something like this:
while (PlayerLevel <= MaxLevel)
{
bool bLevelComplete = GamePlay();
if (cin.fail())
{
//Input extraction failed, need to reset stream and clear buffer until newline
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
}
}
When I run the code I get the messege Scattegories.exe has triggered a breakpoint.
It happens after I enter the 12th nuber into my array, but the array still has a "spot" for it.
There is also a thread so maybe it's that, but it seems to work fine.
So I don't know what it is, thank you.
// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
#include <chrono>
#include <thread>
using std::cout;
using std::cin;
using std::string;
using std::getline;
using namespace std::chrono_literals;
using std::this_thread::sleep_for;
void ltr() //gives a random letter
{
char letter;
letter = rand() % 26 + 65; //assigns a random letter in ascii code to a char (resulting in a random letter)
cout << "The letter is " << letter << "\n";
}
void timer()
{
cout << "You got 1.5 minutes to finish\n"; //Changing the duration of the timer is done by changing the value of 'i' in the "for" loop
for (int i = 10; i > 0; i--)
{
sleep_for(1s);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}
void table(int plr)
{
string ctr[12] = { "A cuntry", "A city", "An animal", "A plant", "A object", "A name", "Food", "Drink", "A game", "A movie", "A book", "A famous person" };
string lst[6][12]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
std::thread t1(timer); //gives time to write the words. Optimaly it would run in the background while each player writes the words.
for (int i = 0; i<12; i++) //changing catagory
{
cout << ctr[i] << ": ";
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next player\n";
}
for (int x = 0; x<plr; x++) //this part (the whole "for" loop) is for confirming evreything is writen down
{
cout << "Player number " << x + 1 << ": ";
for (int i = 0; i<12; i++)
{
cout << lst[x][i] << " ";
}
cout << "\n";
}
sleep_for(5s);
}
int points() //points gained per round
{
int a, b, c, sum;
cout << "How many sections only you got?\n"; //worth 15 points
cin >> a;
cout << "How many words only you got?\n"; //worth 10 points
cin >> b;
cout << "How many words you and another person got?\n"; //worth 5 points
cin >> c;
sum = a * 15 + b * 10 + c * 5;
return sum; //Note: It doesn't matter how many sections there are.
}
int act() //running the program
{
int Players, Points[6];
cout << "How many people are playing? (Up to six players)";
cin >> Players;
ltr();
table(Players);
//Points = points();
cout << "You have earned " << Points << " this round\n\n";
return 1;
}
int main()
{
auto start = std::chrono::high_resolution_clock::now();
srand(time(NULL)); //gives a differant pattern of letters every time
int Points;
Points = act();
for (;;) //inf loop
{
int ph;
cout << "Press 1 to continue or anything else to stop\n";
cin >> ph;
if (ph == 1)
{
Points += act(); //keeping score of the rounds
}
else
{
auto end = std::chrono::high_resolution_clock::now();
break;
}
}
cout << "You have earned a total of " << Points << " great job!";
sleep_for(5s); //time to read the last text
return 0;
}
/*
To do list:
-Convert to arduino
-Make timer work in background of of table
-Check if words in the table (for differant players) are the same and give points accordingly
-Check if words are actual words (connect an online dictonary?)
-Make interface? (if possible and I have time to learn how)
-Think of what to do with Hardwear
-Comment rest of the code
*/
std::thread::~thread says this :
If *this has an associated thread (joinable() == true), std::terminate() is called.
If you ever destroy a std::thread that is joinable, std::terminate() is called. Visual Studio kindly breaks on std::terminate() to allow you to inspect what went wrong. In void table(int plr) you create a thread with std::thread t1(timer); but you never join with it or detach from it.
To solve this, your timer method should be changed to return immediately when the player has finished his turn, and then the main thread should join with it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I get the error:
'_sleep': This function or variable has been superceded by newer
library or operating system functionality. Consider using Sleep
instead. See online help for details.
Can you guys and/or girls tell me what library is causing this error?
Code:
// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
using std::cout;
using std::cin;
using std::string;
using std::getline;
void ltr() //gives a random letter
{
srand(time(NULL)); //gives a differant pattern every time
char letter;
letter = rand() % 27 + 64; //assigns a random letter in ascii code to a char (resulting in a random letter)
cout << "The letter is " << letter << "\n";
}
void timer()
{
cout << "You got 1.5 minutes to finish\n";
for (int i = 90; i > 0; i--)
{
if (i % 5 == 0)
cout << i << "\n";
_sleep(1000);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}
void table()
{
int plr, ctr;
string lst[5][20]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cin >> plr >> ctr; //parameters for later
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
timer();
for (int i = 0; i<ctr; i++) //changing catagory
{
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next player\n";
}
for (int x = 0; x<plr; x++) //this part (the whole "for" loop) is for confirming
{
cout << "Player number " << x + 1 << ": ";
for (int i = 0; i<ctr; i++)
{
cout << lst[x][i] << " ";
}
cout << "\n";
}
_sleep(5000);
}
int points() //points per round
{
int a, b, c, sum;
cout << "How many sections only you got?\n"; //worth 15 points
cin >> a;
cout << "How many words only you got?\n"; //worth 10 points
cin >> b;
cout << "How many words you and another person got?\n"; //worth 5 points
cin >> c;
sum = a * 15 + b * 10 + c * 5;
return sum; //Note: It doesn't matter how many sections there are.
}
int act()
{
int Points;
ltr();
table();
Points = points();
cout << "You have earned " << Points << " this round\n\n";
return Points;
}
int main()
{
int Points;
cout << "Starting in five seconds\n";
_sleep(5000);
Points = act();
for (;;) //inf loop
{
int ph;
cout << "Press 1 to continue or anything else to stop\n";
cin >> ph;
if (ph == 1)
{
Points += act();
}
else
{
break;
}
}
cout << "You have earned a total of " << Points << " great job!";
_sleep(5000); //time to read the last text
return 0;
}
/* To do list:
*Convert to arduino
*Make timer work in background of of table
*Check if words in the table (for differant players) are the same and give points accordingly
*Check if words are actual words (connect an online dictonary?)
*Make interface? (if possible and I have time to learn how)
*Think of what to do with Hardwear
*Comment rest of the code
*/
For using Sleep() function you need
#include <windows.h>
I'm writing this program for the game "Scattegories" and I would like to connect some sort of dictionary (to check if the words exist) to the program.
If I were to do that how would I do it?
// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
#include <chrono>
#include <thread>
using std::cout;
using std::cin;
using std::string;
using std::getline;
using namespace std::chrono_literals;
using std::this_thread::sleep_for;
void ltr() //gives a random letter
{
srand(time(NULL)); //gives a differant pattern every time
char letter;
letter = rand() % 26 + 65; //assigns a random letter in ascii code to a char (resulting in a random letter)
cout << "The letter is " << letter << "\n";
}
void timer()
{
cout << "You got 1.5 minutes to finish\n"; //Changing the duration of the timer is done by changing the value of 'i' in the "for" loop
for (int i = 90; i > 0; i--)
{
if (i % 5 == 0)
cout << i << "\n";
sleep_for(1s);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}
void table()
{
int plr, ctr;
string lst[5][20]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cout << "How many players?";
cin >> plr;
cout << "How many catagories?";
cin >> ctr; //parameters for later
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
cout << "Player number " << x+1<<":";
timer(); //gives time to write the words. Optimaly it would run in the background while each player writes the words.
for (int i = 0; i<ctr; i++) //changing catagory
{
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next player\n";
}
for (int x = 0; x<plr; x++) //this part (the whole "for" loop) is for confirming evreything is writen down
{
cout << "Player number " << x + 1 << ": ";
for (int i = 0; i<ctr; i++)
{
cout << lst[x][i] << " ";
}
cout << "\n";
}
sleep_for(5s);
}
int points() //points gained per round
{
int a, b, c, sum;
cout << "How many sections only you got?\n"; //worth 15 points
cin >> a;
cout << "How many words only you got?\n"; //worth 10 points
cin >> b;
cout << "How many words you and another person got?\n"; //worth 5 points
cin >> c;
sum = a * 15 + b * 10 + c * 5;
return sum; //Note: It doesn't matter how many sections there are.
}
int act() //running the program
{
int Points;
ltr();
table();
Points = points();
cout << "You have earned " << Points << " this round\n\n";
return Points;
}
int main()
{
auto start = std::chrono::high_resolution_clock::now();
int Points;
cout << "Starting in five seconds\n";
sleep_for(5s);
Points = act();
for (;;) //inf loop
{
int ph;
cout << "Press 1 to continue or anything else to stop\n";
cin >> ph;
if (ph == 1)
{
Points += act(); //keeping score of the rounds
}
else
{
auto end = std::chrono::high_resolution_clock::now();
break;
}
}
cout << "You have earned a total of " << Points << " great job!";
sleep_for(5s); //time to read the last text
return 0;
}
/*
To do list:
-Convert to arduino
-Make timer work in background of of table
-Check if words in the table (for differant players) are the same and give points accordingly
-Check if words are actual words (connect an online dictonary?)
-Make interface? (if possible and I have time to learn how)
-Think of what to do with Hardwear
-Comment rest of the code
-Make a point count for each player
-change "srand" placement
*/
Please keep in mind that I'm relatively new to programing (almost half a year), so please try to explain it as simple as you can, thanks.
Can be an interesting exercise to implement your own dictionary.
Use a large array of characters to store the words, sorted alphabetically, each null-terminated. In addition, keep an array of indexes, each pointing to the start of a word.
Then implement a dichotomic search for lookup. It will be fairly efficient because you will find a word after at most Log(N) string comparisons, each taking between 1 and L character comparisons, where L is the word length.
A solution based on hashing can be more efficient, but is a little harder to code.
This is a board game created using C++. In order to win, one player must be able to reach the end of the board three times. But the problem is that it is the the first player who is entered into the board game that is always winning. I have a function setup so the that the simulated dice uses a random number-generator. How can I fix this issue?
#include <iostream>
using namespace std;
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <string>
#define SIZE 20 //EDITED: SIZE is Defined at 20 for the number of squares wanted for the board game. Makes is easier for change
//NOTE TO SELF: This is the revamped version. "EDITED" marks addition/change from 'assignment2_fixed.cpp
/**********************
* FUNCTION PROTOTYPES *
***********************/
void displayRules();
void action();
void firstRoll();
void showState();
int spinDie();
bool play();
bool winner();
int square[SIZE]; //For each square on the board, SIZE is Defined
const int loseTurn=1, switchPlace=2, goAgain=3, moveBack=4; //CONSTANT! Labels each action location for each square
int *location, *lastsq, *losTurn; //EDITED: Declared for dynamic allocation for location on board, last square of board, and lost turn
string *names; //EDITED: This is to hold the names of the players
int numPlayers = 0; //Holds the number of players
int turn; //EDITED: First players turn
/************
* FUNCTIONS *
*************/
void displayRules(){ //Displays the rules to the player once the game starts
cout << "Welcome to 3X" << endl;
cout << "The first player to go around the board three times wins!" <<endl;
cout << "The player with the lowest number goes first" << endl;
cout << "The players take turns until one player wins" << endl;
cout << "The players must move forward the number of spaces the die displays" << endl;
cout << "If the player lands on a square with an action, the player must perform that action, otherwise the next player goes" <<endl;
cout << endl << endl;
}
void action(){ //EDITED: This lists actions for each square
square[2] = goAgain;
square[4] = switchPlace;
square[6] = goAgain;
square[8] = loseTurn;
square[11] = goAgain;
square[14] = moveBack;
square[16] = switchPlace;
square[18] = loseTurn;
}
void firstRoll(){ //EDITED: Initializes for the first die roll
numPlayers = spinDie();
for(int i=0; i<numPlayers; i++)
location[i];
for(int i=0; i<numPlayers; i++)
lastsq[i];
for(int i=0; i<numPlayers; i++)
losTurn[i];
}
void showState(){
for(int i=0; i<numPlayers; i++){
cout << "Player " << names[i] << " is at location " << location[i] << endl;
}
for(int i=0; i<numPlayers; i++){
cout << names[i] << " lands on last space " << lastsq[i] << " times " << endl;
}
}
int spinDie(){ //For the dice. Number is generated randomly based on time
int x = rand()%6 +1 ;
cout<< " a "<< x<< " was rolled"<<endl;
return x;
}
bool play(){ //EDITED: Play function through squares
srand(time(0));
while(true){
if(losTurn[turn]){
losTurn[turn] = 0;//EDITED: Finds if player lost turn based on the value of 'turn'
turn = (turn) % numPlayers;
continue;
}
cout << "Turn: "<< names[turn] << endl;
int spot = spinDie(); //EDITED: Players spot on the board based on random number generator
cout << "Number on die : " << spot << endl;
location[turn] += spot;
if(location[turn] >= SIZE-1){
location[turn] -= SIZE;
lastsq[turn]++;
cout << names[turn] << " passes End!"<<endl;
if(winner())
return true;
}
switch(square[location[turn]]){
case goAgain:
cout<<"Action: Go again.\n";
showState();
break;
case loseTurn:
cout<<"Action: Lose turn.\n";
losTurn[turn] += 1;
break;
case switchPlace:
cout<<"Action: Switch places\n";
break;
case moveBack:
cout<<"Action: Move back 2 places.\n";
location[turn] -= 2;
break;
default:
cout<<"Action: None\n";
}
showState();
turn = (turn) % numPlayers;
}
return false;
}
bool winner(){ //Finds the winner who hits the end square three times
if(lastsq[turn] == 3){
cout<<"\n"<<names[turn]<<" WIN!\n";//Prints name of player with their turn
return true;
}
return false;
}
/***************
* MAIN PROGRAM *
****************/
int main(){
srand(time(0)); //Makes time based number in die random
displayRules(); //Diplays the rules first
cout << "Please type in the number of players between 1-6 : " << endl;
cin >> numPlayers;
while ((numPlayers < 1) || (numPlayers > 6)) //EDITED: Guard against any values outside of 1-6
{
cout << "ERROR: Enter a value from 1 - 6: ";
cin >> numPlayers;
}
names = new string[numPlayers]; //EDITED: Dynamically allocates array of string to hold names of players
location = new int[numPlayers]; //EDITED: Dynamically allocates array of int to hold locations of players
losTurn = new int[numPlayers]; //EDITED: Dynamically allocates array of int to hold lost turn of players
lastsq = new int[numPlayers]; //EDITED: Dynamically allocates array of int to hold count of each time player reach end square
for(int i=0; i<numPlayers; i++){
cout << "Enter name of player " << i+1 << " " << endl; //EDITED: To get name of each player starting with Player 1 (i+1)
cin >> names[i]; //EDITED: Gets names of players into the dynamically allocated strings
}
while(true){//EDITED: Continues the loop
if(play())//EDITED: If the "Play" function is true
break;//EDITED: Breaks once the winner is found
}
return 0;
}
Although your question is vague, I can give you some help to start you off. First off I'm going to show your code for the random factor on the dice.
int spinDie(){ //For the dice. Number is generated randomly based on time
int x = rand()%6 +1 ;
cout<< " a "<< x<< " was rolled"<<endl;
return x;
This code makes it so that the compiler will generate ANY number within an integer range. Then you divide that random number by 6 and find the remainder with the remainder operator (%). The +1 will add to the remainder if it is a factor of 6 such as 36. Your code is fine. The problem is that it is based off of time. The first one on the board probably gets similar or the same numbers each time and the second one does too. Which would explain the first one always winning. I'm assuming the first one gets similar or the same rolls every time because of your lack of explanation of the SPECIFIC problem. Hope this helped a little lol.