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,

  1. Fire randomly. This just chooses a random square and fires a missile at it. A player's own ships are avoided.
  2. 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.
  3. 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):

  1. Ship has been shot.
  2. Ship has been sunk.
  3. Ghost ships exist.
  4. We have more/fewer ships than our opponent.
  5. Board is 25% / 50% / 75% cleared.
  6. More than 5 / 10 / 15 / 20 / 40 moves have past.
  7. Most likely shot is more than 25% / 50% / 75% / 100% probable.
  8. Ship can move in given direction.
  9. Ship can move in any direction.
  10. Ship can rotate.
  11. More than 25% / 50% / 75% of our ship units shot.
  12. More than 25% / 50% / 75% of opponent ship units shot.
  13. Unshot opponent ship unit visible.
  14. Move will increase GG.
  15. Move will decrease GG.
  16. 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.