Пример #1
0
        private IEnumerable <Move> GetDoubleFrontStepMoves(Piece pawn, Board board)
        {
            var startPosRow = board.IsWhitesTurn ? whitePawnStartRow : blackPawnStartRow;
            var isStartPos  = pawn.Position.row == startPosRow;

            if (!isStartPos)
            {
                yield break;
            }

            var destRow        = pawn.Position.row + (board.IsWhitesTurn ? -2 : 2);
            var dest           = (row : destRow, pawn.Position.col);
            var fieldInBetween = Avg(pawn.Position, dest);

            if (board.IsEmptyAt(dest) && board.IsEmptyAt(fieldInBetween))
            {
                yield return(new Move(pawn.Type, MoveType.EnPassantMove, pawn.Position, dest));
            }
        }
Пример #2
0
        private IEnumerable <Move> GetSingleFrontStepMoves(Piece pawn, Board board)
        {
            var destRow = pawn.Position.row + (board.IsWhitesTurn ? -1 : 1);
            var dest    = (row : destRow, pawn.Position.col);

            if (!board.IsEmptyAt(dest))
            {
                yield break;
            }

            if (!_promotionRows.Contains(dest.row))
            {
                yield return(new Move(pawn.Type, MoveType.Move, pawn.Position, dest));

                yield break;
            }

            var promotionPieceTypes = board.IsWhitesTurn ? _whitePromotionPieces : _blackPromotionPieces;

            foreach (var move in promotionPieceTypes.Select(pt => new Move(pawn.Type, MoveType.Move, pawn.Position, dest, pt)))
            {
                yield return(move);
            }
        }