Action Contract
When writing Actions a few points are important to bear in mind:
- Don’t store any object references (unless you are absolutely certain the are immutable)! These refer to a specific game state and when that is copied they will no longer point to the correct place. This is the most common mistake when writing your first game (see Forward Model tips).
- Ensure that the hashCode() and equals() methods are implemented properly. hashCode() is important as this is used as the Action key in much of the internal framework (especially in MCTS). If the hashcode of an Action changes, or you break the java equals() contract, then unexpected things will happen.
- Where possible, encapsulate all logic for a specific action in the Action class. This is helpful in avoiding code-bloat in ForwardModel. For complicated actions consider setting up an action sequence.