-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtroposPlayer.java
More file actions
executable file
·149 lines (119 loc) · 2.96 KB
/
AtroposPlayer.java
File metadata and controls
executable file
·149 lines (119 loc) · 2.96 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
/**
* @file AtroposPlayer.java
* @author Kyle Burke <paithan@cs.bu.edu>
* @date
*
* @brief An opponent for the game Atropos
*
*/
//package something;
import java.lang.*;
import java.io.*;
import java.util.*;
public class AtroposPlayer {
//instance variables
/**
* Indicates the level of playing ability of this opponent.
*/
//private int level;
/**
* Name of this player.
*/
protected String name;
/**
* Blank Color.
*/
private static final int UNCOLORED = 0;
/**
* Color Red.
*/
public static final int RED = 1;
/**
* Color Blue.
*/
public static final int BLUE = 2;
/**
* Color Green.
*/
public static final int GREEN = 3;
//public methods
/**
* Class constructor.
*
* @param paramname Param description.
*/
public AtroposPlayer(String name) {
this.name = name;
}
/**
*
*/
public AtroposCircle getNextPlay(AtroposState state) {
Vector circles = new Vector();
AtroposCircle circle;
int randomIndex;
for (Iterator circleIterator = state.playableCircles();
circleIterator.hasNext(); ) {
circle = (AtroposCircle) circleIterator.next();
if (!this.wouldLose(state.clone(), circle.clone(), this.RED) ||
!this.wouldLose(state.clone(), circle.clone(), this.BLUE) ||
!this.wouldLose(state.clone(), circle.clone(), this.GREEN)) {
circles.add(circle);
}
}
if (circles.isEmpty()) {
//no moves are safe. Time to lose
Iterator circleIterator = state.playableCircles();
circle = (AtroposCircle) circleIterator.next();
randomIndex = this.RED;
} else {
randomIndex = (int) Math.floor(circles.size() * Math.random());
circle = (AtroposCircle) circles.get(randomIndex);
//choose a random color
randomIndex = (int) Math.floor(3 * Math.random()) + 1;
while (this.wouldLose(state.clone(), circle.clone(), randomIndex)) {
randomIndex = (int) Math.floor(3 * Math.random()) + 1;
}
}
circle = circle.clone();
circle.color(randomIndex);
return circle;
}
/**
* Returns the name of this player.
*/
public String getName() {
return this.name;
}
//private methods
/**
* Determines whether the specified play would lose.
*/
private boolean wouldLose(AtroposState state,
AtroposCircle circle, int color) {
circle.color(color);
state.makePlay(circle);
return state.isFinished();
}
//toString
/**
* Returns a string version of this.
*
* @param indent Indentation string.
*/
public String toString(String indent){
String string = "";
return string;
}
/**
* Returns a string version of this.
*/
public String toString() {
return this.toString("");
}
/**
* Main method for testing.
*/
public static void main(String[] args) {
}
} //end of AtroposPlayer.java