Example #1
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 EMoveNotation notation = EMoveNotation.Fan;

            var movingPiece   = new Piece(EPieces.WhiteKnight);
            var fromOneSquare = new Square(ESquare.d2);
            var fromTwoSquare = new Square(ESquare.g5);
            var toSquare      = new Square(ESquare.e4);

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

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

            var g = new Game();

            g.NewGame(fen);

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

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

            Assert.Equal(expectedPrimary, actualPrimary);
            Assert.Equal(expectedSecondary, actualSecondary);
        }
Example #2
0
        public void RanFileAmbiguationPositiveTest()
        {
            // Tests both knights moving to same square for File ambiguity

            const string        fen      = "8/6k1/8/8/3N4/8/1K1N4/8 w - - 0 1";
            const EMoveNotation notation = EMoveNotation.Ran;

            var movingPiece   = new Piece(EPieces.WhiteKnight);
            var fromOneSquare = new Square(ESquare.d2);
            var fromTwoSquare = new Square(ESquare.d4);
            var toSquare      = new Square(ESquare.f3);

            var uniChar        = movingPiece.GetPieceChar();
            var toSquareString = toSquare.GetSquareString();

            var expectedPrimary   = $"{uniChar}{fromOneSquare.GetSquareString()}-{toSquareString}";
            var expectedSecondary = $"{uniChar}{fromTwoSquare.GetSquareString()}-{toSquareString}";

            var pos = new Position();
            var g   = GameFactory.Create(pos);

            g.NewGame(fen);

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

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

            Assert.Equal(expectedPrimary, actualPrimary);
            Assert.Equal(expectedSecondary, actualSecondary);
        }
Example #3
0
        public static string ToNotation(this Move move, IPosition pos, EMoveNotation notation = EMoveNotation.Fan)
        {
            if (move.IsNullMove())
            {
                return("(none)");
            }

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

            return(func(move, pos));
        }
 public static bool HasFlagFast(this EMoveNotation value, EMoveNotation flag) => (value & flag) != 0;