ChessBrowser
Extension to create interactive chess boards
Loading...
Searching...
No Matches
MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88 Class Reference

Public Member Functions

 __construct (string $fen)
 Create a new FenParser.
 
 setFen ( $fen)
 Set new fen position Example: $parser = new FenParser0x88(); $parser->setFen('8/7P/8/8/1k15/8/P7/K7 w - - 0 1');.
 
 isValid ( $move, $fen)
 Check if a move is valid.
 
 getEnPassantSquare ()
 Returns en passant square or null.
 
 getColor ()
 Return color to move, "white" or "black".
 
 getValidMovesAndResult ()
 Returns valid moves in 0x88 numeric format and result.
 
 getCaptureAndProtectiveMoves ( $color)
 Returns comma-separated string of moves (since it's faster to work with than arrays).
 
 getSlidingPiecesAttackingKing ( $color)
 Get a list of sliding pieces attacking the king of a color.
 
 getPinned ( $color)
 Return numeric squares(0x88) of pinned pieces.
 
 getValidSquaresOnCheck ( $color)
 Get valid squares for other pieces than king to move to when in check.
 
 getBishopCheckPath ( $piece, $king)
 Get the path by which a bishop is checking a king.
 
 getRookCheckPath ( $piece, $king)
 Get the path by which a rook is chekcing a king.
 
 getCountChecks ( $kingColor, $moveString)
 Counts the number of pieces checking the $king.
 
 isEnPassantMove ( $move)
 Check if a move is en passant.
 
 isCastleMove ( $move)
 Check if a move is castling.
 
 getParsed ( $move)
 Get the parsed form of a move.
 
 getFromAndToByNotation ( $notation)
 Get from and to by notation.
 
 move ( $move)
 Make a move on the board.
 
 getFen ()
 Returns FEN for current position.
 

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::__construct ( string $fen)

Create a new FenParser.

Parameters
string$fen

Member Function Documentation

◆ getBishopCheckPath()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getBishopCheckPath ( $piece,
$king )

Get the path by which a bishop is checking a king.

Parameters
array$piece
array$king
Returns
array

◆ getCaptureAndProtectiveMoves()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getCaptureAndProtectiveMoves ( $color)

Returns comma-separated string of moves (since it's faster to work with than arrays).

Parameters
string$color
Returns
string

◆ getColor()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getColor ( )

Return color to move, "white" or "black".

Returns
string
Exceptions
ChessBrowserException

◆ getCountChecks()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getCountChecks ( $kingColor,
$moveString )

Counts the number of pieces checking the $king.

$king is set by FenParser0x88::parseFen and FenParser0x88::updatePieces where $king['s'] is the square the king occupies. To determine if the $king is in check, this method evaluates whether the square the king is on—$king['s']—is one (or more) of the squares the opponent's pieces can move to.

Because FenParser0x88::getCaptureAndProtectiveMoves returns a string, this method searches that string to see how many times the king's square is in that list. Because the string '2' would match both '2' and '22', we ensure that it matches all and only the integer representing the king's square by searching for the integer surrounded by commas. The mapping from integer to substring (needle) is stored in Board0x88Config::$keySquares.

Parameters
string$kingColorColor of the king being checked; either 'white' or 'black'
string$moveStringa comma-delimited string of move targets, output by FenParser0x88::getCaptureAndProtectiveMoves. Each field is a square (represented by an integer) where the other player's pieces can move to.
See also
FenParser0x88::getCaptureAndProtectiveMoves
Board0x88Config::$keySquares
Returns
int

◆ getEnPassantSquare()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getEnPassantSquare ( )

Returns en passant square or null.

Returns
int|null

◆ getFen()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getFen ( )

Returns FEN for current position.

Returns
string

◆ getFromAndToByNotation()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getFromAndToByNotation ( $notation)

Get from and to by notation.

TODO document

Parameters
string$notation
Returns
array
Exceptions
ChessBrowserException

◆ getParsed()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getParsed ( $move)

Get the parsed form of a move.

Parameters
string | array$move
Returns
array

◆ getPinned()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getPinned ( $color)

Return numeric squares(0x88) of pinned pieces.

Parameters
string$color
Returns
array

◆ getRookCheckPath()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getRookCheckPath ( $piece,
$king )

Get the path by which a rook is chekcing a king.

Parameters
array$piece
array$king
Returns
array

◆ getSlidingPiecesAttackingKing()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getSlidingPiecesAttackingKing ( $color)

Get a list of sliding pieces attacking the king of a color.

Parameters
string$color
Returns
array

◆ getValidMovesAndResult()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getValidMovesAndResult ( )

Returns valid moves in 0x88 numeric format and result.

Returns
array

◆ getValidSquaresOnCheck()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::getValidSquaresOnCheck ( $color)

Get valid squares for other pieces than king to move to when in check.

i.e. squares which avoids the check.

Example: if white king on g1 is checked by rook on g8, then valid squares for other pieces are the squares g2,g3,g4,g5,g6,g7,g8. Squares are returned in numeric format

Parameters
string$color
Returns
array|null

◆ isCastleMove()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::isCastleMove ( $move)

Check if a move is castling.

TODO combine ifs

Parameters
array$move
Returns
bool

◆ isEnPassantMove()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::isEnPassantMove ( $move)

Check if a move is en passant.

TODO combine ifs

Parameters
array$move
Returns
bool

◆ isValid()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::isValid ( $move,
$fen )

Check if a move is valid.

Parameters
array$move
string$fen
Returns
bool

◆ move()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::move ( $move)

Make a move on the board.

Example:

$parser = new FenParser0x88(); $parser->newGame(); $parser->move("Nf3");

$move can be a string like Nf3, g1f3 or an array with from and to squares, like array("from" => "g1", "to"=>"f3")

Parameters
string | array$move
Exceptions
ChessBrowserException

◆ setFen()

MediaWiki\Extension\ChessBrowser\PgnParser\FenParser0x88::setFen ( $fen)

Set new fen position Example: $parser = new FenParser0x88(); $parser->setFen('8/7P/8/8/1k15/8/P7/K7 w - - 0 1');.

Parameters
string$fen

The documentation for this class was generated from the following file: