dk.brics.bisim.controller
Class AIDefender

java.lang.Object
  extended by dk.brics.bisim.controller.AIDefender
All Implemented Interfaces:
AI, java.lang.Runnable

public class AIDefender
extends java.lang.Object
implements AI

A computer player with the defender role. The defender is passed a partitioned state space and if there exists a perfect strategy.

If so, the defender proceeds as follows:

  1. Get the name of the action chosen by the attacker.
  2. Get the block number of the current node on the attacker's side.
  3. Find a node on the defender's side, such that the node is reachable from the defender's current node through the action. (See also the method findNodeInBlock in the StateSpace class.)
If not, use the following strategy:
  1. Try to find a node in the same block as the attacker's current node.
  2. If that fails, among the candidate configurations the one with the greatest distance to the losing configuration (the accept node of the configuration graph). We can never be sure to win, so we can only attempt not to lose.

Author:
Martin Mosegaard martinm@daimi.au.dk

Field Summary
private  boolean alive
           
private  GameModel gameModel
           
private  MessagePasser messagePasser
           
 
Fields inherited from interface dk.brics.bisim.controller.AI
AI_SLEEP
 
Constructor Summary
AIDefender(GameModel gameModel, MessagePasser messagePasser)
          Create a defender and, if there isn't a winning strategy, annotate configurations with distances to the losing configuration.
 
Method Summary
private  void defenderStep(att.grappa.Node toNode)
          Send a message to the message passer with the name of the node we have chosen to step to.
private  att.grappa.Node getAnyNode(java.lang.String attackerAction, int attackerSide, StateSpace stateSpace)
          Get any node which is the head of an edge from our current node, such that the edge label equals the attacker's action.
private  att.grappa.Node getPerfectNode(java.lang.String attackerAction, int attackerSide, StateSpace stateSpace)
          Find a perfect node in the state space, i.e. a node which resides in the same block as the current node on the attacker's side.
 void kill()
          Tell the AI to stop running.
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gameModel

private GameModel gameModel

messagePasser

private MessagePasser messagePasser

alive

private boolean alive
Constructor Detail

AIDefender

public AIDefender(GameModel gameModel,
                  MessagePasser messagePasser)
Create a defender and, if there isn't a winning strategy, annotate configurations with distances to the losing configuration.

Parameters:
gameModel - A game model from which to get the status and the LTSs
messagePasser - Used for sending move messages to the human player
See Also:
ConfigurationGraph
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

defenderStep

private void defenderStep(att.grappa.Node toNode)
Send a message to the message passer with the name of the node we have chosen to step to.

Parameters:
toNode - The node we have chosen to step to.

getPerfectNode

private att.grappa.Node getPerfectNode(java.lang.String attackerAction,
                                       int attackerSide,
                                       StateSpace stateSpace)
Find a perfect node in the state space, i.e. a node which resides in the same block as the current node on the attacker's side.

Parameters:
attackerAction - The attacker's action
attackerSide - The attacker's side
Returns:
A perfect node if it exists, or null otherwise

getAnyNode

private att.grappa.Node getAnyNode(java.lang.String attackerAction,
                                   int attackerSide,
                                   StateSpace stateSpace)
Get any node which is the head of an edge from our current node, such that the edge label equals the attacker's action. Get the number of choices. If there are more than one, choose the one with the greatest distance to the accept node.

Parameters:
attackerAction - The attacker's action
attackerSide - The attacker's side
Returns:
Any node which is the head of an edge from our current node, such that the edge label equals the attacker's action.

kill

public void kill()
Description copied from interface: AI
Tell the AI to stop running.

Specified by:
kill in interface AI