//********************************************************* // /// <summary> /// Reset initial board info /// </summary> /// <param name="eNextMoveColor"> Next color moving</param> /// <param name="bInitialBoardStd"> true if its a standard board, false if coming from FEN or design mode</param> /// <param name="eMask"> Extra bord information</param> /// <param name="iEnPassant"> Position for en passant</param> // //********************************************************* private void ResetInitialBoardInfo(PlayerColorE eNextMoveColor, bool bInitialBoardStd, BoardStateMaskE eMask, int iEnPassant) { PieceE ePiece; for (int iIndex = 0; iIndex < m_piPiecesCount.Length; iIndex++) { m_piPiecesCount[iIndex] = 0; } for (int iIndex = 0; iIndex < 64; iIndex++) { ePiece = m_pBoard[iIndex]; switch(ePiece) { case PieceE.King | PieceE.White: m_iWhiteKingPos = iIndex; break; case PieceE.King | PieceE.Black: m_iBlackKingPos = iIndex; break; } m_piPiecesCount[(int)ePiece]++; } m_iPossibleEnPassantAt = iEnPassant; m_iRBlackRookMoveCount = ((eMask & BoardStateMaskE.BRCastling) == BoardStateMaskE.BRCastling) ? 0 : 1; m_iLBlackRookMoveCount = ((eMask & BoardStateMaskE.BLCastling) == BoardStateMaskE.BLCastling) ? 0 : 1; m_iBlackKingMoveCount = 0; m_iRWhiteRookMoveCount = ((eMask & BoardStateMaskE.WRCastling) == BoardStateMaskE.WRCastling) ? 0 : 1; m_iLWhiteRookMoveCount = ((eMask & BoardStateMaskE.WLCastling) == BoardStateMaskE.WLCastling) ? 0 : 1; m_iWhiteKingMoveCount = 0; m_bWhiteCastle = false; m_bBlackCastle = false; m_i64ZobristKey = ZobristKey.ComputeBoardZobristKey(m_pBoard); m_eNextMoveColor = eNextMoveColor; m_bDesignMode = false; m_bStdInitialBoard = bInitialBoardStd; m_moveHistory.Reset(m_pBoard, ComputeBoardExtraInfo(PlayerColorE.White, false)); m_moveStack.Clear(); m_stackPossibleEnPassantAt.Clear(); }
//********************************************************* // /// <summary> /// Try to close the design mode. /// </summary> /// <param name="eNextMoveColor"> Color of the next move</param> /// <param name="eBoardMask"> Board extra information</param> /// <param name="iEnPassant"> Position of en passant or 0 if none</param> /// <returns> /// true if succeed, false if board is invalid /// </returns> // //********************************************************* public bool CloseDesignMode(PlayerColorE eNextMoveColor, BoardStateMaskE eBoardMask, int iEnPassant) { bool bRetVal; if (!m_bDesignMode) { bRetVal = true; } else { ResetInitialBoardInfo(eNextMoveColor, false, eBoardMask, iEnPassant); if (m_piPiecesCount[(int)(PieceE.King | PieceE.White)] == 1 && m_piPiecesCount[(int)(PieceE.King | PieceE.Black)] == 1) { bRetVal = true; } else { bRetVal = false; } } return(bRetVal); }
/// <summary> /// Reset initial board info /// </summary> /// <param name="eNextMoveColor"> Next color moving</param> /// <param name="bInitialBoardStd"> true if its a standard board, false if coming from FEN or design mode</param> /// <param name="eMask"> Extra bord information</param> /// <param name="iEnPassant"> Position for en passant</param> private void ResetInitialBoardInfo(PlayerColorE eNextMoveColor, bool bInitialBoardStd, BoardStateMaskE eMask, int iEnPassant) { PieceE ePiece; int iEnPassantCol; Array.Clear(m_piPiecesCount, 0, m_piPiecesCount.Length); for (int iIndex = 0; iIndex < 64; iIndex++) { ePiece = m_pBoard[iIndex]; switch(ePiece) { case PieceE.King | PieceE.White: m_iWhiteKingPos = iIndex; break; case PieceE.King | PieceE.Black: m_iBlackKingPos = iIndex; break; } m_piPiecesCount[(int)ePiece]++; } if (iEnPassant != 0) { iEnPassantCol = (iEnPassant >> 3); if (iEnPassantCol != 2 && iEnPassantCol != 5) { if (iEnPassantCol == 3) { // Fixing old saved board which was keeping the en passant position at the position of the pawn instead of behind it iEnPassant -= 8; } else if (iEnPassantCol == 4) { iEnPassant += 8; } else { iEnPassant = 0; } } } m_iPossibleEnPassantAt = iEnPassant; m_iRBlackRookMoveCount = ((eMask & BoardStateMaskE.BRCastling) == BoardStateMaskE.BRCastling) ? 0 : 1; m_iLBlackRookMoveCount = ((eMask & BoardStateMaskE.BLCastling) == BoardStateMaskE.BLCastling) ? 0 : 1; m_iBlackKingMoveCount = 0; m_iRWhiteRookMoveCount = ((eMask & BoardStateMaskE.WRCastling) == BoardStateMaskE.WRCastling) ? 0 : 1; m_iLWhiteRookMoveCount = ((eMask & BoardStateMaskE.WLCastling) == BoardStateMaskE.WLCastling) ? 0 : 1; m_iWhiteKingMoveCount = 0; m_bWhiteCastle = false; m_bBlackCastle = false; m_i64ZobristKey = ZobristKey.ComputeBoardZobristKey(m_pBoard); m_eNextMoveColor = eNextMoveColor; m_bDesignMode = false; m_bStdInitialBoard = bInitialBoardStd; m_moveHistory.Reset(m_pBoard, ComputeBoardExtraInfo(PlayerColorE.White, false)); m_moveStack.Clear(); m_stackPossibleEnPassantAt.Clear(); }