Class GameRules

java.lang.Object
  |
  +--GameRules

public class GameRules
extends java.lang.Object

An object of this class describes the rules for a particular variation of movable tic-tac-toe, specifically, the moves that are possible from a given state, and whether a given state is a win for one of the players.


Constructor Summary
GameRules(int[][] ml)
          Constructs a GameRules object in which legal moves are defined by the given array of 4-tuples.
GameRules(java.lang.String game_id)
          Constructs a GameRules object for a game whose legal moves are stored in the file game_id.rules.
 
Method Summary
 boolean isLegal(GameState gs, Move move)
          Tests whether the given game state and the move from it are legal according to the game rules.
 int isWin(GameState gs)
          Returns +1 if player +1 has won in the given game state, -1 if player -1 has won, and 0 if no one has won.
 Move[] legalMoves(GameState gs)
          Returns an array of all possible legal moves from the given game state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameRules

public GameRules(int[][] ml)
Constructs a GameRules object in which legal moves are defined by the given array of 4-tuples. Each 4-tuple is of the form (fx, fy, tx, ty) with the meaning that it is legal to move a piece from position fx, fy to position tx, ty.


GameRules

public GameRules(java.lang.String game_id)
          throws java.lang.IllegalArgumentException,
                 java.io.IOException
Constructs a GameRules object for a game whose legal moves are stored in the file game_id.rules.

Method Detail

legalMoves

public Move[] legalMoves(GameState gs)
Returns an array of all possible legal moves from the given game state.

Parameters:
gs - given game state

isWin

public int isWin(GameState gs)
Returns +1 if player +1 has won in the given game state, -1 if player -1 has won, and 0 if no one has won.

Parameters:
gs - game state to be checked

isLegal

public boolean isLegal(GameState gs,
                       Move move)
Tests whether the given game state and the move from it are legal according to the game rules.

Parameters:
gs - game state to be checked
move - move to be checked