Пример #1
0
        public List <TMove> GetMoves()
        {
            var cells = GetFreeCells();
            var moves = new List <TMove>();

            foreach (var cell in cells)
            {
                if (cell == null)
                {
                    continue;
                }
                var capture = cell.Piece;
                if (this is TPawn && capture == null && Cell.X > cell.X)
                {
                    capture = Cell.GetNeighbour(-1, 0).Piece;
                }
                if (this is TPawn && capture == null && Cell.X < cell.X)
                {
                    capture = Cell.GetNeighbour(1, 0).Piece;
                }

                if (capture?.Player == Player)
                {
                    continue;
                }
                var move = new TMove();
                move.Piece     = this;
                move.StartCell = Cell;
                move.StopCell  = cell;
                move.Capture   = capture;
                moves.Add(move);
            }
            return(moves);
        }
Пример #2
0
 public void Make()
 {
     if (Piece is TKing)
     {
         if (StopCell.X == StartCell.X - 2)
         {
             var rook = StartCell.GetNeighbour(-4, 0).Piece;
             rook.Cell = StopCell.GetNeighbour(1, 0);
         }
         if (StopCell.X == StartCell.X + 2)
         {
             var rook = StartCell.GetNeighbour(3, 0).Piece;
             rook.Cell = StopCell.GetNeighbour(-1, 0);
         }
     }
     Piece.Cell = StopCell;
     if (Capture != null)
     {
         Piece.Player.Enemy.Pieces.Remove(Capture);
     }
     Piece.MoveCount++;
     Piece.Player.Board.Moves.Add(this);
     Piece.Player.Board.ActivePlayer = Piece.Player.Board.ActivePlayer.Enemy;
 }