Exemple #1
0
 public Move(Square from, Square to, MoveTypes type = MoveTypes.Normal)
     : this()
 {
     From = from;
     To = to;
     Type = type;
 }
Exemple #2
0
        public void AttackedFrom_WhteRookE1KnightC3C4BlackRookA4TargetE4_ReturnsBitboardC3E1()
        {
            // arrange
            var white = new Side(
                "G1",
                new PieceSet<Queen>(),
                new PieceSet<Bishop>(),
                new PieceSet<Knight>(Bitboard.With.C3.C4),
                new PieceSet<Rook>(Bitboard.With.E1),
                new WhitePawns()
                );

            var black = new Side(
                "G8",
                new PieceSet<Queen>(),
                new PieceSet<Bishop>(),
                new PieceSet<Knight>(),
                new PieceSet<Rook>(Bitboard.With.A4),
                new BlackPawns()
                );

            var target = new Square("E4");
            Bitboard expected = Bitboard.With.C3.E1.Build();

            // act
            Bitboard result = target.AttackedFrom(white, black);

            // assert
            result.Should().Be(expected);
        }
Exemple #3
0
        public Bitboard GetCapturesMoveBoard(Bitboard notblockers, Bitboard enemies, Square? enpassant)
        {
            if (enpassant != null)
                enemies &= new Bitboard().And((Square) enpassant);

            Bitboard bleft = Locations.Except(new File(7)).Shift(-1, +1).Intersect(enemies);
            Bitboard bright = Locations.Except(new File(0)).Shift(-1, -1).Intersect(enemies);
            return bleft | bright;
        }
Exemple #4
0
 public IEnumerable<Move> GetAllMoves(
     Bitboard notblockers,
     Bitboard enemies,
     Square? enpassant
     )
 {
     return GetMovesOneSquareForward(notblockers)
         .Union(GetMovesTwoSquaresForward(notblockers))
         .Union(GetCaptures(enemies, enpassant));
 }
Exemple #5
0
        public IEnumerable<Move> GetCaptures(Bitboard enemies, Bitboard filterFrom, Bitboard filterTo, Square? enpassant = null)
        {
            if (enpassant != null)
                enemies |= new Bitboard().And((Square) enpassant);

            enemies &= filterTo;
            Bitboard l = Locations.Intersect(filterFrom);
            Bitboard bleft = l.Except(new File(7)).Shift(-1, +1).Intersect(enemies);
            Bitboard bright = l.Except(new File(0)).Shift(-1, -1).Intersect(enemies);

            return GetMoves(bleft, 7).Union(GetMoves(bright, 9));
        }
Exemple #6
0
        public Bitboard GetMoveBoard(Bitboard notblockers, Bitboard enemies, Square? enpassant)
        {
            ulong onesquarforward = (Locations >> 8 & notblockers);

            Bitboard twosquaresforward = Locations
                .Intersect(new Rank(6))
                .Shift(-1, 0).Intersect(notblockers)
                .Shift(-1, 0).Intersect(notblockers);

            return onesquarforward | twosquaresforward |
                   GetCapturesMoveBoard(notblockers, enemies, enpassant);
        }
Exemple #7
0
        public Bitboard Get(Square from,
            Bitboard friends,
            Bitboard enemies
            )
        {
            var allpieces = friends.And(enemies);
            var result = Bitboard.Empty.And(from.DiagonalNW, from.DiagonalNE);

            return result.Except(from, friends,
                                 from.RayTo.NE.Intersect(allpieces).LowestSquare.RayTo.NE,
                                 from.RayTo.NW.Intersect(allpieces).LowestSquare.RayTo.NW,
                                 from.RayTo.SE.Intersect(allpieces).HighestSquare.RayTo.SE,
                                 from.RayTo.SW.Intersect(allpieces).HighestSquare.RayTo.SW);
        }
Exemple #8
0
        public void Attacks_RookD5TargetE1_returnsFalse()
        {
            // arrange
            var s = new Side("G8",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(Bitboard.With.D5),
                             new BlackPawns());

            var enemy = new Square("E1");

            // act
            bool result = s.Attacks(enemy, enemy.AsBoard);

            // assert
            result.Should().Be(false);
        }
Exemple #9
0
        public void GetBlockersToStaightAttacks_RookE1BishopE4TargetE5_ReturnsD4Bitboard()
        {
            // arrange
            var s = new Side("G1",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(Bitboard.With.E4),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(Bitboard.With.E1),
                             new WhitePawns()
                );

            var target = new Square("E5");

            // act
            Bitboard blockers = s.GetBlockersToStraightAttacks(target, Bitboard.Empty);

            // assert
            blockers.Should().Be(new Square("E4").AsBoard);
        }
Exemple #10
0
        public void GetDirectAttackMoves_BlackPawnsD4G4H6TargetE2()
        {
            // arrange
            var s = new Side("G8",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(),
                             new BlackPawns(Bitboard.With.D4.G4.H6)
                );

            Bitboard enemy = new Square("F3").AsBoard;

            // act
            IEnumerable<Move> result = s.GetDirectAttackMoves("E2", enemy);

            // assert
            result.Should().Have.SameSequenceAs(
                new Move("G4", "F3"),
                new Move("D4", "D3")
                );
        }
Exemple #11
0
        public void GetBlockersToDiagonalAttacks_BishopA1RookInD4TargetInE5_ReturnsD4Bitboard()
        {
            // arrange
            var s = new Side("G1",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(Bitboard.With.A1),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(Bitboard.With.D4),
                             new WhitePawns()
                );

            var target = new Square("E5");

            // act
            Bitboard blockers = s.GetBlockersToDiagonalAttacks(target, Bitboard.Empty);

            // assert
            blockers.Should().Be(new Square("D4").AsBoard);
        }
Exemple #12
0
        public void GetBlockersToDiagonalAttacks_BishopA1WhitePawnsInitialPositionTargetInE5_ReturnsB2Bitboard()
        {
            // arrange
            var s = new Side("G1",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(Bitboard.With.A1),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(),
                             WhitePawns.InitialPosition
                );

            var target = new Square("E5");

            // act
            Bitboard blockers = s.GetBlockersToDiagonalAttacks(target, Bitboard.Empty);

            // assert
            blockers.Should().Be(new Square("B2").AsBoard);
        }
Exemple #13
0
 public Rays(Square origin)
     : this()
 {
     originField = origin;
 }
Exemple #14
0
 public IEnumerable<Move> GetCaptures(Bitboard enemies, Square? enpassant = null)
 {
     return GetCaptures(enemies, Bitboard.Full, Bitboard.Full, enpassant);
 }
Exemple #15
0
 public Bitboard Get(Square from, Bitboard friends, Bitboard enemies)
 {
     return Cache[from].Except(friends);
 }
Exemple #16
0
        public void ConstructFromRankAndFile_E7()
        {
            var square = new Square("7", "E");

            square.Index.Should().Be(52);
            square.IsValid.Should().Be.True();
            square.Rank.Index.Should().Be(6);
            square.File.Index.Should().Be(4);
            square.ToString().Should().Be("E7");
        }
Exemple #17
0
        public void GetDirectAttackMoves_WhitePawnsD4G4G2EnemyF5TargetE6()
        {
            // arrange
            var s = new Side("G1",
                             new PieceSet<Queen>(),
                             new PieceSet<Bishop>(),
                             new PieceSet<Knight>(),
                             new PieceSet<Rook>(),
                             new WhitePawns(Bitboard.With.D4.G4)
                );

            Bitboard enemy = new Square("F5").AsBoard;

            // act
            IEnumerable<Move> result = s.GetDirectAttackMoves("E6", enemy);

            // assert
            result.Should().Have.SameSequenceAs(
                new Move("G4", "F5"),
                new Move("D4", "D5")
                );
        }
Exemple #18
0
        public void MakeMove_InitialPositionE2E4_EnpassantShouldBeE3()
        {
            // arrange
            Board board = Board.NewGame();
            var enpassant = new Square("E3");
            // act
            Board result = board.MakeMove(new Move("E2", "E4"));

            // assert
            result.Enpassant.Value.Should().Be(enpassant);
            //Assert.Fail(result.Enpassant.ToString());
        }
Exemple #19
0
 public AttackMasks(Square target)
     : this()
 {
     Target = target;
 }