public class SmartAI extends MinMaxAI
This implementation uses a search depth of 4, only places moves adjacent to moves that have already been played, and uses a reasonable heuristic measure of goodness (described below).
Modifier and Type | Method and Description |
---|---|
int |
estimate(Board b)
A particular line of 5 adjacent cells is "winnable" for player p if
it does not contain any of the opponent's marks.
|
java.lang.Iterable<Location> |
moves(Board b)
Return the set of locations that are adjacent to played locations, or
the center of the board if no moves have been played.
|
boolean |
reasonableMove(Board b,
Location loc)
Returns true iff loc is empty and has a neighbor.
|
int |
score(Board b,
Player p)
return the positive score for player p
|
int |
score(Board b,
Player p,
Line s)
Return the score for player p, for the line s.
|
gameChanged
public SmartAI(Player me)
public int estimate(Board b)
We measure goodness by counting the number of winnable lines, and scoring them based on the number of the player's marks as follows:
Number of marks | Score |
---|---|
0 | 0 |
1 | 1 |
2 | 10 |
3 | 100 |
4 | 1000 |
5 | 10000 |
Note that overlapping segments will be counted multiple times, so that, for example, the following board:
O O OXO O Owill count as 5 points for X, since there are 5 vertical line segments passing through X, while
OOO OXO O Owill only count for 1 point, since only the line segment proceeding down from X is winnable. The estimate is the difference between the player's score and his opponent's
public java.lang.Iterable<Location> moves(Board b)