-
Notifications
You must be signed in to change notification settings - Fork 0
/
foosFoo.java
122 lines (92 loc) · 3.81 KB
/
foosFoo.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
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.lang.System;
import java.util.Arrays;
class foosFoo {
public static int NUM_FOOSPLAYERS = 26;
public static int NUM_FIELDED = 22;
public static int ITER_PER_QUARTER = 200;
public static int myType = -1;
public static String fileName = "yifan_itr_1.txt";
public static int teamScore = 0;
/**
* keep track of the games played and choose based on their preportions
* type result is even, offensive and defensive
* initalized as 1:1:1 for math convenience
*/
public static int[] GAME_TYPE_RESULT = new int[]{1,1,1};
public static void main(String[] args) {
int[] game_state;
if (args.length != 1) {
System.out.println("Usage: java foosteam GAMEID"
+ "\n\tGAMEID = 0 creates a new game"
+ "\n\tGAMEID = WXYZ connect to a specific game");
return;
}
double time = System.currentTimeMillis();
BufferedWriter outBuffer = null;
try {
FileWriter fstream = new FileWriter(fileName);
outBuffer = new BufferedWriter(fstream);
} catch (Exception e) {
System.out.println("canot write to file: "+fileName);
}
// Connect to a FoosGame with id from the command line
FoosGame game = new FoosGame(args[0]);
myType = Strategies.chooseInitType(GAME_TYPE_RESULT);
try {
outBuffer.write("the play type is: "+myType);
} catch (Exception e) {
System.out.println("cannot write myType: "+myType);
}
int[] roster = helper.rowNumToRoster(Strategies.INIT_TYPES[myType]);
while (true) {
// Send the roster and get the game state
game_state = game.make_move(roster);
if (game_state[2] == 4 * ITER_PER_QUARTER)
break;
// every quater choose a new roaster
else if ((game_state[2]%ITER_PER_QUARTER) == 0) {
// update myType!
myType = Strategies.chooseInitType(GAME_TYPE_RESULT);
// update roaster --- no longer contrained by moving by one!
int[] init = helper.rowNumToRoster(Strategies.INIT_TYPES[myType]);
// update off the tired one
roster = Strategies.updateInitRosterForTired(init, game_state);
} else {
// Use the game state to determine the next move
roster = new_move(game_state);
}
if (!game.is_valid(roster)) {
System.out.println("ILLEGAL MOVE with the following roster");
System.out.println(Arrays.toString(roster));
break;
}
// keep track of performance
if (game_state[0] > teamScore) {
GAME_TYPE_RESULT[myType] += 1;
teamScore = game_state[0];
try {
outBuffer.write("we won via: \n"+Arrays.toString(game_state));
} catch (Exception e) {
System.out.println("cannot write game_state");
}
}
}
System.out.println("Final Score: " + game_state[0] + " - " + game_state[1]);
if (game_state[0] > game_state[1])
System.out.println("WIN!");
if (game_state[0] == game_state[1])
System.out.println("Tie Game");
try {
outBuffer.close();
} catch (Exception e) {
System.out.println("caught exception before it killed us");
}
System.out.println("and the types did:"+Arrays.toString(GAME_TYPE_RESULT));
}
public static int[] new_move(int[] game_state) {
int[] newRoster = Strategies.moveBasedOnFatigue(game_state);
return newRoster;
}
}