-
Notifications
You must be signed in to change notification settings - Fork 0
/
Match.java
176 lines (149 loc) · 5.94 KB
/
Match.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package thesis;
import java.util.ArrayList;
/**
*
* @author natha_000
*/
public class Match {
private Player player1, player2, winner, loser, playerBetOn;
private int matchNumber, roundNumber, bet, payout;
private double player1WinProbablity;
private boolean isBetting;
public Match (Player p1, Player p2, int mNum, int rNum){
this.player1 = p1;
this.player2 = p2;
this.matchNumber = mNum;
this.roundNumber = rNum;
}
public Match (Player p1, Player p2){
this.player1 = p1;
this.player2 = p2;
}
public Player getPlayer1(){
return this.player1;
}
public Player getPlayer2(){
return this.player2;
}
public void setPlayer1(Player newPlayer){
this.player1 = newPlayer;
}
public void setPlayer2(Player newPlayer){
this.player2 = newPlayer;
}
public void setP1WinProbability(double probability){
this.player1WinProbablity = probability;
}
public double getP1WinProbability(){
return this.player1WinProbablity;
}
public void generateWinProbability(){
double ELOdiff = player2.getELOscore() - player1.getELOscore();
double ELODiffDivided = ELOdiff / 400;
double finalStep = 1 + Math.pow(10, ELODiffDivided);
double p1WinLikelihood = 1/finalStep; // p1winlikelihood is likelihood (out of 1) that player 1 wins
setP1WinProbability(p1WinLikelihood);
}
public String randomPredictMatch (){
generateWinProbability();
int p1WinLikelihoodMultiplied = (int)(getP1WinProbability() * 100); // multiplying p1winlikelihood by 100 to get a whole number for use in RNG
int newRandomNumber = (int) (Math.random() * 100);
if (newRandomNumber > (100 - p1WinLikelihoodMultiplied)){
setMatchWinner(player1);
setMatchLoser(player2);
int newELOP1 = (int) (player1.getELOscore() + (20 * (1 - getP1WinProbability()))); // calculating new ELO scores, 1 meaning player won match and 0 meaning player lost
player1.setELOscore(newELOP1);
int newELOP2 =(int) (player2.getELOscore() + (20 * (0 - (1 - getP1WinProbability())))); // subtracting p1winlikelihood from 1 yields likelihood that player 2 will win match
player2.setELOscore(newELOP2);
if(newELOP2 < 0){
player2.setELOscore(0);
}
return player1.getName();
} else {
setMatchWinner(player2);
setMatchLoser(player1);
int newELOP1 =(int) (player1.getELOscore() + (20 * (0 - getP1WinProbability())));
player1.setELOscore(newELOP1);
if(newELOP1 < 0){
player1.setELOscore(0);
}
int newELOP2 = (int) (player2.getELOscore() + (20 * (1 - (1 - getP1WinProbability()))));
player2.setELOscore(newELOP2);
return player2.getName();
}
}
public void updateELO(Player p1, Player p2){
this.player1 = p1;
this.player2 = p2;
generateWinProbability(); // generating win probability so we can use it to adjust ELO ratings of players
if(this.winner == this.player1){
int newP1ELO = (int) (player1.getELOscore() + (20 * (1 - getP1WinProbability()))); // same thing as in randomPredictMatch, we calculate new elo score based on expected match result
player1.setELOscore(newP1ELO);
int newP2ELO = (int) (player2.getELOscore() + (20 * (0 - (1 - getP1WinProbability()))));
player2.setELOscore(newP2ELO);
} else if (this.winner == this.player2){
int newP1ELO =(int) (player1.getELOscore() + (20 * (0 - getP1WinProbability())));
player1.setELOscore(newP1ELO);
int newP2ELO = (int) (player2.getELOscore() + (20 * (1 - (1 - getP1WinProbability()))));
player2.setELOscore(newP2ELO);
}
}
public void betOnMatch(int betAmount, Player playerChosen){
isBetting = true;
playerBetOn = playerChosen;
bet = betAmount;
}
public void betOnPlayer(Player playerChosen){
isBetting = true;
playerBetOn = playerChosen;
}
public void placeBetAmount(int betAmount){
isBetting = true;
bet = betAmount;
}
public int payOutBet(){
if(playerBetOn == getMatchWinner() && playerBetOn == player1){
payout = (int)(bet / (getP1WinProbability()));
} else if (playerBetOn == getMatchWinner() && playerBetOn == player2){
payout = (int)(bet / (1 - getP1WinProbability()));
} else {
payout = 0;
}
return payout;
}
public void setMatchWinner(Player whoWon){
this.winner = whoWon;
}
public void setMatchLoser(Player whoLost){
this.loser = whoLost;
}
public Player getMatchWinner(){
return this.winner;
}
public Player getMatchLoser(){
return this.loser;
}
public void setPayout(int pay){
this.payout = pay;
}
public int getPayout(){
return this.payout;
}
public boolean checkIfBetting(){
return this.isBetting;
}
public ArrayList<Player> getPlayers(){
ArrayList<Player> playersInMatch = new ArrayList<Player>();
playersInMatch.add(player1);
playersInMatch.add(player2);
return playersInMatch;
}
public String toString(){
return player1.getName() + " " + player1.getELOscore() + " vs " + player2.getName() + " " + player2.getELOscore() + "\n";
}
}