Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            /*
             */
            Search.init(3);
            benchStart();
            return;

            int       port   = 4000;    // int.Parse (Console.ReadLine ());
            string    ip     = "127.0.0.1";
            TcpClient client = new TcpClient(ip, port);

            stream = client.GetStream();


            while (true)
            {
                Byte[] data         = new byte[256];
                string incomingData = "";

                Int32 bytes = stream.Read(data, 0, data.Length);
                incomingData = Encoding.Default.GetString(data, 0, bytes);
                MoveHandler.playMove(formatBoard(incomingData));
                playMove(MoveHandler.getMoveString());
            }
        }
Exemplo n.º 2
0
        public static void minMaxSearch(Board startBoard)
        {
            List <int[]> moves = startBoard.getAvailableMoves(0);

            int[] results = new int[moves.Count];

            /*
             * Parallel.For(0, moves.Count, i => {
             *      int[] m = moves[i];
             *      Board simBoard = simulateMove(startBoard, new int[] { m[0], m[1] }, new int[] { m[2], m[3] }, 0);
             *      results[i] = alphaBetaSearch(simBoard, 1, depth, int.MinValue, int.MaxValue);
             *      //results[i] = (tempSearch(simBoard, 1, depth));
             * });
             */

            for (int i = 0; i < moves.Count; i++)
            {
                int[] m        = moves[i];
                Board simBoard = simulateMove(startBoard, new int[] { m[0], m[1] }, new int[] { m[2], m[3] }, 0);
                results[i] = (tempSearch(simBoard, 1, depth));
            }


            int bestIndex = getRandomBestMove(results.ToList());

            int[] bestMove = moves[bestIndex];
            MoveHandler.setMove(bestMove);
        }
Exemplo n.º 3
0
        private static void benchStart()
        {
            Stopwatch s       = new Stopwatch();
            int       amount  = 20;
            double    average = 0;

            for (int i = 0; i < amount; i++)
            {
                s.Reset();
                s.Start();
                MoveHandler.playMove(formatBoard(generateStartBoard()));
                s.Stop();
                Console.WriteLine("Time: " + s.ElapsedMilliseconds);
                average += s.ElapsedMilliseconds;
            }

            Console.WriteLine("Average: " + average / amount);
        }
Exemplo n.º 4
0
 public static string playBotMove(string boardMsg)
 {
     MoveHandler.playMove(formatBoard(boardMsg));
     return(MoveHandler.getMoveString());
 }