Package featurecat.lizzie.rules
Class Board
- java.lang.Object
-
- featurecat.lizzie.rules.Board
-
- All Implemented Interfaces:
LeelazListener
public class Board extends java.lang.Object implements LeelazListener
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
allowCoords
java.lang.String
avoidCoords
static int
boardHeight
static int
boardSize0
static int
boardWidth
boolean
isAllowing
boolean
isAvoding
boolean
isForcing
boolean
isKeepingAvoid
-
Constructor Summary
Constructors Constructor Description Board()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAllowCoords(int x, int y)
void
addNodeProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Add a keys and values to nodevoid
addNodeProperty(java.lang.String key, java.lang.String value)
Add a key and value to nodevoid
addStone(int x, int y, Stone color)
Add a stone to the board representation.static java.util.Optional<int[]>
asCoordinates(java.lang.String namedCoordinate)
Converts a named coordinate eg C16, T5, K10, etc to an x and y coordinatestatic int
asDigit(java.lang.String name)
static java.lang.String
asName(int c)
static java.lang.String
asName(int c, boolean isName)
void
autosave()
boolean
autosaveToMemory()
void
bestMoveNotification(java.util.List<MoveData> bestMoves)
boolean
changeMove(int moveNumber, int[] coords)
boolean
changeMove(int moveNumber, int[] coords, boolean swapColorOnly)
boolean
changeMove(int moveNumber, java.lang.String changeMove)
void
clear()
Clears all history and starts over from empty board.void
clearAnalysis()
void
comment(java.lang.String comment)
The comment.static java.lang.String
convertCoordinatesToName(int x, int y)
Converts a x and y coordinate to a named coordinate eg C16, T5, K10, etcvoid
deleteBranch()
void
deleteMove()
void
flatten()
for handicapstatic int[]
getCoord(int index)
BoardData
getData()
BoardHistoryList
getHistory()
static int
getIndex(int x, int y)
Calculates the array index of a stone stored at (x, y)java.util.Optional<int[]>
getLastMove()
Shows where to mark the last coordinatejava.util.ArrayList<MoveList>
getMoveList()
int[]
getMoveNumberList()
Gets current board move numberjava.util.Optional<int[]>
getNextMove()
Gets the move played in this positiondouble[]
getScore(Stone[] scoreStones)
Stone[]
getStones()
Get current board stateboolean
goToMoveNumber(int moveNumber)
boolean
goToMoveNumberBeyondBranch(int moveNumber)
void
goToMoveNumberByBackChildren(int moveNumber)
Go to move number by back routing from children when in branchboolean
goToMoveNumberHelper(int moveNumber, boolean withinBranch)
boolean
goToMoveNumberWithinBranch(int moveNumber)
boolean
inAnalysisMode()
boolean
inScoreMode()
boolean
isCoordsEmpty(int x, int y)
static boolean
isValid(int[] c)
static boolean
isValid(int x, int y)
Checks if a coordinate is validvoid
moveBranchDown()
void
moveBranchUp()
void
moveNumber(int moveNumber)
Update the move number.int
moveNumberByCoord(int[] coord)
void
moveToAnyPosition(BoardHistoryNode targetNode)
Jump anywhere in the board history tree.boolean
nextBranch()
Moves to next variation (variation to the right) if possible.boolean
nextMove()
Goes to the next coordinate, thread safeboolean
nextMove(int fromBackChildren)
Goes to the next coordinate, thread safeboolean
nextVariation(int idx)
Goes to the next variation, thread safevoid
pass()
overloaded method for pass(), chooses color in an alternating patternvoid
pass(Stone color)
The pass.void
pass(Stone color, boolean newBranch)
void
pass(Stone color, boolean newBranch, boolean dummy)
void
pass(Stone color, boolean newBranch, boolean dummy, boolean changeMove)
The pass.void
place(int x, int y)
overloaded method for place(), chooses color in an alternating patternvoid
place(int x, int y, Stone color)
Places a stone onto the board representation.void
place(int x, int y, Stone color, boolean newBranch)
void
place(int x, int y, Stone color, boolean newBranch, boolean changeMove)
Places a stone onto the board representation.void
place(java.lang.String namedCoordinate)
overloaded method for place.boolean
previousBranch()
Moves to previous variation (variation to the left) if possible, or back to main trunk To move to another variation, the variation must have the same number of moves in it.boolean
previousMove()
Goes to the previous coordinate, thread safestatic int
removeDeadChain(int x, int y, Stone color, Stone[] stones, Zobrist zobrist)
Removes a chain if it has no libertiesvoid
removeStone(int x, int y, Stone color)
Remove a stone from the board representation.void
reopen(int width, int height)
Open board again when the SZ property is setup by sgfvoid
restoreMoveNumber()
Restore move number by saved nodevoid
restoreMoveNumber(BoardHistoryNode node)
Restore move number by nodevoid
resumePreviousGame()
void
saveBackRouting(BoardHistoryNode node)
Save the back routing from childrenvoid
saveMoveNumber()
Save the move number for restore If in the branch, save the back routing from childrenStone[]
scoreStones()
boolean
setAllowCoords(int x, int y)
boolean
setAsMainBranch()
boolean
setAvoidCoords(int x, int y)
void
setKomi(double komi)
void
setScoreMode(boolean on)
void
toggleAnalysis()
boolean
undoToChildOfPreviousWithVariation()
void
updateWinrate()
-
-
-
Field Detail
-
boardSize0
public static int boardSize0
-
boardWidth
public static int boardWidth
-
boardHeight
public static int boardHeight
-
allowCoords
public java.lang.String allowCoords
-
avoidCoords
public java.lang.String avoidCoords
-
isForcing
public boolean isForcing
-
isAllowing
public boolean isAllowing
-
isAvoding
public boolean isAvoding
-
isKeepingAvoid
public boolean isKeepingAvoid
-
-
Method Detail
-
getIndex
public static int getIndex(int x, int y)
Calculates the array index of a stone stored at (x, y)- Parameters:
x
- the x coordinatey
- the y coordinate- Returns:
- the array index
-
getCoord
public static int[] getCoord(int index)
-
asCoordinates
public static java.util.Optional<int[]> asCoordinates(java.lang.String namedCoordinate)
Converts a named coordinate eg C16, T5, K10, etc to an x and y coordinate- Parameters:
namedCoordinate
- a capitalized version of the named coordinate. Must be a valid 19x19 Go coordinate, without I- Returns:
- an optional array of coordinates, empty for pass and resign
-
asDigit
public static int asDigit(java.lang.String name)
-
asName
public static java.lang.String asName(int c)
-
clearAnalysis
public void clearAnalysis()
-
asName
public static java.lang.String asName(int c, boolean isName)
-
convertCoordinatesToName
public static java.lang.String convertCoordinatesToName(int x, int y)
Converts a x and y coordinate to a named coordinate eg C16, T5, K10, etc- Parameters:
x
- x coordinate -- must be validy
- y coordinate -- must be valid- Returns:
- a string representing the coordinate
-
isValid
public static boolean isValid(int x, int y)
Checks if a coordinate is valid- Parameters:
x
- x coordinatey
- y coordinate- Returns:
- whether or not this coordinate is part of the board
-
isValid
public static boolean isValid(int[] c)
-
reopen
public void reopen(int width, int height)
Open board again when the SZ property is setup by sgf- Parameters:
size
-
-
comment
public void comment(java.lang.String comment)
The comment. Thread safe- Parameters:
comment
- the comment of stone
-
moveNumber
public void moveNumber(int moveNumber)
Update the move number. Thread safe- Parameters:
moveNumber
- the move number of stone
-
moveNumberByCoord
public int moveNumberByCoord(int[] coord)
-
addStone
public void addStone(int x, int y, Stone color)
Add a stone to the board representation. Thread safe- Parameters:
x
- x coordinatey
- y coordinatecolor
- the type of stone to place
-
removeStone
public void removeStone(int x, int y, Stone color)
Remove a stone from the board representation. Thread safe- Parameters:
x
- x coordinatey
- y coordinatecolor
- the type of stone to place
-
addNodeProperty
public void addNodeProperty(java.lang.String key, java.lang.String value)
Add a key and value to node- Parameters:
key
-value
-
-
addNodeProperties
public void addNodeProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Add a keys and values to node- Parameters:
properties
-
-
setKomi
public void setKomi(double komi)
-
pass
public void pass(Stone color)
The pass. Thread safe- Parameters:
color
- the type of pass
-
pass
public void pass(Stone color, boolean newBranch)
-
pass
public void pass(Stone color, boolean newBranch, boolean dummy)
-
pass
public void pass(Stone color, boolean newBranch, boolean dummy, boolean changeMove)
The pass. Thread safe- Parameters:
color
- the type of passnewBranch
- add a new branch
-
pass
public void pass()
overloaded method for pass(), chooses color in an alternating pattern
-
place
public void place(int x, int y, Stone color)
Places a stone onto the board representation. Thread safe- Parameters:
x
- x coordinatey
- y coordinatecolor
- the type of stone to place
-
place
public void place(int x, int y, Stone color, boolean newBranch)
-
place
public void place(int x, int y, Stone color, boolean newBranch, boolean changeMove)
Places a stone onto the board representation. Thread safe- Parameters:
x
- x coordinatey
- y coordinatecolor
- the type of stone to placenewBranch
- add a new branch
-
place
public void place(int x, int y)
overloaded method for place(), chooses color in an alternating pattern- Parameters:
x
- x coordinatey
- y coordinate
-
place
public void place(java.lang.String namedCoordinate)
overloaded method for place. To be used by the LeelaZ engine. Color is then assumed to be alternating- Parameters:
namedCoordinate
- the coordinate to place a stone,
-
flatten
public void flatten()
for handicap
-
removeDeadChain
public static int removeDeadChain(int x, int y, Stone color, Stone[] stones, Zobrist zobrist)
Removes a chain if it has no liberties- Parameters:
x
- x coordinate -- needn't be validy
- y coordinate -- needn't be validcolor
- the color of the chain to removestones
- the stones array to modifyzobrist
- the zobrist object to modify- Returns:
- number of removed stones
-
getStones
public Stone[] getStones()
Get current board state- Returns:
- the stones array corresponding to the current board state
-
getLastMove
public java.util.Optional<int[]> getLastMove()
Shows where to mark the last coordinate- Returns:
- the last played stone, if any, Optional.empty otherwise
-
getNextMove
public java.util.Optional<int[]> getNextMove()
Gets the move played in this position- Returns:
- the next move, if any, Optional.empty otherwise
-
getMoveNumberList
public int[] getMoveNumberList()
Gets current board move number- Returns:
- the int array corresponding to the current board move number
-
nextMove
public boolean nextMove()
Goes to the next coordinate, thread safe
-
nextMove
public boolean nextMove(int fromBackChildren)
Goes to the next coordinate, thread safe- Parameters:
fromBackChildren
- by back children branch- Returns:
- true when has next variation
-
saveMoveNumber
public void saveMoveNumber()
Save the move number for restore If in the branch, save the back routing from children
-
saveBackRouting
public void saveBackRouting(BoardHistoryNode node)
Save the back routing from children
-
restoreMoveNumber
public void restoreMoveNumber()
Restore move number by saved node
-
restoreMoveNumber
public void restoreMoveNumber(BoardHistoryNode node)
Restore move number by node
-
goToMoveNumberByBackChildren
public void goToMoveNumberByBackChildren(int moveNumber)
Go to move number by back routing from children when in branch
-
goToMoveNumber
public boolean goToMoveNumber(int moveNumber)
-
goToMoveNumberWithinBranch
public boolean goToMoveNumberWithinBranch(int moveNumber)
-
goToMoveNumberBeyondBranch
public boolean goToMoveNumberBeyondBranch(int moveNumber)
-
goToMoveNumberHelper
public boolean goToMoveNumberHelper(int moveNumber, boolean withinBranch)
-
nextVariation
public boolean nextVariation(int idx)
Goes to the next variation, thread safe
-
nextBranch
public boolean nextBranch()
Moves to next variation (variation to the right) if possible. The variation must have a move with the same move number as the current move in it.- Returns:
- true if there exist a target variation
-
previousBranch
public boolean previousBranch()
Moves to previous variation (variation to the left) if possible, or back to main trunk To move to another variation, the variation must have the same number of moves in it.Note: This method will always move back to main trunk, even if variation has more moves than main trunk (if this case it will move to the last move in the trunk).
- Returns:
- true if there exist a target variation
-
moveToAnyPosition
public void moveToAnyPosition(BoardHistoryNode targetNode)
Jump anywhere in the board history tree.- Parameters:
targetNode
- history node to be located
-
moveBranchUp
public void moveBranchUp()
-
moveBranchDown
public void moveBranchDown()
-
deleteMove
public void deleteMove()
-
deleteBranch
public void deleteBranch()
-
getData
public BoardData getData()
-
getHistory
public BoardHistoryList getHistory()
-
clear
public void clear()
Clears all history and starts over from empty board.
-
previousMove
public boolean previousMove()
Goes to the previous coordinate, thread safe
-
undoToChildOfPreviousWithVariation
public boolean undoToChildOfPreviousWithVariation()
-
setScoreMode
public void setScoreMode(boolean on)
-
scoreStones
public Stone[] scoreStones()
-
getScore
public double[] getScore(Stone[] scoreStones)
-
inAnalysisMode
public boolean inAnalysisMode()
-
inScoreMode
public boolean inScoreMode()
-
toggleAnalysis
public void toggleAnalysis()
-
bestMoveNotification
public void bestMoveNotification(java.util.List<MoveData> bestMoves)
- Specified by:
bestMoveNotification
in interfaceLeelazListener
-
autosave
public void autosave()
-
autosaveToMemory
public boolean autosaveToMemory()
-
resumePreviousGame
public void resumePreviousGame()
-
updateWinrate
public void updateWinrate()
-
changeMove
public boolean changeMove(int moveNumber, java.lang.String changeMove)
-
changeMove
public boolean changeMove(int moveNumber, int[] coords)
-
changeMove
public boolean changeMove(int moveNumber, int[] coords, boolean swapColorOnly)
-
getMoveList
public java.util.ArrayList<MoveList> getMoveList()
-
setAvoidCoords
public boolean setAvoidCoords(int x, int y)
-
setAllowCoords
public boolean setAllowCoords(int x, int y)
-
addAllowCoords
public boolean addAllowCoords(int x, int y)
-
isCoordsEmpty
public boolean isCoordsEmpty(int x, int y)
-
setAsMainBranch
public boolean setAsMainBranch()
-
-