Example #1
0
        public string ToNotation(Move move, MoveNotations notation = MoveNotations.Fan)
        {
            if (move.IsNullMove())
            {
                return("(none)");
            }

            if (!_notationFuncs.TryGetValue(notation, out var func))
            {
                throw new InvalidMove("Invalid move notation detected.");
            }

            return(func(move));
        }
Example #2
0
        public void RookSanAmbiguityTest()
        {
            // Tests rook ambiguity notation for white rooks @ e1 and g2. Author : johnathandavis

            const string        fen      = "5r1k/p6p/4r1n1/3NPp2/8/8/PP4RP/4R1K1 w - - 3 53";
            const MoveNotations notation = MoveNotations.San;
            var expectedNotations        = new[] { "Ree2", "Rge2" };

            var game = GameFactory.Create(fen);

            var sanMoves = game.Pos
                           .GenerateMoves()
                           .Select(m => new MoveAmbiguity(game.Pos).ToNotation(m, notation))
                           .ToArray();

            foreach (var notationResult in expectedNotations)
            {
                Assert.Contains(sanMoves, s => s == notationResult);
            }
        }
Example #3
0
        public void FanRankFileAmbiguationPositiveTest()
        {
            // Tests both knights moving to same square for Rank ambiguity

            const string        fen      = "8/6k1/8/8/8/8/1K1N1N2/8 w - - 0 1";
            const MoveNotations notation = MoveNotations.Fan;

            var movingPiece   = new Piece(Pieces.WhiteKnight);
            var fromOneSquare = new Square(Squares.d2);
            var fromTwoSquare = new Square(Squares.f2);
            var toSquare      = new Square(Squares.e4);

            var uniChar        = movingPiece.GetUnicodeChar();
            var toSquareString = toSquare.ToString();

            var expectedPrimary   = $"{uniChar}{fromOneSquare.FileChar}{toSquareString}";
            var expectedSecondary = $"{uniChar}{fromTwoSquare.FileChar}{toSquareString}";

            var board      = new Board();
            var pieceValue = new PieceValue();
            var pos        = new Position(board, pieceValue);
            var g          = GameFactory.Create(pos);

            g.NewGame(fen);

            var w1 = new Move(fromOneSquare, toSquare);
            var w2 = new Move(fromTwoSquare, toSquare);

            var ambiguity = new MoveAmbiguity(pos);

            var actualPrimary   = ambiguity.ToNotation(w1, notation);
            var actualSecondary = ambiguity.ToNotation(w2, notation);

            Assert.Equal(expectedPrimary, actualPrimary);
            Assert.Equal(expectedSecondary, actualSecondary);
        }
Example #4
0
 public static bool HasFlagFast(this MoveNotations value, MoveNotations flag) => (value & flag) != 0;