bluegammon.logic
Class Rules

java.lang.Object
  extended bybluegammon.logic.Rules

public class Rules
extends java.lang.Object

Contains state of rules and logic of deciding valid moves.

Author:
Peter Andersson

Field Summary
static int EVEN_OUT
          Flag denoting that a piece must go out on an even dice
static int MAX_FIVE
          Flag denoting that there may be maximum five pieces on a row
 
Method Summary
static int getRuleFlags()
          Returns current rule settings as an integer.
static boolean isAnyRuleSet()
          Returns true if any special rule has been enabled.
static boolean isSet(int rule)
          Queries if a rule is enabled or not.
static boolean isValidFromGuard(BoardState state, int to, int[] player, int[] opponent)
          Returns if a move is valid from guardposition to specified position.
static boolean isValidMove(BoardState state, int from, int to, boolean white, int[] player, int[] opponent)
          Returns if a move is valid from specified position to specified position.
static int loadRules(java.io.DataInputStream dis)
          Loads rules.
static int saveRules(java.io.DataOutputStream dos)
          Saves rules.
static void set(int rule, boolean set)
          Enables/disables a rule.
static void setRuleFlags(int flags)
          Sets current rules as an integer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_FIVE

public static final int MAX_FIVE
Flag denoting that there may be maximum five pieces on a row

See Also:
Constant Field Values

EVEN_OUT

public static final int EVEN_OUT
Flag denoting that a piece must go out on an even dice

See Also:
Constant Field Values
Method Detail

isAnyRuleSet

public static boolean isAnyRuleSet()
Returns true if any special rule has been enabled. Returns false if no special rules are enabled.

Returns:
true if any rule is enabled, false otherwise.

set

public static void set(int rule,
                       boolean set)
Enables/disables a rule.

Parameters:
rule - The rule.
set - true to enable, false to disable.

isSet

public static boolean isSet(int rule)
Queries if a rule is enabled or not.

Parameters:
rule - The rule.
Returns:
true if enabled, false otherwise.

isValidFromGuard

public static boolean isValidFromGuard(BoardState state,
                                       int to,
                                       int[] player,
                                       int[] opponent)
Returns if a move is valid from guardposition to specified position.

Parameters:
state - The board state.
to - The destination index to move piece to.
player - Player indices.
opponent - Opponend indices.
Returns:
True if valid, false otherwise.

isValidMove

public static boolean isValidMove(BoardState state,
                                  int from,
                                  int to,
                                  boolean white,
                                  int[] player,
                                  int[] opponent)
Returns if a move is valid from specified position to specified position.

Parameters:
state - The board state.
from - The source index to move piece from.
to - The destination index to move piece to.
white - The color of the piece.
player - Player indices.
opponent - Opponend indices.
Returns:
True if valid, false otherwise.

getRuleFlags

public static int getRuleFlags()
Returns current rule settings as an integer.

Returns:
Current rule settings.

setRuleFlags

public static void setRuleFlags(int flags)
Sets current rules as an integer.

Parameters:
flags - Current rule settings.

loadRules

public static int loadRules(java.io.DataInputStream dis)
                     throws java.io.IOException
Loads rules.

Parameters:
dis - The stream to read from.
Returns:
number of bytes read.
Throws:
java.io.IOException - if loading fails.

saveRules

public static int saveRules(java.io.DataOutputStream dos)
                     throws java.io.IOException
Saves rules.

Parameters:
dos - The stream to write to.
Returns:
Number of bytes written.
Throws:
java.io.IOException - if save failed.