// inputs // - previous piece state // - current piece state // - previous cell Piece // - piece team color (white, black) // - player castling status (if player have castled short or long or none) // - board - for checking ambiguity (multiple choice) public string ToSan(Cell currCell, Vector2Int prevPos, Piece targetPiece, Color teamColor, CastleStatus castleStatus) { _currCell = currCell; _prevPos = prevPos; _castleStatus = castleStatus; _teamColor = teamColor; _targetPiece = targetPiece; if (IsCastleShort() && castleStatus == CastleStatus.NONE) { return("0-0"); } if (IsCastleLong() && castleStatus == CastleStatus.NONE) { return("0-0-0"); } string san = ""; if (IsCapturing()) { // eg. dxc4 if (currCell.CurrentPiece is Pawn) { var f = new[] { "a", "b", "c", "d", "e", "f", "g", "h" }[_prevPos.x]; var t = new[] { "a", "b", "c", "d", "e", "f", "g", "h" }[_currCell.BoardPosition.x]; var r = _currCell.BoardPosition.y + 1; san = f + "x" + t + r; } else { var f = GetPieceAsSymbol(_currCell.CurrentPiece); var t = new[] { "a", "b", "c", "d", "e", "f", "g", "h" }[_currCell.BoardPosition.x]; var r = _currCell.BoardPosition.y + 1; san = f + "x" + t + r; } } else { var f = GetPieceAsSymbol(_currCell.CurrentPiece); var t = new[] { "a", "b", "c", "d", "e", "f", "g", "h" }[_currCell.BoardPosition.x]; var r = _currCell.BoardPosition.y + 1; san = f + t + r; } if (IsKingInCheck()) { san += "+"; } return(san); }
public void MakeMove_Sets_Can_Castle_When_White_Rook_Captured(uint fromMove, uint toMove, CastleStatus castleStatus) { var gameState = new GameState("r3k2r/8/8/8/8/8/8/R3K2R b KQkq - 0 1", _zobristHash); var move = 0U; move = move.SetFromMove(fromMove); move = move.SetToMove(toMove); move = move.SetMovingPiece(MoveUtility.BlackRook); move = move.SetCapturedPiece(MoveUtility.WhiteRook); gameState.MakeMove(move, _zobristHash); Assert.That(gameState.CurrentWhiteCastleStatus, Is.EqualTo((int)castleStatus), "All Pieces Bitboard"); }