public void FromStringComplexTest() { int count = 100; var rand = new Random(DateTime.Now.Millisecond); while ((count--) > 0) { var board = new BitBoard(); var str = new StringBuilder(64); str.Append('0', 64); var indices = GetRandomBits(rand.Next(64)); foreach (var point in indices) { board.SetBit((Square)(point.Item1*8 + point.Item2)); int index = (7 - point.Item1)*8 + point.Item2; str[index] = '1'; } Assert.AreEqual( board.GetInnerValue(), BitBoardHelper.FromString(str.ToString())); } }
public PawnMovesGenerator(BitBoard board, AttacksGenerator generator) : base(board, generator) { this.movesReferences = new Move[4][][][][]; this.movesReferences[(int)PawnTarget.SinglePush] = PawnBitBoardHelper.QuietMoves; this.movesReferences[(int)PawnTarget.LeftAttack] = PawnBitBoardHelper.AttacksLeftMoves; this.movesReferences[(int)PawnTarget.RightAttack] = PawnBitBoardHelper.AttacksRightMoves; this.movesReferences[(int)PawnTarget.DoublePush] = PawnBitBoardHelper.DoublePushes; }
public void BitsCountTest() { int count = 100000; while (count-- != 0) { string binaryString = this.Get64CharsString (); int onesCount = binaryString.Count ((c) => c == '1'); ulong val = Convert.ToUInt64 (binaryString, 2); BitBoard bb = new BitBoard (val); Assert.AreEqual (onesCount, bb.GetBitsCount ()); } }
public static MovesGenerator CreateGenerator(Figure figureType, BitBoard bb, AttacksGenerator ag) { switch (figureType) { case Figure.Pawn: return new PawnMovesGenerator(bb, ag); case Figure.Knight: case Figure.Bishop: case Figure.Rook: case Figure.Queen: return new MovesGenerator(bb, ag); case Figure.King: return new KingMovesGenerator(bb, ag); default: return null; } }
public void Test1ByteMoves() { int count = 100000; while ((count--) > 0) { Square start = (Square)rand.Next(64); var board = new BitBoard(); var randomSquares = GetRandomSquaresList(rand.Next(64)); var moves = new List<Move>(); foreach (var sq in randomSquares) { board.SetBit(sq); moves.Add(new Move(start, sq)); } var serializedMoves = BitBoardSerializer.GetMoves(start, board.GetInnerValue()).ToList(); bool isOk = true; if (serializedMoves.Count != moves.Count) isOk = false; if (isOk) for (int i = 0; i < serializedMoves.Count; ++i) if ((moves[i].From != serializedMoves[i].From) || (moves[i].To != serializedMoves[i].To)) { isOk = false; break; } Assert.IsTrue(isOk); } }
public bool IsDisjointWith(BitBoard b) { return((this.board & b.board) == 0); }
public bool IsSubsetOf(BitBoard b) { return((this.board & b.board) == this.board); }
public MovesGenerator(BitBoard bitboard, AttacksGenerator attacksgenerator) { this.board = bitboard; this.generator = attacksgenerator; }
public bool IsSubsetOf(BitBoard b) { return ((this.board & b.board) == this.board); }
public bool IsDisjointWith(BitBoard b) { return (this.board & b.board) == 0; }
public void Test1ByteSquares() { int count = 100000; while ((count--) > 0) { var board = new BitBoard(); var randomSquares = GetRandomSquaresList(rand.Next(64)); foreach (var sq in randomSquares) board.SetBit(sq); var serializedSquares = BitBoardSerializer.GetSquares(board.GetInnerValue()).Distinct().ToList(); serializedSquares.Sort(); Assert.IsTrue( Enumerable.SequenceEqual( serializedSquares, randomSquares)); } }
public KingMovesGenerator(BitBoard bitboard, AttacksGenerator attacksgenerator) : base(bitboard, attacksgenerator) { this.kingBoard = (KingBitBoard)bitboard; }