Class Position
This class represents a position in standard chess
Inheritance
Implements
Inherited Members
Namespace: PonzianiComponents.Chesslib
Assembly: PonzianiComponents.dll
Syntax
public class Position : ICloneable
Constructors
| Improve this Doc View SourcePosition()
Create the start position
Declaration
public Position()
Position(String)
Create a position from a FEN string
Declaration
public Position(string fen)
Parameters
Type | Name | Description |
---|---|---|
System.String | fen | The position specified in FEN notation |
Properties
| Improve this Doc View SourceChess960
Position is a Chess960 position
Declaration
public bool Chess960 { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
DrawPlyCount
The number of plies since the last pawn push or capture
Declaration
public int DrawPlyCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
EPD
The EPD representation of the position (FEN without move number and h50 move counter
Declaration
public string EPD { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The En-passant square is only provided if there is a capture possible
EPSquare
The En-Passant Square (the to-square of an en passant capture). This square is only set, if an enpassant capture is possible (not after any pawn double move as in FEN standard)
Declaration
public Square EPSquare { get; }
Property Value
Type | Description |
---|---|
Square |
FEN
The FEN representation of the position In case of Chess960 X-Fen representation is used
Declaration
public string FEN { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The En-passant square is only provided if there is a capture possible
IsCheck
Returns true is side to move is in check
Declaration
public bool IsCheck { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsDoubleCheck
Returns true if side to move is double-checked
Declaration
public bool IsDoubleCheck { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsMate
Returns true if position is a mate
Declaration
public bool IsMate { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsStalemate
Returns true if position is stalemate
Declaration
public bool IsStalemate { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
MoveNumber
The move number of the current position
Declaration
public int MoveNumber { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
PolyglotKey
Hash Key of current position used to find position in Polyglot opening books
Declaration
public ulong PolyglotKey { get; }
Property Value
Type | Description |
---|---|
System.UInt64 |
SFEN
The Shredder-FEN representation of the position (only relevant for Chess960)
Declaration
public string SFEN { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The En-passant square is only provided if there is a capture possible
SideToMove
The side which has to make the next move
Declaration
public Side SideToMove { get; }
Property Value
Type | Description |
---|---|
Side |
Methods
| Improve this Doc View SourceApplyMove(Move)
Applies a move to the position
Declaration
public void ApplyMove(Move move)
Parameters
Type | Name | Description |
---|---|---|
Move | move | The move to be applied |
ApplyMove(String)
Applies a move to the position
Declaration
public void ApplyMove(string moveInUCINotation)
Parameters
Type | Name | Description |
---|---|---|
System.String | moveInUCINotation | The move to be applied in UCI notation |
ASCII()
ASCII rendering of position. Allows to printout a position diagram in console applications
Declaration
public string ASCII()
Returns
Type | Description |
---|---|
System.String | ASCII based position diagramm |
AsHTML()
HTML rendering of position. Useful for debugging within Visual Studio
Declaration
public string AsHTML()
Returns
Type | Description |
---|---|
System.String | An HTML string showing the position diagram |
CastlingAllowed(CastleFlag)
Returns true if the provided Castling option is allowed
Declaration
public bool CastlingAllowed(CastleFlag flag)
Parameters
Type | Name | Description |
---|---|---|
CastleFlag | flag |
Returns
Type | Description |
---|---|
System.Boolean |
CheckLegal(out String)
Checks if a position is legal and consistent
Declaration
public bool CheckLegal(out string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | out parameter providing information about cause of illegality |
Returns
Type | Description |
---|---|
System.Boolean | true, if position is legal, false otherwise |
Clone()
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object |
Divide(Int32)
Returns the Divide value (a variation of perft, listing all moves and for each move, the perft of the decremented depth)
Declaration
public Dictionary<Move, long> Divide(int depth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | depth | The depth for which the divide command shall be executed |
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<Move, System.Int64> | A Dictionary which contains for any legal move in the positions a perft result |
FixCastlingFlags()
Declaration
public void FixCastlingFlags()
GetMoves()
Generates a list of all legal Moves
Declaration
public List<Move> GetMoves()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Move> | List of all legal moves |
GetPhase()
Calculates the game phase starting by 0 at startposition and ending at 256 (Pawn ending)
Declaration
public int GetPhase()
Returns
Type | Description |
---|---|
System.Int32 | The game phase |
GetPiece(Square)
Get's the piece for a given square
Declaration
public Piece GetPiece(Square square)
Parameters
Type | Name | Description |
---|---|---|
Square | square | A square |
Returns
Type | Description |
---|---|
Piece | The piece on the square |
GetPieceSquareList()
Calculates a list of squares for each piece
Declaration
public Dictionary<Piece, List<Square>> GetPieceSquareList()
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<Piece, System.Collections.Generic.List<Square>> |
IsDrawnByInsufficientMatingMaterial()
Checks if position is drawn due to lack of sufficient mating material
Declaration
public bool IsDrawnByInsufficientMatingMaterial()
Returns
Type | Description |
---|---|
System.Boolean | true, if position is drawn |
Perft(Int32, Boolean)
Calculates the perft value of the current position See https://chessprogramming.wikispaces.com/Perft
Declaration
public long Perft(int depth, bool divide = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | depth | The depth for which perft should be calculated |
System.Boolean | divide | If true, the subresults for each move on the initial depth will be printed to console https://www.chessprogramming.org/Perft |
Returns
Type | Description |
---|---|
System.Int64 | The perft result |
ToSAN(Move)
Creates the SAN (Standard Algebraic Notation) encoding of a move
Declaration
public string ToSAN(Move move)
Parameters
Type | Name | Description |
---|---|---|
Move | move | The move to be encoded |
Returns
Type | Description |
---|---|
System.String | The SAN encoded move |