public static CastlingRight CalculateCastlingRight(ColorT c, CastlingSide s) { return (CastlingRight)((int)CastlingRight.WHITE_OO << ((s == CastlingSide.QUEEN_SIDE ? 1 : 0) + 2 * c)); }
public static CastlingType ToCastlingType(this CastlingSide castlingSide, GameSide gameSide) { return(unchecked ((CastlingType)(((int)gameSide << 1) + castlingSide))); }
/// <summary> /// Проверяет, возможна ли рокировка с определнной стороны. Ход записывается во временный список. /// </summary> /// <param name="side">Сторона рокировки.</param> public void TestCastling(List <FigureMove> tempList, CastlingSide side) { // Определяем клетки между королем и ладьей (они должны быть свободны). List <Vector2Int> cellsBetweenKingAndRook = new List <Vector2Int>(); // Определяем клетки, которые проходит король при рокировке (они должны быть не по боем вражеских фигур). List <Vector2Int> kingPassesCells = new List <Vector2Int>(); Vector2Int rookPos; Vector2Int rookNewPos; if (side == CastlingSide.queenside) { cellsBetweenKingAndRook.Add(new Vector2Int(1, y)); cellsBetweenKingAndRook.Add(new Vector2Int(2, y)); cellsBetweenKingAndRook.Add(new Vector2Int(3, y)); kingPassesCells.Add(new Vector2Int(2, y)); kingPassesCells.Add(new Vector2Int(3, y)); // Ладья будет со стороны королевы rookPos = new Vector2Int(0, y); rookNewPos = new Vector2Int(3, y); } else { cellsBetweenKingAndRook.Add(new Vector2Int(5, y)); cellsBetweenKingAndRook.Add(new Vector2Int(6, y)); kingPassesCells.Add(new Vector2Int(5, y)); kingPassesCells.Add(new Vector2Int(6, y)); // Ладья будет со стороны короля rookPos = new Vector2Int(7, y); rookNewPos = new Vector2Int(5, y); } // Ищем ладью Figure figureInTheCorner = boardState.GetFigureAtCell(rookPos); bool rookInPlace = figureInTheCorner != null && figureInTheCorner.GetType() == typeof(Rook) && figureInTheCorner.color == color; if (!rookInPlace) { return; } Rook rook = (Rook)figureInTheCorner; // Фигуры не двигались с начала партии bool figuresNotMoved = moveCount == 0 && rook.moveCount == 0; // Клетки меджу ними свободны bool cellsBetweenAreFree = cellsBetweenKingAndRook.TrueForAll((cell) => boardState.GetFigureAtCell(cell) == null); // Клетки между ними не под боем bool kingCellsAreUnderAttack = boardState.AnyCellIsUnderAttack(kingPassesCells, InvertColor(color)); // Король не под шахом bool kingIsUnderAttack = boardState.DetectCheck(this); if (figuresNotMoved && cellsBetweenAreFree) { int newX = side == CastlingSide.queenside ? 2 : 6; tempList.Add( new CastlingMove( from: Pos, to: new Vector2Int(newX, y), rookFrom: rookPos, rookTo: rookNewPos, passedFirstCheck: !kingCellsAreUnderAttack && !kingIsUnderAttack ) ); } }
internal static CastlingRight MakeCastling(ColorT C, CastlingSide S) { return C == Color.WHITE ? S == CastlingSide.QUEEN_SIDE ? CastlingRight.WHITE_OOO : CastlingRight.WHITE_OO : S == CastlingSide.QUEEN_SIDE ? CastlingRight.BLACK_OOO : CastlingRight.BLACK_OO; }