/// <summary> /// Load the structure from a binary reader /// </summary> /// <param name="reader"> Binary reader</param> public void LoadFromStream(System.IO.BinaryReader reader) { m_lVal1 = reader.ReadInt64(); m_lVal2 = reader.ReadInt64(); m_lVal3 = reader.ReadInt64(); m_lVal4 = reader.ReadInt64(); m_eInfo = (ChessBoard.BoardStateMaskE)reader.ReadInt32(); }
/// <summary> /// Reset the move history /// </summary> /// <param name="peBoard"> Board array</param> /// <param name="eInfo"> Board extra info</param> public void Reset(ChessBoard.PieceE[] peBoard, ChessBoard.BoardStateMaskE eInfo) { m_arrCountMove[0] = 0; m_iCountMoveDepth = 0; m_iMoveCount = 0; Array.Clear(m_arrHashCount, 0, m_arrHashCount.Length); ComputeCurrentPackedBoard(peBoard, eInfo); }
/// <summary> /// Compute the packed representation of a board /// </summary> /// <param name="peBoard"> Board array</param> /// <param name="eInfo"> Board extra info</param> public static PackedBoard ComputePackedBoard(ChessBoard.PieceE[] peBoard, ChessBoard.BoardStateMaskE eInfo) { PackedBoard packedBoard; packedBoard.m_lVal1 = ComputePackedValue(peBoard, 0); packedBoard.m_lVal2 = ComputePackedValue(peBoard, 16); packedBoard.m_lVal3 = ComputePackedValue(peBoard, 32); packedBoard.m_lVal4 = ComputePackedValue(peBoard, 48); packedBoard.m_eInfo = eInfo & ~ChessBoard.BoardStateMaskE.BlackToMove; return(packedBoard); }
/// <summary> /// Record a new entry in the table /// </summary> /// <param name="i64ZobristKey"> Zobrist key. Probably unique for this board position.</param> /// <param name="eExtraInfo"> Extra information about the board not contains in the Zobrist key</param> /// <param name="iDepth"> Current depth (reverse)</param> /// <param name="iValue"> Board evaluation</param> /// <param name="eType"> Type of the entry</param> public void RecordEntry(long i64ZobristKey, ChessBoard.BoardStateMaskE eExtraInfo, int iDepth, int iValue, TransEntryTypeE eType) { TransEntry entry; i64ZobristKey ^= (int)eExtraInfo; entry.m_i64Key = i64ZobristKey; entry.m_iGen = m_iGen; entry.m_eExtraInfo = eExtraInfo; entry.m_iDepth = iDepth; entry.m_iValue = iValue; entry.m_eType = eType; m_arrTransEntry[(UInt64)i64ZobristKey % (UInt64)m_arrTransEntry.Length] = entry; }
public void ParseFENTest() { PgnParser_Accessor target = new PgnParser_Accessor(); string strFEN = ""; ChessBoard.PlayerColorE eColorToMove; ChessBoard.BoardStateMaskE eBoardStateMask; int iEnPassant; bool bexpected = true; ChessBoard.PlayerColorE coloExpected = ChessBoard.PlayerColorE.Black; ChessBoard.BoardStateMaskE MaskoExpected = ChessBoard.BoardStateMaskE.BlackToMove; int iExpected = 0; bool bactual = target.ParseFEN(strFEN, out eColorToMove, out eBoardStateMask, out iEnPassant); // Сбой при создании частного метода доступа для "Microsoft.VisualStudio.TestTools.TypesAndSymbols.Assembly" Assert.Inconclusive("Сбой при создании частного метода доступа для \"Microsoft.VisualStudio.TestTools.T" + "ypesAndSymbols.Assembly\""); }
/// <summary> /// Set a board state mask depending on the passed value /// </summary> /// <param name="strValue"> Value (must be 0 or 1)</param> /// <param name="eMask"> Mask to add if 1</param> /// <returns> /// true if ok, false if error /// </returns> private bool SetBoardStateMask(string strValue, ChessBoard.BoardStateMaskE eMask) { bool bRetVal; switch (strValue) { case "0": bRetVal = true; break; case "1": bRetVal = true; BoardStateMask |= eMask; break; default: bRetVal = false; break; } return(bRetVal); }
/// <summary> /// Try to find if the current board has already been evaluated /// </summary> /// <param name="i64ZobristKey"> Zobrist key. Probably unique for this board position.</param> /// <param name="eExtraInfo"> Extra information about the board not contains in the Zobrist key</param> /// <param name="iDepth"> Current depth (reverse)</param> /// <param name="iAlpha"> Alpha cut off</param> /// <param name="iBeta"> Beta cut off</param> /// <returns> /// Int32.MaxValue if no valid value found, else value of the board. /// </returns> public int ProbeEntry(long i64ZobristKey, ChessBoard.BoardStateMaskE eExtraInfo, int iDepth, int iAlpha, int iBeta) { int iRetVal = Int32.MaxValue; TransEntry entry; i64ZobristKey ^= (int)eExtraInfo; entry = m_arrTransEntry[(UInt64)i64ZobristKey % (UInt64)m_arrTransEntry.Length]; if (entry.m_i64Key == i64ZobristKey && entry.m_iGen == m_iGen && entry.m_eExtraInfo == eExtraInfo) { if (entry.m_iDepth >= iDepth) { switch (entry.m_eType) { case TransEntryTypeE.Exact: iRetVal = entry.m_iValue; break; case TransEntryTypeE.Alpha: if (entry.m_iValue <= iAlpha) { iRetVal = iAlpha; } break; case TransEntryTypeE.Beta: if (entry.m_iValue >= iBeta) { iRetVal = iBeta; } break; } m_iCacheHit++; } } return(iRetVal); }
/// <summary> /// Parse FEN definition into a board representation /// </summary> /// <param name="strFEN"> FEN</param> /// <param name="eColorToMove"> Return the color to move</param> /// <param name="eBoardStateMask"> Return the mask of castling info</param> /// <param name="iEnPassant"> Return the en passant position or 0 if none</param> /// <returns> /// true if succeed, false if failed /// </returns> private bool ParseFEN(string strFEN, out ChessBoard.PlayerColorE eColorToMove, out ChessBoard.BoardStateMaskE eBoardStateMask, out int iEnPassant) { bool bRetVal = true; string[] arrCmd; string[] arrRow; string strCmd; int iPos; int iLinePos; int iBlankCount; ChessBoard.PieceE ePiece; eBoardStateMask = (ChessBoard.BoardStateMaskE) 0; iEnPassant = 0; eColorToMove = ChessBoard.PlayerColorE.White; arrCmd = strFEN.Split(' '); if (arrCmd.Length != 6) { bRetVal = false; } else { arrRow = arrCmd[0].Split('/'); if (arrRow.Length != 8) { bRetVal = false; } else { iPos = 63; foreach (string strRow in arrRow) { iLinePos = 0; foreach (char cChr in strRow) { ePiece = ChessBoard.PieceE.None; switch (cChr) { case 'P': ePiece = ChessBoard.PieceE.Pawn | ChessBoard.PieceE.White; break; case 'N': ePiece = ChessBoard.PieceE.Knight | ChessBoard.PieceE.White; break; case 'B': ePiece = ChessBoard.PieceE.Bishop | ChessBoard.PieceE.White; break; case 'R': ePiece = ChessBoard.PieceE.Rook | ChessBoard.PieceE.White; break; case 'Q': ePiece = ChessBoard.PieceE.Queen | ChessBoard.PieceE.White; break; case 'K': ePiece = ChessBoard.PieceE.King | ChessBoard.PieceE.White; break; case 'p': ePiece = ChessBoard.PieceE.Pawn | ChessBoard.PieceE.Black; break; case 'n': ePiece = ChessBoard.PieceE.Knight | ChessBoard.PieceE.Black; break; case 'b': ePiece = ChessBoard.PieceE.Bishop | ChessBoard.PieceE.Black; break; case 'r': ePiece = ChessBoard.PieceE.Rook | ChessBoard.PieceE.Black; break; case 'q': ePiece = ChessBoard.PieceE.Queen | ChessBoard.PieceE.Black; break; case 'k': ePiece = ChessBoard.PieceE.King | ChessBoard.PieceE.Black; break; default: if (cChr >= '1' && cChr <= '8') { iBlankCount = Int32.Parse(cChr.ToString()); if (iBlankCount + iLinePos <= 8) { for (int iIndex = 0; iIndex < iBlankCount; iIndex++) { m_chessBoard[iPos--] = ChessBoard.PieceE.None; } iLinePos += iBlankCount; } } else { bRetVal = false; } break; } if (bRetVal && ePiece != ChessBoard.PieceE.None) { if (iLinePos < 8) { m_chessBoard[iPos--] = ePiece; iLinePos++; } else { bRetVal = false; } } } if (iLinePos != 8) { bRetVal = false; } } if (bRetVal) { strCmd = arrCmd[1]; if (strCmd == "w") { eColorToMove = ChessBoard.PlayerColorE.White; } else if (strCmd == "b") { eColorToMove = ChessBoard.PlayerColorE.Black; } else { bRetVal = false; } strCmd = arrCmd[2]; if (strCmd != "-") { for (int iIndex = 0; iIndex < strCmd.Length; iIndex++) { switch (strCmd[iIndex]) { case 'K': eBoardStateMask |= ChessBoard.BoardStateMaskE.WRCastling; break; case 'Q': eBoardStateMask |= ChessBoard.BoardStateMaskE.WLCastling; break; case 'k': eBoardStateMask |= ChessBoard.BoardStateMaskE.BRCastling; break; case 'q': eBoardStateMask |= ChessBoard.BoardStateMaskE.BLCastling; break; } } } strCmd = arrCmd[3]; if (strCmd == "-") { iEnPassant = 0; } else { iEnPassant = PgnUtil.GetSquareIDFromPGN(strCmd); if (iEnPassant == -1) { iEnPassant = 0; } } } } } return(bRetVal); }
/// <summary> /// Update the current board packing /// </summary> /// <param name="eInfo"> Board extra info</param> public void UpdateCurrentPackedBoard(ChessBoard.BoardStateMaskE eInfo) { m_packedBoardCurrent.m_eInfo = eInfo & ~ChessBoard.BoardStateMaskE.BlackToMove; }
/// <summary> /// Compute the current packed representation of a board /// </summary> /// <param name="peBoard"> Board array</param> /// <param name="eInfo"> Board extra info</param> private void ComputeCurrentPackedBoard(ChessBoard.PieceE[] peBoard, ChessBoard.BoardStateMaskE eInfo) { m_packedBoardCurrent = ComputePackedBoard(peBoard, eInfo); }