public bool IsCheck() { Board after = new Board(Fen); after.MoveColor = MoveColor.FlipColor(); return(after.CanEatKing()); }
public Board Move(FigureMoving fm) { Board next = new Board(Fen); next.SetFigureAt(fm.From, Figure.none); next.SetFigureAt(fm.To, fm.Promotion == Figure.none ? fm.Figure : fm.Promotion); if (MoveColor == Color.black) { next.MoveNumber++; } next.MoveColor = MoveColor.FlipColor(); next.GenerateFen(); return(next); }
// Метод хода, создаем новую доску с измененным положением фигур public Board Move(FigureMoving fm) { Board next = new Board(Fen); // Новая доска с тем же феном next.SetFigureAt(fm.From, Figure.none); // Удаляем фигуру с прошлой клетки next.SetFigureAt(fm.To, fm.Promotion == Figure.none ? fm.Figure : fm.Promotion); // Двигаем фигуру (или еще и повышаем) if (MoveColor == Color.black) // Увеличиваем номер хода, если ходили черные { next.MoveNumber++; } next.MoveColor = MoveColor.FlipColor(); // Меняем игрока next.GenerateFen(); // Восстанавливаем фен по положению фигур return(next); }
public Board Move(FigureMoving fm) { Board next = new Board(Fen); Figure figure = (fm.Promotion == Figure.none) ? fm.Figure : fm.Promotion; next.SetFigureAt(fm.From, Figure.none); //remove the figure from the previous square next.SetFigureAt(fm.To, figure); //set new figure on the correspoding square next.MoveColor = MoveColor.FlipColor(); next.GenerateFen(); return(next); }
public Board Move(MovingFigure mf) { var nextBoardState = new Board(Fen); nextBoardState.SetFigureAt(mf.From, Figure.None); nextBoardState.SetFigureAt(mf.To, mf.Promotion == Figure.None ? mf.Figure : mf.Promotion); if (MoveColor == Color.Black) { nextBoardState.MoveNumber = MoveNumber + 1; } nextBoardState.MoveColor = MoveColor.FlipColor(); nextBoardState.UpdateCastlingData(mf); nextBoardState.GenerateNextFen(); return(nextBoardState); }
public Board Castle(MovingFigure king, MovingFigure rook) { var nextBoardState = new Board(Fen); nextBoardState.SetFigureAt(king.From, Figure.None); nextBoardState.SetFigureAt(king.To, king.Figure); nextBoardState.SetFigureAt(rook.From, Figure.None); nextBoardState.SetFigureAt(rook.To, rook.Figure); if (MoveColor == Color.Black) { nextBoardState.MoveNumber = MoveNumber + 1; } nextBoardState.MoveColor = MoveColor.FlipColor(); nextBoardState.UpdateCastlingData(king); nextBoardState.GenerateNextFen(); return(nextBoardState); }
private void UpdateMoveColor() { MoveColor = MoveColor.FlipColor(); }