org.moyoman.module.shape.simpleshape
Class SimpleShape

java.lang.Object
  |
  +--org.moyoman.module.Module
        |
        +--org.moyoman.module.shape.simpleshape.SimpleShape
All Implemented Interfaces:
Cloneable, Component, ModuleInterface, Serializable, Shape

public class SimpleShape
extends Module
implements Shape

This module implements the Shape interface. It is responsible for evaluating moves in the opening.

See Also:
Serialized Form

Field Summary
private  RatedMove[] bosm
           
private  RatedMove[] bsm
           
private static DebugType[] dt
          The debug types that this module supports.
private  RatedMove[] gosm
           
private  RatedMove[] gsm
           
private  boolean isGenerated
          This flag is used to determine when to clear variables set by generateMove().
private  ModuleType[] mt
          The modules that this module requires.
private  RatedMove[] rm
          The moves that were rated by this module.
 
Fields inherited from class org.moyoman.module.Module
 
Fields inherited from interface org.moyoman.module.shape.Shape
CONFIDENCE
 
Constructor Summary
SimpleShape(GameId id, ModuleName name)
          Create the SimpleShape object.
 
Method Summary
private  void addStoneIfInRange(ArrayList al, Color color, int x, int y)
           
private  boolean checkSpace(Board board, Point pt1, Point pt2, boolean flag)
           
 Object clone()
          Clone the module.
private  RatedMove createRatedMove(Stone st, Board board, float rating)
           
private  boolean evaluateSquare(Point pt1, Point potential, Color color, Board board)
           
 void generateMove(Module[] modules)
          Generate the move for this module.
 RatedMove[] getBadShapeMoves()
           
 Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
 DebugType[] getDebugTypes()
          Return the types of debug information that this module supports.
 RatedMove[] getGoodShapeMoves()
           
 RatedMove[] getMoves()
          Return the moves generated by the module.
private  Stone[] getOffsetStones(Stone st, int offset1, int offset2)
          Get all stones offset by the given amount from the given stone.
 RatedMove[] getOpponentsBadShapeMoves()
           
 RatedMove[] getOpponentsGoodShapeMoves()
           
 ModuleType[] getRequiredModuleList()
          Return the modules that this module requires to perform its task.
private  boolean isAttachmentMatch(Stone st, Board board)
           
private  boolean isDiagonalMoveMatch(Stone st, Board board)
           
private  boolean isEmptyTriangleMatch(Stone st, Board board)
           
private  boolean isFieldMatch(Stone st, Board board)
           
private  boolean isKnightsMoveMatch(Stone st, Board board)
           
private  boolean isLargeKnightsMoveMatch(Stone st, Board board)
           
private  boolean isOneSpaceJumpMatch(Stone st, Board board)
           
private  boolean isTwoSpaceJumpMatch(Stone st, Board board)
           
 void makeMove(Move move, Module[] modules)
          Update the internal data structures of this module with the new move.
private  void setShapeMoves(Color color, boolean isCurrentPlayer, Board board)
          Set the good and bad shape moves for the specified player.
 
Methods inherited from class org.moyoman.module.Module
checkTime, create, createHelper, debug, error, error, fatal, fatal, getAllHelpers, getHelper, getId, getKomi, getModule, getModuleName, getScheduler, information, setTime, warning, warning
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.moyoman.module.ModuleInterface
getScheduler
 

Field Detail

dt

private static DebugType[] dt
The debug types that this module supports.


mt

private ModuleType[] mt
The modules that this module requires.


rm

private RatedMove[] rm
The moves that were rated by this module.


gsm

private RatedMove[] gsm

bsm

private RatedMove[] bsm

gosm

private RatedMove[] gosm

bosm

private RatedMove[] bosm

isGenerated

private boolean isGenerated
This flag is used to determine when to clear variables set by generateMove().

Constructor Detail

SimpleShape

public SimpleShape(GameId id,
                   ModuleName name)
            throws InternalErrorException
Create the SimpleShape object.

Parameters:
id - The id of the game.
name - The name of this module.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Method Detail

generateMove

public void generateMove(Module[] modules)
Generate the move for this module. The side effect of calling this method is that an array of RatedMove objects is stored which is returned by the getMoves() method.

Specified by:
generateMove in class Module
Parameters:
modules - An array of modules which this module needs in order to perform its work. Those modules reflect the current state of the board but are copies of the actual modules, so this method is free to manipulate them.

setShapeMoves

private void setShapeMoves(Color color,
                           boolean isCurrentPlayer,
                           Board board)
Set the good and bad shape moves for the specified player. This method is stateless because this module only does a simple analysis of shape. More sophisticated implementations of the Shape module type will probably want to reuse analysis from move to move.

Parameters:
color - The color of the player being analyzed.
isCurrentPlayer - If true, then the player to move, otherwise the opponent.
board - the Board module.

getOffsetStones

private Stone[] getOffsetStones(Stone st,
                                int offset1,
                                int offset2)
Get all stones offset by the given amount from the given stone. For example, if the offsets are 2 and 1, then get all stones which are a knights move away from the original stone. No check is done for what is actually on that point of the board, this method just handles the logic for checking for the edge of the board. Also, offset1 and offset2 could be either horizontal or vertical.

Parameters:
st - The stone in question.
offset1 - The distance from the stone in one direction.
offset2 - The distance from the stone in the other direction.
Returns:
An array of Stone object of the specifed offset of the same color as the original stone.

addStoneIfInRange

private void addStoneIfInRange(ArrayList al,
                               Color color,
                               int x,
                               int y)

checkSpace

private boolean checkSpace(Board board,
                           Point pt1,
                           Point pt2,
                           boolean flag)

isOneSpaceJumpMatch

private boolean isOneSpaceJumpMatch(Stone st,
                                    Board board)

isTwoSpaceJumpMatch

private boolean isTwoSpaceJumpMatch(Stone st,
                                    Board board)

isDiagonalMoveMatch

private boolean isDiagonalMoveMatch(Stone st,
                                    Board board)

isKnightsMoveMatch

private boolean isKnightsMoveMatch(Stone st,
                                   Board board)

isLargeKnightsMoveMatch

private boolean isLargeKnightsMoveMatch(Stone st,
                                        Board board)

evaluateSquare

private boolean evaluateSquare(Point pt1,
                               Point potential,
                               Color color,
                               Board board)

isEmptyTriangleMatch

private boolean isEmptyTriangleMatch(Stone st,
                                     Board board)

isFieldMatch

private boolean isFieldMatch(Stone st,
                             Board board)

isAttachmentMatch

private boolean isAttachmentMatch(Stone st,
                                  Board board)

createRatedMove

private RatedMove createRatedMove(Stone st,
                                  Board board,
                                  float rating)

getGoodShapeMoves

public RatedMove[] getGoodShapeMoves()
Specified by:
getGoodShapeMoves in interface Shape

getBadShapeMoves

public RatedMove[] getBadShapeMoves()
Specified by:
getBadShapeMoves in interface Shape

getOpponentsGoodShapeMoves

public RatedMove[] getOpponentsGoodShapeMoves()
Specified by:
getOpponentsGoodShapeMoves in interface Shape

getOpponentsBadShapeMoves

public RatedMove[] getOpponentsBadShapeMoves()
Specified by:
getOpponentsBadShapeMoves in interface Shape

getDebugInformation

public Debug[] getDebugInformation(DebugType[] types)
Return the debug information for this module.

Specified by:
getDebugInformation in class Module
Parameters:
types - Only return a subset of the debug types in this array.
Returns:
The debug information that this module supports.

getDebugTypes

public DebugType[] getDebugTypes()
Return the types of debug information that this module supports.

Specified by:
getDebugTypes in class Module
Returns:
The types of debug information that this module supports.

getMoves

public RatedMove[] getMoves()
Return the moves generated by the module. Note that both good and bad moves can be returned.

Specified by:
getMoves in interface ModuleInterface
Specified by:
getMoves in class Module
Returns:
An array of RatedMove objects.

getRequiredModuleList

public ModuleType[] getRequiredModuleList()
Return the modules that this module requires to perform its task.

Specified by:
getRequiredModuleList in class Module
Returns:
An array of module types that the module requires.

makeMove

public void makeMove(Move move,
                     Module[] modules)
Update the internal data structures of this module with the new move. This module is stateless, so minimal work is done here.

Specified by:
makeMove in class Module
Parameters:
move - The move that was just made.
modules - The modules that this method needs to perform its job.

clone

public Object clone()
Clone the module.

Specified by:
clone in interface ModuleInterface
Overrides:
clone in class Module
Returns:
The A SimpleEndgame object which is a clone of this one.