dk.brics.bisimulationGame.controller
Class AIDefender

java.lang.Object
  extended by dk.brics.bisimulationGame.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, try to avoid suspicious configurations:
    Build a configuration graph and mark a set of nodes as suspicious; namely those nodes, or configurations, which have edges to the accept node. Then at each step, when there are more choices, attempt to avoid reaching a suspicious configuration.
    We can never be sure to win, so we can only attempt not to lose.
    The concept of suspicious configurations can probably be improved.
  3. If that fails, just try to match the action from the current node.

Author:
Martin Mosegaard martinm@daimi.au.dk

Field Summary
private  boolean alive
           
private  GameModel gameModel
           
private  MessagePasser messagePasser
           
private  StateSpace stateSpace
           
private  java.util.HashSet<CGNode> suspicious
          A set of suspicious nodes.
 
Fields inherited from interface dk.brics.bisimulationGame.controller.AI
AI_SLEEP
 
Constructor Summary
AIDefender(GameModel gameModel, MessagePasser messagePasser, StateSpace stateSpace, boolean winning)
          Creates a defender and, if there isn't a winning strategy, computes a set of suspicious configurations from a configuration graph.
 
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)
          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)
          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

stateSpace

private StateSpace stateSpace

suspicious

private java.util.HashSet<CGNode> suspicious
A set of suspicious nodes. Only used when there isn't a perfect strategy.


alive

private boolean alive
Constructor Detail

AIDefender

public AIDefender(GameModel gameModel,
                  MessagePasser messagePasser,
                  StateSpace stateSpace,
                  boolean winning)
Creates a defender and, if there isn't a winning strategy, computes a set of suspicious configurations from a configuration graph.

Parameters:
gameModel - A game model from which to get the status and the LTSs
messagePasser - Used for sending move messages to the human player
stateSpace - Used for building a configuration graph and for looking up nodes in a specific block
winning - Indicates if there is a perfect strategy for the defender
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)
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)
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, attempt to avoid reaching a suspicious configuration. Suspicious configurations can be found as those PGNodes that have an edge 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