The Evaluator
While the Ghost Ships provide information on where enemy ships may be and where to shoot next,
they don't provide an obvious choice of what option a player should take: fire, move, or rotate.
For IntelligentPlayer the firing choices are more refined. It can,
- Fire randomly. This just chooses a random square and fires a missile at it. A
player's own ships are avoided.
- Fire randomly on the far half of the board. This option is provided because,
initially, enemy ships can only exist in the far half of the board. We provided this option to
see if the learning algorithm would detect its usefulness.
- Fire intelligently. This chooses the square with the highest probability of
containing an enemy ship (as calculated by the Ghost Ship system) and fires at it.
To decide what move to make, we provided a weighted evaluation function. The function considers
some thirty boolean variables with associated weights, and considers them for each possible
command it could execute (if it is a move or rotate command, the particular ship in question is
given as a parameter). If the boolean variable (e.g., ``Have more than 25% of my ship segments
been shot?'') is true, the the associated weight is added to a score. The command with the
highest score is executed by the player.
The boolean variables we have implemented are (similar ones have been grouped together):
- Ship has been shot.
- Ship has been sunk.
- Ghost ships exist.
- We have more/fewer ships than our opponent.
- Board is 25% / 50% / 75% cleared.
- More than 5 / 10 / 15 / 20 / 40 moves have past.
- Most likely shot is more than 25% / 50% / 75% / 100% probable.
- Ship can move in given direction.
- Ship can move in any direction.
- Ship can rotate.
- More than 25% / 50% / 75% of our ship units shot.
- More than 25% / 50% / 75% of opponent ship units shot.
- Unshot opponent ship unit visible.
- Move will increase GG.
- Move will decrease GG.
- Move will not change GG.
GG is a value representing the shortest Manhattan distance from any of your ship segments to any
other Ghost Ship units. (It's called GG because, ``Good God, we couldn't think of a shorter
name for it!'')
The functionality is provided by the Evaluator class. Evaluator manages the
weights (as an array of floats) and the boolean variables (as member functions). It also
provides methods to read weights from and write them to disk, to mutate a set of weights, and to
combine two sets of weights and derive a new one. These features are made use of by the Coach.