示例#1
0
        public void ShouldParseFromBoardMove(string @from, string to, DefaultActions moveType, string expectedSan)
        {
            var game = ChessFactory.NewChessGame();
            var move = BoardMove.Create(from.ToBoardLocation(), to.ToBoardLocation(), (int)moveType);

            Assert.That(StandardAlgebraicNotation.ParseFromGameMove(game.BoardState, move).ToNotation(), Is.EqualTo(expectedSan));
        }
        public void ShouldParseFromRank(string notation, int rank)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.FromFileX.HasValue.ShouldBeTrue();
            an.FromFileX.Value.ShouldBe(rank);
        }
        public void ShouldParsePromotion(string notation, ChessPieceName piece)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.PromotionPiece.HasValue.ShouldBeTrue();
            an.PromotionPiece.Value.ShouldBe(piece);
        }
        public void ShouldDisambiguateRank(string move, string expected)
        {
            var san = StandardAlgebraicNotation.Parse(move);

            san.FromFileX.HasValue.ShouldBeFalse();
            san.FromRankY.HasValue.ShouldBeTrue();
            san.FromRankY.Value.ShouldBe(4);
        }
        public void ShouldParseFromFile(string notation, int file)
        {
            StandardAlgebraicNotation.Parse(notation);
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.FromFileX.HasValue.ShouldBeTrue();
            an.FromFileX.Value.ShouldBe(file);
        }
        public void ShouldParsePieceName(string notation, ChessPieceName piece)
        {
            StandardAlgebraicNotation.Parse(notation);

            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.Piece.ShouldBe(piece);
        }
 public Move[] ToMoveList(params LocatedItem <ChessPieceEntity>[] locatedItems)
 {
     return(locatedItems
            .SelectMany(i => i.Paths.FlattenMoves())
            .Select(m => new Move
     {
         Coord = $"{m.ToChessCoords()}",
         SAN = StandardAlgebraicNotation.ParseFromGameMove(Game.BoardState, m, true).ToNotation()
     }).ToArray());
 }
示例#8
0
        public string Move(string input)
        {
            if (!StandardAlgebraicNotation.TryParse(input, out var san))
            {
                // TODO: More detailed error
                return($"Error: invalid move {input}, are you using upper-case for Files?");
            }

            _sanMoveFinder = new SanMoveFinder(_engine.BoardState);

            var move = _sanMoveFinder.Find(san, (Colours)_engine.CurrentPlayer);

            if (move == null)
            {
                return($"Error: No matching move found: {input}");
            }

            var validMove = PlayValidMove(move);

            return(validMove);
        }
        public void Should_put_plus_on_end_of_moves_that_cause_check()
        {
            // TODO: Better way to check this, than using a full board.
            var builder = new ChessBoardBuilder()
                          .Board("....rrk." +
                                 ".b...pp." +
                                 ".n...q.p" +
                                 "..p.N..." +
                                 ".pB....." +
                                 ".......P" +
                                 "PP...PP." +
                                 "R..QR.K."
                                 );

            var game      = ChessFactory.CustomChessGame(builder.ToGameSetup());
            var from      = "C4".ToBoardLocation();
            var piece     = game.BoardState.GetItem(from);
            var boardMove = piece.Paths.FindMove(from, "f7".ToBoardLocation());
            var san       = StandardAlgebraicNotation.ParseFromGameMove(game.BoardState, boardMove, true);

            san.ToNotation().ShouldBe("Bxf7+");
        }
        public void ShouldParseToRank(string notation, int rank)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.ToRankY.ShouldBe(rank);
        }
        public void ShouldParseToFile(string notation, int file)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.ToFileX.ShouldBe(file);
        }
        public void ShouldParseTakeMoves(string notation)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeTrue();

            an.MoveType.ShouldBe(SanMoveTypes.Take);
        }
 public void Should_parse_san_notation(string san)
 {
     StandardAlgebraicNotation.Parse(san).ToNotation().ShouldBe(san);
 }
        public void ShouldFailParsing(string notation)
        {
            StandardAlgebraicNotation.TryParse(notation, out var an).ShouldBeFalse();

            Should.Throw <Exception>(() => StandardAlgebraicNotation.Parse(notation));
        }
示例#15
0
 public static StandardAlgebraicNotation ToSan(this string s)
 {
     return(StandardAlgebraicNotation.Parse(s));
 }