public bool IsCheckAfterMove(FigureMoving fm) { Board after = Move(fm); bool result = after.CanEatKing(); return(result); }
public bool CanMove(FigureMoving fm) { this.fm = fm; bool result = CanMoveFrom() && CanMoveTo() && CanFigureMove(); return(result); }
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); }
private bool CanEatKing() { Square oppKing = FindOpponentKing(); Moves moves = new Moves(this); foreach (FigureOnSquare fs in YieldFigures()) { FigureMoving fm = new FigureMoving(oppKing, fs); if (moves.CanMove(fm)) { return(true); } } return(false); }
void FindAllMoves() { allPossibleMoves = new List <FigureMoving>(); foreach (FigureOnSquare fs in board.YieldFigures()) { foreach (Square to in Square.YieldSquares()) { FigureMoving fm = new FigureMoving(to, fs); if (moves.CanMove(fm)) { if (!board.IsCheckAfterMove(fm)) { allPossibleMoves.Add(fm); } } } } }
public Chess Move(string move) //Example: move = Ke2e4 (K = king, e2 = old move, e4 = new move) { FigureMoving fm = new FigureMoving(move); //fm = from, to, figure, promotion if (!moves.CanMove(fm)) { return(this); } if (board.IsCheckAfterMove(fm)) { return(this); //the same board } Board nextBoard = board.Move(fm); //отвечает за ход, содержит всю инфу о доске, массив фигур, фен от которого отталкивается при пост новой доски, после хода Chess nextChess = new Chess(nextBoard); //запускает игру return(nextChess); }