de.tabacha.cgo
Class DefaultBoard

java.lang.Object
  extended byde.tabacha.cgo.DefaultBoard
All Implemented Interfaces:
Board, java.lang.Cloneable, Constants, java.io.Serializable

public final class DefaultBoard
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, Constants, Board

The 19x19 board from the game Go.
$Id: DefaultBoard.java,v 1.9 2004/12/23 21:42:43 mk Exp $

Version:
$Revision: 1.9 $
See Also:
Serialized Form
Threadsafe?
false

Field Summary
 
Fields inherited from interface de.tabacha.cgo.Constants
BALL, COL_COUNT, DCOL, DOWN, DROW, E, EMPTY, FIRST_DIRECTION, KICK_OFF_FIELD, LAST_DIRECTION, N, NE, NW, OPPOSITE, PIECE, ROW_COUNT, S, SE, SW, UP, UPSIDEDOWN, W
 
Constructor Summary
DefaultBoard()
          Constructs and resets the board.
DefaultBoard(byte[][] fields, Field ballField, boolean whoseTurn)
          Constructor that receives direct values.
 
Method Summary
 void addPiece(Field f)
          Puts a piece (aka player) on the board.
 void addPiece(int col, int row)
          Puts a piece (aka player) on the board.
 void clear()
          Removes all pieces and the ball from the field.
 java.lang.Object clone()
          Returns a deep copy of this object.
 boolean equals(java.lang.Object o)
          Returns true if the other object is also a DefaultBoard and represents the same position.
 Field getBall()
          Returns the actual field of the ball.
 int hashCode()
          As nearly all information about the position is in the byte arrays, returns the hash code of the two-dimensional field array.
protected  void jump(Jump move)
          Moves the ball around the field.
protected  void jumpOnce(byte dir, Move move)
          Makes the ball jump once.
 void move(Move move)
          Makes a move.
protected  void nextTurn()
          Switchs the player who has to move.
 byte on(Field field)
          Returns the content of the specified field on the board.
 byte on(int col, int row)
          Returns the content of the field on the specified row and column.
protected  void put(Put move)
          Puts a piece on the board.
 void removePiece(Field f)
          Removes a piece (aka player) from the board.
 void removePiece(int col, int row)
          Removes a piece (aka player) from the board.
 void reset()
          Sets the board to the start position.
 void setBall(Field newBallField)
          Sets the actual field of the ball.
 void setBall(int col, int row)
          Sets the actual field of the ball.
 byte[][] toArray()
          Returns this object as a two-dimensional array containing the contents of the fields.
 java.lang.String toString()
          Returns a string representation of the board, for debugging.
 Board upsideDown()
          Returns a copy of this board mirrored along the x-axis.
 boolean whoseTurn()
          Returns the player who has to move.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultBoard

public DefaultBoard()
Constructs and resets the board.


DefaultBoard

public DefaultBoard(byte[][] fields,
                    Field ballField,
                    boolean whoseTurn)
Constructor that receives direct values. Will not test if the ball is set in the byte array at the place of the ball field.

Method Detail

clone

public java.lang.Object clone()
Description copied from interface: Board
Returns a deep copy of this object.

Specified by:
clone in interface Board

toArray

public byte[][] toArray()
Description copied from interface: Board
Returns this object as a two-dimensional array containing the contents of the fields.

Specified by:
toArray in interface Board

clear

public void clear()
Removes all pieces and the ball from the field. The ball field will be outside the board.


reset

public void reset()
Sets the board to the start position.

Specified by:
reset in interface Board

upsideDown

public Board upsideDown()
Description copied from interface: Board
Returns a copy of this board mirrored along the x-axis.

Specified by:
upsideDown in interface Board

nextTurn

protected void nextTurn()
Switchs the player who has to move.


whoseTurn

public boolean whoseTurn()
Description copied from interface: Board
Returns the player who has to move.

Specified by:
whoseTurn in interface Board
Returns:
UP or DOWN, declared in Constants.

on

public byte on(int col,
               int row)
Description copied from interface: Board
Returns the content of the field on the specified row and column.

Specified by:
on in interface Board
Returns:
EMPTY, PIECE or BALL; declared in Constants.

on

public byte on(Field field)
Description copied from interface: Board
Returns the content of the specified field on the board.

Specified by:
on in interface Board
Returns:
EMPTY, PIECE or BALL; declared in Constants.

getBall

public Field getBall()
Description copied from interface: Board
Returns the actual field of the ball.

Specified by:
getBall in interface Board

setBall

public void setBall(Field newBallField)
Description copied from interface: Board
Sets the actual field of the ball.

Specified by:
setBall in interface Board

setBall

public void setBall(int col,
                    int row)
Description copied from interface: Board
Sets the actual field of the ball.

Specified by:
setBall in interface Board

addPiece

public void addPiece(Field f)
Description copied from interface: Board
Puts a piece (aka player) on the board. No warning if the field wasn't empty.

Specified by:
addPiece in interface Board

addPiece

public void addPiece(int col,
                     int row)
Description copied from interface: Board
Puts a piece (aka player) on the board. No warning if the field wasn't empty.

Specified by:
addPiece in interface Board

removePiece

public void removePiece(Field f)
Description copied from interface: Board
Removes a piece (aka player) from the board. No warning if there wasn't a piece on this field.

Specified by:
removePiece in interface Board

removePiece

public void removePiece(int col,
                        int row)
Description copied from interface: Board
Removes a piece (aka player) from the board. No warning if there wasn't a piece on this field.

Specified by:
removePiece in interface Board

move

public final void move(Move move)
                throws InvalidMoveException
Description copied from interface: Board
Makes a move. If successfully performed, it's the next player's turn.

Specified by:
move in interface Board
Throws:
InvalidMoveException - If the move was not correct.

put

protected void put(Put move)
            throws InvalidMoveException
Puts a piece on the board. The player is not changed, so this must not be a public method.

Throws:
InvalidMoveException - If field is not empty or outside the board.

jump

protected void jump(Jump move)
             throws InvalidMoveException
Moves the ball around the field. If the ball is in the goal, further jumps will be ignored. The player is not changed, so this must not be a public method.

Throws:
InvalidMoveException - If no jumps are contained in the move or one of the jumps is not possible

jumpOnce

protected void jumpOnce(byte dir,
                        Move move)
                 throws InvalidMoveException
Makes the ball jump once.

Parameters:
dir - Direction where to jump to. Defined in Constants.
move - The move this jump is a part of.
Throws:
InvalidMoveException - If jump is not possible.

equals

public boolean equals(java.lang.Object o)
Returns true if the other object is also a DefaultBoard and represents the same position.


hashCode

public int hashCode()
As nearly all information about the position is in the byte arrays, returns the hash code of the two-dimensional field array.


toString

public java.lang.String toString()
Returns a string representation of the board, for debugging. Not localized.