Internet Chess ToolKit
v0.2.0

ictk.boardgame
Interface ContinuationList

All Known Implementing Classes:
ContinuationArrayList

public interface ContinuationList

This class facilitiates the branching aspect of the History tree. There are three main features the "departure move", which is the the move from which all the continuations originate. There is the "main-line", which is the primary continuation from the "move". And then there are "variations". These are auxilery or alternate continuations.

This class allows the variations to be promoted in their order and all the way up to the main-line, which, though not a "variation" in the sense used for this class, is the top most variation in regards to the ordered variations. In other words: if you promote a variation high enough it will become the main-line.

Note: the main-line is the only continuation that is allowed to be null. this is often used when the game ends with the departure move and the variations show possible continuations.


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).
 

Method Detail

getDepartureMove

public Move getDepartureMove()
gets the departure move, that is the move that comes before all of these variations.


isTerminal

public boolean isTerminal()
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();


setMainLineTerminal

public boolean setMainLineTerminal()
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.

Returns:
true if there previously existed a mainline

exists

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

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)
determines if the move is in the current list of continuations

Parameters:
move - is this move in the list of continuation

hasMainLine

public boolean hasMainLine()
calls exists(0). This queries the move to see if there is a main line that follows.


getMainLine

public Move getMainLine()
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.

Returns:
null if isTerminal() or the mainline has been set to null

hasVariations

public boolean hasVariations()

get

public Move get(int i)

size

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

Returns:
0 if no variations and main-line is null

sizeOfVariations

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


add

public void add(Move m,
                boolean isMain)
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.

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)
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()


getIndex

public int getIndex(Move m)
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.

Returns:
n if move is found

find

public Move[] find(Move m)
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.

Returns:
null if no moves match the inputed move.

findIndex

public int[] findIndex(Move m)
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.

Returns:
null if no moves match the inputed move.

remove

public void remove(int i)
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.

Throws:
may - throw ArrayIndexOutOfBoundException

remove

public void remove(Move m)
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.

Throws:
may - throw ArrayIndexOutOfBoundException

removeAll

public void removeAll()
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.


removeAllVariations

public void removeAllVariations()
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.


dispose

public void dispose()
reclaims all resources and recursively deletes all branch moves. isTerminal() will return true as a result. This will also unlink all references to the departure move.


promote

public int promote(Move move,
                   int num)
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.

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
Throws:
IndexArrayOutOfBoundException - if you promote past the main line
java.lang.NullPointerException - if the move is not in the variation list

demote

public int demote(Move move,
                  int num)
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.

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
Throws:
IndexArrayOutOfBoundException - if demoted past the last variation
java.lang.NullPointerException - if the move is not in the variation list

dump

public java.lang.String dump()
for debugging


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