Exemple #1
0
        public void TestBishopMoves1()
        {
            int idx   = 27;
            var vex   = Bishop.BishopVectors;
            var perms = Bishop.GetPermutations(idx);
            var moves = perms.Select(x => Bishop.GetMoves(x, idx)).ToList();

            var strsp = perms.Select(x => Bitboard.ToString(x)).ToList();
            var strsm = moves.Select(x => Bitboard.ToString(x)).ToList();
        }
Exemple #2
0
        public void BishopNumberOfMoves_HasNotMovedYetOnEmptyBoard_SevenPossibleMoves()
        {
            var board  = new BasePiece[8, 8];
            var Bishop = new Bishop()
            {
                Color = Color.White, Location = new Vector(0, 2)
            };

            board[0, 2] = Bishop;
            var possibleMoves = Bishop.GetMoves(board).Length;

            Assert.AreEqual(7, possibleMoves);
        }
Exemple #3
0
        public void TestBishopMoves2()
        {
            int idx = 0;

            ulong[] vex   = Bishop.BishopVectors;
            var     perms = Bishop.GetPermutations(idx);
            var     moves = perms.Select(x => Bishop.GetMoves(x, idx)).ToList();

            var strsp = perms.Select(x => Bitboard.ToString(x)).ToList();
            var strsm = moves.Select(x => Bitboard.ToString(x)).ToList();

            Assert.AreEqual((ulong)0x8040201008040200, moves[0]);
        }
Exemple #4
0
        public void BishopCannotCaptureFriendlyPieces_ReturnsTrue()
        {
            var board  = new BasePiece[8, 8];
            var Bishop = new Bishop()
            {
                Color = Color.White, Location = new Vector(0, 2)
            };

            for (int i = 0; i < 8; i++)
            {
                board[1, i] = new Pawn()
                {
                    Color = Color.White, Location = new Vector(1, i)
                };
            }
            var possibleMoves = Bishop.GetMoves(board).Length;

            Assert.IsTrue(possibleMoves == 0);
        }
Exemple #5
0
 private static void GenerateDiagAttacksLookup()
 {
     int[] probe = new int[14];
     for (int i = 0; i <= 119; ++i)
     {
         Bishop k = new Bishop(Side.White, new OX88Chessboard("/8/8/8/8/8/8/8/8 w - - 0 1"), i);
         int    n = k.GetMoves(0, probe);
         MakeDict(n, probe);
         for (int j = 0; j <= 119; ++j)
         {
             if (Square.SquareValid(i) && Square.SquareValid(j))
             {
                 if (destCells.Contains(j))
                 {
                     DiagAttackLookup[Square.Ox88Dist(i, j)] = GetDiagAttackDirFrom(i, j);
                 }
             }
         }
     }
 }
Exemple #6
0
        public static void CalculateMagic()
        {
            Logfile = "Log-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            int timeoutSeconds = 10;

            Console.Write("Rook or Bishop: ");
            string line = Console.ReadLine();
            bool   rook = (line.ToLower().Trim() == "rook");

            Console.Write("Position to start at: ");
            line = Console.ReadLine();
            idx  = Convert.ToInt32(line);

            Console.Write("# of positions to search: ");
            line = Console.ReadLine();
            int idxMax = Convert.ToInt32(line) + idx;

            Console.Write("Time for each iteration (seconds): ");
            line           = Console.ReadLine();
            timeoutSeconds = Convert.ToInt32(line);

            Console.Write("Number of worker threads: ");
            line = Console.ReadLine();
            int numberOfThreads = Convert.ToInt32(line);

            Bits = 14;

            while (true)
            {
                if (idx >= idxMax)
                {
                    break;
                }

                if (rook)
                {
                    var perms = Rook.GetPermutations(idx);
                    Map = new Dictionary <ulong, ulong>();

                    foreach (var perm in perms)
                    {
                        Map[perm] = Rook.GetMoves(perm, idx);
                    }
                }
                else
                {
                    var perms = Bishop.GetPermutations(idx);
                    Map = new Dictionary <ulong, ulong>();

                    foreach (var perm in perms)
                    {
                        Map[perm] = Bishop.GetMoves(perm, idx);
                    }
                }

                int cardinalCount = Map.Select(x => x.Value).Distinct().Count();

                Log("Position " + idx + " : " + Map.Count + "/" + cardinalCount + ". Searching for " + Bits + " bit index");

                Running   = true;
                Success   = false;
                StartTime = DateTime.Now;

                for (int i = 0; i < numberOfThreads; i++)
                {
                    new Thread(new ThreadStart(Find)).Start();
                }

                while (Running)
                {
                    if ((DateTime.Now - StartTime).TotalSeconds > timeoutSeconds)
                    {
                        Running = false;
                    }

                    Thread.Sleep(10);
                }

                Thread.Sleep(100);



                if (Success)
                {
                    Log("New best match for postition " + idx + ": " + MagicNumbers[idx].Item1 + " bits - " + MagicNumbers[idx].Item2);
                    Bits--;
                }
                else
                {
                    Log("Search aborted");
                    Bits = 14;
                    idx++;
                }
            }

            Log("-----------------------------");
            foreach (var kvp in MagicNumbers)
            {
                Log("" + kvp.Key + ": " + kvp.Value.Item1 + " bits: " + kvp.Value.Item2);
            }
            Log("-----------------------------");
            Log("All numbers found");
            Console.ReadLine();
        }