Esempio n. 1
0
 public bool CanMove(FigureMoving fm)
 {
     this.fm = fm;
     return
         (CanMoveFrom() &&
          CanMoveTo() &&
          CanFigureMove());
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public Chess Move(FigureMoving move)
        {
            if (!moves.CanMove(move))
            {
                return(this);
            }
            if (board.IsCheckAfterMove(move))
            {
                return(this);
            }
            Board nextBoard = board.Move(move);
            Chess nextChess = new Chess(nextBoard);

            return(nextChess);
        }
Esempio n. 4
0
        private bool CanEatKing()
        {
            var badKing = FindBadKing();
            var moves   = new Moves(this);

            foreach (var item in YieldFigures())
            {
                var fm = new FigureMoving(item, badKing);
                if (moves.CanMove(fm))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        public Chess Move(string move) //Pe2e4
        {
            FigureMoving fm = new FigureMoving(move);

            if (!moves.CanMove(fm))
            {
                return(this);
            }
            if (board.IsCheckAfterMove(fm))
            {
                return(this);
            }
            Board nextBoard = board.Move(fm);
            Chess nextChess = new Chess(nextBoard);

            return(nextChess);
        }
Esempio n. 6
0
 void FindAllMoves()
 {
     allMoves = new List <FigureMoving>();
     foreach (var fs in board.YieldFigures())
     {
         foreach (var to in Square.YieldSquares())
         {
             var fm = new FigureMoving(fs, to);
             if (moves.CanMove(fm))
             {
                 if (!board.IsCheckAfterMove(fm))
                 {
                     allMoves.Add(fm);
                 }
             }
         }
     }
 }
Esempio n. 7
0
        public bool IsCheckAfterMove(FigureMoving fm) //невозможный ход
        {
            Board after = Move(fm);

            return(after.CanEatKing());
        }