dk.brics.bisimulationGame.controller
Class AIAttacker

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

public class AIAttacker
extends java.lang.Object
implements AI

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

If so, the attacker proceeds as follows:

  1. Build a configuration graph based on the state space.
  2. At each turn:
    a. Lookup a strategy based on the current nodes in both LTSs.
    b. Choose side, action and transition from this strategy.

If not, use the following strategy:

  1. If there is a strategy at the current configuration, use it. This allows the attacker to win if the defender makes a not-so-smart move.
  2. Else, create a dynamic strategy:
  3. Choose a side based on the number of choices on the left and the right side:
    a. If there is no action enabled on either side, choose the other.
    b. Else if there is only one choice on one side and more on the other, choose the side with more choices.
    c. Else just choose a random side.
  4. Choose an action:
    Random choice, for now.

Author:
Martin Mosegaard martinm@daimi.au.dk

Field Summary
private  boolean alive
           
private  Strategy currentStrategy
           
private  GameModel gameModel
           
private  MessagePasser messagePasser
           
private  java.util.HashMap<CGNode,Strategy> nodeMap
           
 
Fields inherited from interface dk.brics.bisimulationGame.controller.AI
AI_SLEEP
 
Constructor Summary
AIAttacker(GameModel gameModel, MessagePasser messagePasser, StateSpace stateSpace)
          Constructs an attacker and builds a strategy for it.
 
Method Summary
private  void attackerChoseSide()
          Look up the side in the current strategy and send a message to the message passer.
private  void attackerStep()
          Look up the current strategy and send a message to the message passer.
private  int chooseRandomSide()
          Choose a random side.
private  int chooseSide()
          Choose a side based on the number of choices on either side.
private  Strategy getDynamicStrategy()
          Create a dynamic strategy.
private  Strategy getStrategy()
          Returns the strategy at the current node pair.
 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

nodeMap

private java.util.HashMap<CGNode,Strategy> nodeMap

currentStrategy

private Strategy currentStrategy

alive

private boolean alive
Constructor Detail

AIAttacker

public AIAttacker(GameModel gameModel,
                  MessagePasser messagePasser,
                  StateSpace stateSpace)
Constructs an attacker and builds a strategy for it.

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 a strategy
See Also:
ConfigurationGraph
Method Detail

run

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

attackerChoseSide

private void attackerChoseSide()
Look up the side in the current strategy and send a message to the message passer.


attackerStep

private void attackerStep()
Look up the current strategy and send a message to the message passer.


chooseSide

private int chooseSide()
Choose a side based on the number of choices on either side. Strategy for choosing side: If there is no action enabled on either side, choose the other. Else if there is only one choice on one side and more on the other, choose the side with more choices. Else just choose a random side. We know that at least one side has at least one choice, otherwise the game would be over.

Returns:
A side

chooseRandomSide

private int chooseRandomSide()
Choose a random side.

Returns:
A side

getStrategy

private Strategy getStrategy()
Returns the strategy at the current node pair.

Returns:
The strategy for the matching pair graph node

getDynamicStrategy

private Strategy getDynamicStrategy()
Create a dynamic strategy. This is done when there isn't a perfect attacker strategy.


kill

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

Specified by:
kill in interface AI