<hexchess-board>

Chess is better with hexagons

API

<hexchess-board>

A hexagonal chess board used for playing Glinsky-style hex chess. Player variables

Attributes

NameDescriptionTypeDefault
turnWhose turn it is initiallystring
boardA hex-FEN notation describing the state of the board. If the string is empty, no pieces will be rendered.Board
movesA list of moves made on the board. This is useful for analyzing games already played or certain pre-determined openings.Move[]
black-player-nameBlack's player namestring'Black'
white-player-nameWhite's player namestring'White'
orientationThe orientation of the board.Orientation'white'
player-roleThe role of the player. If `white`, you can only make moves when it is white's turn. If `black`, you can only make moves when it is black's turn. If `spectator`, then you cannot make moves at all via the UI. If `analyzer`, then you can make moves for both sides, and it simuluates a local game.Role'analyzer'
hide-coordinatesShow the board coordinates on the bottom and left sides of the board.booleanfalse
frozenDo not allow any other moves beyond the predetermined ones set in the `moves` property.booleanfalse
show-hintsClicking on an opponent's piece shows all the squares it can move tobooleantrue
hide-playernamesHide player names - usually only used for custom websites to render player names separately.booleanfalse
hide-capturedpiecesHide captured pieces - usually only used for custom websites to render captured pieces separately.booleanfalse

Methods

NameParametersDescriptionReturn
exportExports the current game to a CSV list of moves that can be fed back into this same component.string
fenConverts to a hex-FEN notation describing the state of the board. Includes the positions of all the pieces along with whose turn it is.string
flipFlip the orientation of the board.void
resizeResize the board based on the latest dimensions given to the shadow root.void
rewindRewinds one move to a previous position. If there are no previous moves, this does nothing.void
rewindAllRewinds all moves until the starting position of the board is reached.void
fastForwardFast forwards one move to the next position. If there are no next moves, this does nothing.void
fastForwardAllFast forwards all moves until the current state of the board is reached.void
freezePrevent any more moves to the game. Usually called when the game is over.void
unfreezeUnfreeze the board and re-enable moves to be made.void
move
NameDescriptionType
fromstring
Make a move on the board.
move
NameDescriptionType
fromSquare
toSquare
boolean
move
NameDescriptionType
argstring | Square
toSquare
boolean
promote
NameDescriptionType
piecePiece
Promote a pawn.
resetResets and unfreezes the board to the default start state.void
stopCustomEventsPauses all custom events from being emitted. This is useful when replaying many pre-programmed moves.void
restartCustomEventsvoid

Events

NameDescription
promotingFired when a pawn is ready to promote.
promotedFired when a pawn has been promoted to a piece.
gameoverFired when the game is over.
moveFired when a move is made on the board.
furthestbackFired when the game is rewound to its starting position.
furthestforwardFired when a game is fast forwarded back to its current position.

CSS Custom Properties

NameDescription
--hexchess-playername-sizeThe font size of the player names.
--hexchess-playername-colorThe color of the player names. Board variables
--hexchess-board-bgThe background color of the whitespace of the board (not tiles).
--hexchess-white-bgThe background color of the white tiles.
--hexchess-selected-white-bgThe background color of a white tile that's selected to be moved.
--hexchess-black-bgThe background color of the black tiles.
--hexchess-selected-black-bgThe background color of a black tile that's selected to be moved.
--hexchess-grey-bgThe background color of the grey tiles.
--hexchess-selected-grey-bgThe background color of a grey tile that's selected to be moved.
--hexchess-label-bgThe background color of the column and row labels.
--hexchess-label-sizeThe font size of the column and row labels.
--hexchess-possible-move-bgThe fill color of the small dot shown on a hexagon indicating this is a legal move.
--hexchess-possible-move-opponent-bgThe fill color of the small dot shown on a hexagon indicating this is a move an opponent piece can make.
--hexchess-possible-capture-bgThe stroke color of the large circle outlining a piece that can be captured.
--hexchess-possible-move-stroke-whiteThe outline color of a hexagon when the user drags over a white square, trying to move there.
--hexchess-possible-move-stroke-greyThe outline color of a hexagon when the user drags over a grey square, trying to move there.
--hexchess-possible-move-stroke-blackThe outline color of a hexagon when the user drags over a black square, trying to move there.
--hexchess-possible-move-stroke-opponentThe outline of a square when dragging an opponent piece to a possible move. Custom events