Beispiel #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();
        }
Beispiel #2
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]);
        }
Beispiel #3
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();
        }
Beispiel #4
0
 public void TestBishopPermutations()
 {
     var vex   = Bishop.BishopVectors;
     var perms = Bishop.GetPermutations(0);
     var strs  = perms.Select(x => Bitboard.ToString(x)).ToList();
 }