interface IJumper{
int start;
int end;
}
class Snake implements IJumper{
public Snake(int start, int end){
this.start = start;
this.end = end;
if(start < end)
throw Exception("Invalid Snake");
}
}
class Ladder implements IJumper{
public Ladder(int start, int end){
this.start = start;
this.end = end;
}
if(start > end)
throw Exception("Invalid Ladder");
}
class Player{
Account account;
String specialId;
bool isActive;
int rollDice(){
/*Generate random numbers from 1 to 6*/
}
}
class Account{
string firstName;
string lastName;
string email;
string phone;
int points;
}
class SALGame{
int board[100];
List<Player> players;
List<IJumper> snakes;
List<IJumper> ladders'
Player winner;
bool isActive = false;
public SALGame(List<Players> players, List<IJumper> snakes, List<IJumper> ladders){
this.players = players;
this.snakes = snakes;
this.ladders = ladders;
startGame();
}
private void cleanBoard(){
for(int i=0; i<100; i++) board[i] = -1;
}
private void startGame(){
cleanBoard();
for(int i=0; i<snakes.size(); i++) board[snakes[i].start] = snakes[i].end;
for(int i=0; i<ladders.size(); i++) board[ladders[i].start] = ladders[i].end;
isActive = true;
play();
}
private void play(){
queue<pair<Player, int>> q;
for(int i=0; i<players.size(); i++) q.push(make_pair(players[i], 0));
while(!q.empty()){
Player curr = q.front().first;
int position = q.front().second;
q.pop();
//Simulating dice throw
Thread.currentThread().sleep(10000);
int dx = player.rollDice();
if(position + dx == 99){
winner = player;
break;
}
if(position + dx > 99)
continue;
if(board[position+dx]==-1)
q.push(make_pair(player, position+dx));
else
q.push(make_pair(player, board[position+dx]));
}
}
public void resetGame(){
cleanBoard();
}
}
class System{
List<SALGame> games;
bool startGame(List<Players> players, List<IJumper> snakes, List<IJumper> ladders){
games.add(new SALGame(players, snakes, ladders));
}
for(int i=0; i<games.length(); i++)
cout<<games[i].winner.firstname<<endl;
}