PawnXIIX
07-04-2012, 09:32 PM
Hey guys, I have an event simulator that I wrote over the last hour and a half. I guess I need to get out more if this is "fun".
Here is what the algorithm is based on:
- If you are falling behind, you have a better chance of getting an item
- Fail rate is still 2/3, 1/2, 0
- Random items are not calculated. Sorry :P
- Perfect opening theory, meaning 168 openings over 7 days.
The winner took 31 chips in this event trial with 168 attempts. There are 50 players here.
With my events I took an average of just over 28 chips to win the event. Remember...that's even with pefect opening. This I believe is because I was very low with my initial idea on the odds of finding a chip.
public class newEvent
{
public static void main(String [] args)
{
players = new player[TOT_PLAYERS];
for(int i = 0; i < TOT_PLAYERS; i++)
players[i] = new player((int)(Math.random()*3), i);
for(int i = 0; i < TOT_OPENS; i++)
{
for(int j = 0; j < TOT_PLAYERS; j++)
{
players[j].logAttempt();
boolean opened = false;
if(players[j].getOpenType() == 2)
opened = true;
else if((players[j].getOpenType() == 1) && (Math.random() > .5))
opened = true;
else if((players[j].getOpenType() == 0) && (Math.random() > .666))
opened = true;
if(opened)
{
players[j].logOpen();
double tempOdds = calcComputerChipOdds(players[j]);
if(Math.random() < tempOdds)
{
players[j].giveComputerChip();
System.out.println("Computer Chip for player " + j);
}
else
{
System.out.println("Random item for player " + j);
}
}
else
{
System.out.println("Fail for player " + j);
}
}
}
player winner = getCurrentLeader();
System.out.println("Winner is player number: " + winner.getNumber() + " with " + winner.getComputerChips() + " chips.");
}
private static double calcComputerChipOdds(player temp)
{
player leader = getCurrentLeader();
double newRate = CHIP_RATE + (CHIP_RATE * (leader.getComputerChips() - temp.getComputerChips()));
//System.out.println(newRate);
newRate = ((newRate > .5) ? .5 : newRate);
return newRate;
}
private static player getCurrentLeader()
{
int maxLocation = 0;
int leader = players[maxLocation].getComputerChips();
for(int i = 1; i < TOT_PLAYERS; i++)
{
if(players[i].getComputerChips() > leader)
{
maxLocation = i;
leader = players[maxLocation].getComputerChips();
}
}
return players[maxLocation];
}
public static final int TOT_PLAYERS = 50;
public static final int TOT_OPENS = 168;
public static final String [] OPEN_TYPE = {"Free", "Cash", "Gold"};
public static final String [] REWARDS = {"Chip", "300xRP", "$10,000", "$50,000", "Racer Z", "Deviant Coat", "Hitman Sniper Rifle"};
public static final double CHIP_RATE = .5 / REWARDS.length;
public static player [] players;
}
public class player
{
public player(int openType, int playerNumber)
{
goldUsed = 0;
totalAttempts = 0;
computerChips = 0;
successfulOpens = 0;
this.openType = openType;
this.playerNumber = playerNumber;
}
public int getOpenType()
{
return openType;
}
public void giveComputerChip()
{
computerChips++;
}
public void logOpen()
{
successfulOpens++;
if(getOpenType() == 2)
goldUsed++;
}
public void logAttempt()
{
totalAttempts++;
}
public int getComputerChips()
{
return computerChips;
}
public int getNumber()
{
return playerNumber;
}
private int openType, goldUsed, totalAttempts, computerChips, successfulOpens, playerNumber;
}
Later on tonight I am going to run a full scale example with a few hundred people with a realistic opening number. Maybe even later I'll run with a few thousand people.
Anyone have anything that you see wrong? I am open to criticism and anything that I did wrong :)
Here is what the algorithm is based on:
- If you are falling behind, you have a better chance of getting an item
- Fail rate is still 2/3, 1/2, 0
- Random items are not calculated. Sorry :P
- Perfect opening theory, meaning 168 openings over 7 days.
The winner took 31 chips in this event trial with 168 attempts. There are 50 players here.
With my events I took an average of just over 28 chips to win the event. Remember...that's even with pefect opening. This I believe is because I was very low with my initial idea on the odds of finding a chip.
public class newEvent
{
public static void main(String [] args)
{
players = new player[TOT_PLAYERS];
for(int i = 0; i < TOT_PLAYERS; i++)
players[i] = new player((int)(Math.random()*3), i);
for(int i = 0; i < TOT_OPENS; i++)
{
for(int j = 0; j < TOT_PLAYERS; j++)
{
players[j].logAttempt();
boolean opened = false;
if(players[j].getOpenType() == 2)
opened = true;
else if((players[j].getOpenType() == 1) && (Math.random() > .5))
opened = true;
else if((players[j].getOpenType() == 0) && (Math.random() > .666))
opened = true;
if(opened)
{
players[j].logOpen();
double tempOdds = calcComputerChipOdds(players[j]);
if(Math.random() < tempOdds)
{
players[j].giveComputerChip();
System.out.println("Computer Chip for player " + j);
}
else
{
System.out.println("Random item for player " + j);
}
}
else
{
System.out.println("Fail for player " + j);
}
}
}
player winner = getCurrentLeader();
System.out.println("Winner is player number: " + winner.getNumber() + " with " + winner.getComputerChips() + " chips.");
}
private static double calcComputerChipOdds(player temp)
{
player leader = getCurrentLeader();
double newRate = CHIP_RATE + (CHIP_RATE * (leader.getComputerChips() - temp.getComputerChips()));
//System.out.println(newRate);
newRate = ((newRate > .5) ? .5 : newRate);
return newRate;
}
private static player getCurrentLeader()
{
int maxLocation = 0;
int leader = players[maxLocation].getComputerChips();
for(int i = 1; i < TOT_PLAYERS; i++)
{
if(players[i].getComputerChips() > leader)
{
maxLocation = i;
leader = players[maxLocation].getComputerChips();
}
}
return players[maxLocation];
}
public static final int TOT_PLAYERS = 50;
public static final int TOT_OPENS = 168;
public static final String [] OPEN_TYPE = {"Free", "Cash", "Gold"};
public static final String [] REWARDS = {"Chip", "300xRP", "$10,000", "$50,000", "Racer Z", "Deviant Coat", "Hitman Sniper Rifle"};
public static final double CHIP_RATE = .5 / REWARDS.length;
public static player [] players;
}
public class player
{
public player(int openType, int playerNumber)
{
goldUsed = 0;
totalAttempts = 0;
computerChips = 0;
successfulOpens = 0;
this.openType = openType;
this.playerNumber = playerNumber;
}
public int getOpenType()
{
return openType;
}
public void giveComputerChip()
{
computerChips++;
}
public void logOpen()
{
successfulOpens++;
if(getOpenType() == 2)
goldUsed++;
}
public void logAttempt()
{
totalAttempts++;
}
public int getComputerChips()
{
return computerChips;
}
public int getNumber()
{
return playerNumber;
}
private int openType, goldUsed, totalAttempts, computerChips, successfulOpens, playerNumber;
}
Later on tonight I am going to run a full scale example with a few hundred people with a realistic opening number. Maybe even later I'll run with a few thousand people.
Anyone have anything that you see wrong? I am open to criticism and anything that I did wrong :)