Internet Chess ToolKit
v0.2.0

ictk.boardgame
Class ContinuationArrayList

java.lang.Object
  extended byictk.boardgame.ContinuationArrayList
All Implemented Interfaces:
ContinuationList

public class ContinuationArrayList
extends java.lang.Object
implements ContinuationList

ContinuationArrayList uses arrays internally to represent the banching structure. Arrays are compacted when null items are created.


Constructor Summary
ContinuationArrayList()
           
ContinuationArrayList(Move m)
           
 
Method Summary
 void add(Move m)
          This adds the move to the continuation list.
 void add(Move m, boolean isMain)
          adds a move to the continuation list.
 int demote(Move move, int num)
          demotes the variation moving it down the variation list.
 void dispose()
          reclaims all resources and recursively deletes all branch moves.
 java.lang.String dump()
          for debugging
 boolean exists(int variation)
          this does not throw ArrayOutOfBoundsException if your ask an index out of range, you just get false returned.
 boolean exists(Move move)
          determines if the move is in the current list of continuations
 Move[] find(Move m)
          searches the continuation list for moves that are equal to the move submitted.
 int[] findIndex(Move m)
          searches the continuation list for moves that are equal to the move submitted.
 Move get(int i)
           
 Move getDepartureMove()
          gets the departure move, that is the move that comes before all of these variations.
 int getIndex(Move m)
          gets the index of this Move object in the variation branches.
 Move getMainLine()
          get the next move in the game history.
 boolean hasMainLine()
          calls exists(0).
 boolean hasVariations()
           
 boolean isTerminal()
          no main line and no variations exist.
 int promote(Move move, int num)
          promotes the move up the list of continuations.
 void remove(int i)
          removes a variation from the continuation list.
 void remove(Move m)
          removes the move from the continuation list.
 void removeAll()
          makes this move a terminal node.
 void removeAllVariations()
          All variations are destroyed as Move.dispose() is called recusively down the line for each variation.
 boolean setMainLineTerminal()
          set the mainline to null.
 int size()
          gets the number of continuation (variations + the main-line) that exist after this move.
 int sizeOfVariations()
          much more useful than size(), this function returns the number of variations (continuations minus the main-line).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContinuationArrayList

public ContinuationArrayList(Move m)

ContinuationArrayList

public ContinuationArrayList()
Method Detail

getDepartureMove

public Move getDepartureMove()
Description copied from interface: ContinuationList
gets the departure move, that is the move that comes before all of these variations.

Specified by:
getDepartureMove in interface ContinuationList

isTerminal

public boolean isTerminal()
Description copied from interface: ContinuationList
no main line and no variations exist. The move that owns this ContinuationList a terminal node. In this case sizeOfVariation() == 0 and !hasMainLine(). This is also the same as isEmpty();

Specified by:
isTerminal in interface ContinuationList

setMainLineTerminal

public boolean setMainLineTerminal()
Description copied from interface: ContinuationList
set the mainline to null. If there existed a main line then it is bumped down to a variation. All other variations are similarly bumped.

Specified by:
setMainLineTerminal in interface ContinuationList
Returns:
true if there previously existed a mainline

exists

public boolean exists(int variation)
Description copied from interface: ContinuationList
this does not throw ArrayOutOfBoundsException if your ask an index out of range, you just get false returned.

Specified by:
exists in interface ContinuationList
Parameters:
variation - which branch to look at (0) is the main line
Returns:
false there is no variation on that line

exists

public boolean exists(Move move)
Description copied from interface: ContinuationList
determines if the move is in the current list of continuations

Specified by:
exists in interface ContinuationList
Parameters:
move - is this move in the list of continuation

hasMainLine

public boolean hasMainLine()
Description copied from interface: ContinuationList
calls exists(0). This queries the move to see if there is a main line that follows.

Specified by:
hasMainLine in interface ContinuationList

getMainLine

public Move getMainLine()
Description copied from interface: ContinuationList
get the next move in the game history. If the move branches (if there are several variations of the game after this move) then this function returns the main line of descent for this game.

Specified by:
getMainLine in interface ContinuationList
Returns:
null if isTerminal() or the mainline has been set to null

hasVariations

public boolean hasVariations()
Specified by:
hasVariations in interface ContinuationList

get

public Move get(int i)
Specified by:
get in interface ContinuationList

size

public int size()
Description copied from interface: ContinuationList
gets the number of continuation (variations + the main-line) that exist after this move. This isn't as useful as it may seem.

Specified by:
size in interface ContinuationList
Returns:
0 if no variations and main-line is null

sizeOfVariations

public int sizeOfVariations()
Description copied from interface: ContinuationList
much more useful than size(), this function returns the number of variations (continuations minus the main-line).

Specified by:
sizeOfVariations in interface ContinuationList

add

public void add(Move m,
                boolean isMain)
Description copied from interface: ContinuationList
adds a move to the continuation list. This does not check to see if the move is already one of the variations. This function should be only accessed through the History class. If you are to access it outside of History the depatureMove and History.getCurrentMove() must be the same. That is, you can only add a move to the continuation list of the last move played.

Specified by:
add in interface ContinuationList
Parameters:
isMain - If true then the move added will be the first continuation. All other moves will be bumped down (if the mainline wasn't null to begin with). LIFO if isMake is not true then the move will be the last branch, in otherwords, appended to the list. FIFO

add

public void add(Move m)
Description copied from interface: ContinuationList
This adds the move to the continuation list. If no moves exist (no main-line and no variations) the move added will become the main-line. If the main-line has been set to null the move added will still become the main line (if this is not what you want you must use add(Move,false)). If the main-line exists the move is appended to the end of the variation list. FIFO
This function should be only accessed through the History class. If you are to access it outside of History the depatureMove and History.getCurrentMove()

Specified by:
add in interface ContinuationList

getIndex

public int getIndex(Move m)
Description copied from interface: ContinuationList
gets the index of this Move object in the variation branches. To search for equavilant moves in the variation list you should use find(Move) or findIndex(Move) since there could be more than one possible match.

Specified by:
getIndex in interface ContinuationList
Returns:
n if move is found

find

public Move[] find(Move m)
Description copied from interface: ContinuationList
searches the continuation list for moves that are equal to the move submitted. It is enough for their coordinates to be equal. Each move that matches will be returned in the Move array.

Specified by:
find in interface ContinuationList
Returns:
null if no moves match the inputed move.

findIndex

public int[] findIndex(Move m)
Description copied from interface: ContinuationList
searches the continuation list for moves that are equal to the move submitted. It is enough for their coordinates to be equal. Each move that matches will have its index returned in the int array.

Specified by:
findIndex in interface ContinuationList
Returns:
null if no moves match the inputed move.

remove

public void remove(int i)
Description copied from interface: ContinuationList
removes a variation from the continuation list. All data from this variation will be destroyed as Move.dispose() is called recursively down the line. This list will then be compressed even if it was the main-line that was removed. To make the main-line null you need to call set(0, null);
If the move to be removed is currently executed the history list will be rewound to this move's departureMove.

Specified by:
remove in interface ContinuationList

remove

public void remove(Move m)
Description copied from interface: ContinuationList
removes the move from the continuation list. All data for this continuation will be destroyed as Move.dispose() is called recursively down the line. The list will then be compressed even if it was the main-line that was removed.
If the move to be removed is currently executed the history list will be rewound to this move's departureMove.

Specified by:
remove in interface ContinuationList

removeAll

public void removeAll()
Description copied from interface: ContinuationList
makes this move a terminal node. All variations are destroyed as Move.dispose() is called recusively down the line for each variation.
If the move to be removed is currently executed the history list will be rewound to this move's departureMove.

Specified by:
removeAll in interface ContinuationList

removeAllVariations

public void removeAllVariations()
Description copied from interface: ContinuationList
All variations are destroyed as Move.dispose() is called recusively down the line for each variation. The main-line is not affected.
If the move to be removed is currently executed the history list will be rewound to this move's departureMove.

Specified by:
removeAllVariations in interface ContinuationList

dispose

public void dispose()
reclaims all resources and recursively deletes all branch moves.

Specified by:
dispose in interface ContinuationList

promote

public int promote(Move move,
                   int num)
Description copied from interface: ContinuationList
promotes the move up the list of continuations. Note: if a variation is promoted to the main-line and the main-line is null the "null" will not be bumped down the list.

Specified by:
promote in interface ContinuationList
Parameters:
num - how many places to displace the variations. If 0 the variation will be promoted to the main line.
Returns:
the index of this variation after the promotion

demote

public int demote(Move move,
                  int num)
Description copied from interface: ContinuationList
demotes the variation moving it down the variation list. Note: if the mainline is the only variation and is demoted then the resulting mainline will be null and the old mainline will be the first variation.

Specified by:
demote in interface ContinuationList
Parameters:
num - how many places to displace the variations. If 0 the variation will be demoted to last variation
Returns:
the index of this variation after the promotion

dump

public java.lang.String dump()
for debugging

Specified by:
dump in interface ContinuationList

Submit a bug or feature
Visit the Website
Internet Chess ToolKit is licensed under the GPL v2 .