-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
166 lines (145 loc) · 5.17 KB
/
Copy pathGame.java
File metadata and controls
166 lines (145 loc) · 5.17 KB
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
import java.util.ArrayList;
import java.util.Random;
public class Game {
// give everything a difficulty
// generate random robots based on difficulty distribution
ArrayList<Robot> blueAlliance; // Our team
ArrayList<Robot> redAlliance; // Opposing team
int redPoints;
int bluePoints;
int redRPoints;
int blueRPoints;
public Game(ArrayList<Robot> blueAlliance, ArrayList<Robot> redAlliance) {
this.blueAlliance = blueAlliance;
this.redAlliance = redAlliance;
}
// always randomize opponents, ask how many alliacne memebers to assign values
// to
static public Robot randomizeRobot() {
Random numGen = new Random();
boolean shootLowAuto = false;
if (numGen.nextDouble() < Constants.CHANCE_LOW_AUTO) {
shootLowAuto = true;
}
boolean shootLowTele = false;
if (numGen.nextDouble() < Constants.CHANCE_LOW_TELE) {
shootLowTele = true;
}
double autoAccuracy = (Constants.MIN_RANDOM_AUTO_ACCURACY + numGen.nextInt(Constants.MAX_RANDOM_AUTO_ACCURACY-Constants.MIN_RANDOM_AUTO_ACCURACY)) / 100; // percentage
double teleAccuracy = (Constants.MIN_RANDOM_TELE_ACCURACY + numGen.nextInt(Constants.MAX_RANDOM_TELE_ACCURACY-Constants.MIN_RANDOM_TELE_ACCURACY)) / 100;
int secondsPerCycleAuto = Constants.MIN_RANDOM_AUTO_CYCLE + numGen.nextInt(Constants.MAX_RANDOM_AUTO_CYCLE-Constants.MIN_RANDOM_AUTO_CYCLE);
int secondsPerCycleTele = Constants.MIN_RANDOM_TELE_CYCLE + numGen.nextInt(Constants.MAX_RANDOM_TELE_CYCLE-Constants.MIN_RANDOM_TELE_CYCLE);
int hangPoints = 0;
switch (numGen.nextInt(5)) {
case 0:
hangPoints = 0;
break;
case 1:
hangPoints = 4;
break;
case 2:
hangPoints = 6;
break;
case 3:
hangPoints = 10;
break;
case 4:
hangPoints = 15;
break;
}
int hangTime = Constants.MIN_RANDOM_HANGTIME + numGen.nextInt(Constants.MAX_RANDOM_HANGTIME); // in seconds
Robot robot = new Robot(shootLowAuto, shootLowTele, autoAccuracy, teleAccuracy, secondsPerCycleAuto,
secondsPerCycleTele, hangPoints, hangTime);
return robot;
}
public int getBlueAlliancePoints() {
int totalPoints = 0;
for (Robot robot : blueAlliance) {
totalPoints += robot.pointsScored();
}
return totalPoints;
}
public int getRedAlliancePoints() {
int totalPoints = 0;
for (Robot robot : redAlliance) {
totalPoints += robot.pointsScored();
}
return totalPoints;
}
public int getBlueAllianceRPs() {
int totalPoints = 0;
if (getBlueAlliancePoints() > getRedAlliancePoints()) {
totalPoints = 2;
} else if (getRedAlliancePoints() == getBlueAlliancePoints()) {
totalPoints = 1;
}
int totalHangPoints = 0;
for (Robot robot : blueAlliance) {
totalHangPoints += robot.getHangPoints();
}
if (totalHangPoints >= 16) {
totalPoints += 1;
}
int totalBallsScored = 0;
for (Robot robot : blueAlliance) {
totalBallsScored += robot.teleopBallsScored();
totalBallsScored += robot.autoBallsScored();
}
if (quintet(blueAlliance)) {
if (totalBallsScored >= 18) {
totalPoints += 1;
}
} else {
if (totalBallsScored >= 20) {
totalPoints += 1;
}
}
return totalPoints;
}
public int getRedAllianceRPs() {
int totalPoints = 0;
if (getRedAlliancePoints() > getBlueAlliancePoints()) {
totalPoints = 2;
} else if (getRedAlliancePoints() == getBlueAlliancePoints()) {
totalPoints = 1;
}
int totalHangPoints = 0;
for (Robot robot : redAlliance) {
totalHangPoints += robot.getHangPoints();
}
if (totalHangPoints >= 16) {
totalPoints += 1;
}
int totalBallsScored = 0;
for (Robot robot : redAlliance) {
totalBallsScored += robot.teleopBallsScored();
totalBallsScored += robot.autoBallsScored();
}
if (quintet(redAlliance)) {
if (totalBallsScored >= 18) {
totalPoints += 1;
}
} else {
if (totalBallsScored >= 20) {
totalPoints += 1;
}
}
return totalPoints;
}
public String winner() {
String winner = "Blue Alliance";
if (getRedAlliancePoints() > getBlueAlliancePoints()) {
winner = "Red Alliance";
} else if (getRedAlliancePoints() == getBlueAlliancePoints()) {
winner = "Tie";
}
return winner;
}
public boolean quintet(ArrayList<Robot> alliance) {
int totalBallsScored = 0;
for (Robot robot : alliance) {
totalBallsScored += robot.autoBallsScored();
}
return (totalBallsScored >= 5);
}
}