コード例 #1
0
        private static void processLine(string line, TextWriter output, NodeCounter counter)
        {
            string comment, board;
            int    first = line.IndexOfAny(COMMENT_LEADERS);

            if (first < 0)
            {
                comment = "";
                board   = line.Trim(DELIMERS);
            }
            else
            {
                comment = line.Substring(first);
                board   = line.Substring(0, first).Trim(DELIMERS);
            }
            string[] boardParts = board.Split(DELIMERS, StringSplitOptions.RemoveEmptyEntries);
            if (boardParts.Length == 0)               // we are done here
            {
                output.WriteLine(comment);
                output.Flush();
                return;
            }

            processBoard(boardParts, output, counter);
            output.WriteLine(comment);
            output.Flush();
        }
コード例 #2
0
 public static void runScript(TextReader input, TextWriter output)
 {
     NodeCounter counter = new NodeCounter();
     string line;
     while ((line = input.ReadLine()) != null) {
         processLine(line, output, counter);
         if (line == END) break;
     }
     outputCounter(counter, output);
 }
コード例 #3
0
 private static void outputCounter(NodeCounter counter, TextWriter output)
 {
     output.Write("Total:");
     output.Write("\t");
     output.Write("");
     output.Write("\t");
     output.Write(nodesString(counter.totalNodes));
     output.Write("\t");
     output.Write(npsString(counter.totalTime, counter.totalNodes));
     output.Write("\t");
     output.Write(counter.totalTime.TotalSeconds.ToString("0.0") + " s");
     output.WriteLine("\t");
 }
コード例 #4
0
        public static void runScript(TextReader input, TextWriter output)
        {
            NodeCounter counter = new NodeCounter();
            string      line;

            while ((line = input.ReadLine()) != null)
            {
                processLine(line, output, counter);
                if (line == END)
                {
                    break;
                }
            }
            outputCounter(counter, output);
        }
コード例 #5
0
        private static void processLine(string line, TextWriter output, NodeCounter counter)
        {
            string comment, board;
            int first = line.IndexOfAny(COMMENT_LEADERS);
            if (first < 0) {
                comment = "";
                board = line.Trim(DELIMERS);
            } else {
                comment = line.Substring(first);
                board = line.Substring(0, first).Trim(DELIMERS);
            }
            string[] boardParts = board.Split(DELIMERS, StringSplitOptions.RemoveEmptyEntries);
            if (boardParts.Length == 0) { // we are done here
                output.WriteLine(comment);
                output.Flush();
                return;
            }

            processBoard(boardParts, output, counter);
            output.WriteLine(comment);
            output.Flush();
        }
コード例 #6
0
        private static void processBoard(string[] boardParts, TextWriter output, NodeCounter counter)
        {
            // check params first
            if (boardParts.Length < 2) {
                output.Write("Error: not enough arguments supplied.\t");
                return;
            }
            Chess[,] board = parseBoard(boardParts[0]);
            if (board == null) {
                output.Write("Error: board not recognized.\t");
                return;
            }

            Chess mover = parseMover(boardParts[1]);
            if (mover == Chess.AVAILABLE) {
                output.Write("Error: mover not recognized.\t");
                return;
            }

            bool wld = false, warmup = false;
            int mid = 0;
            for (int i = 2; i < boardParts.Length; i++) {
                string option = boardParts[i].ToUpper();
                if (option == "WLD")
                    wld = true;
                else if (option == "WARMUP")
                    warmup = true;
                else if (option.StartsWith("MID")) {
                    Int32.TryParse(option.Substring(3), out mid);
                    if (mid < 0) mid = 0;
                }
            }

            Engine.clearCache();
            Engine engine = new Engine();
            engine.setBoard(board);

            DateTime timeStart = DateTime.Now;
            SearchResult res = (mid == 0) ? engine.solveExact(mover, wld) : engine.solve(mover, mid, false);
            TimeSpan timeSpan = DateTime.Now - timeStart;

            SearchStats stats = engine.getSearchStats();

            engine.Dispose();

            output.Write(resultString(res, wld, mid));
            output.Write("\t");
            output.Write(moveString(res));
            output.Write("\t");
            output.Write(nodesString(stats.EvaluationCount));
            output.Write("\t");
            output.Write(npsString(timeSpan, stats.EvaluationCount));
            output.Write("\t");
            output.Write(timeSpan.TotalSeconds.ToString("0.0") + " s");
            output.Write("\t");

            if (!warmup) {
                counter.totalNodes += stats.EvaluationCount;
                counter.totalTime += timeSpan;
            }
        }
コード例 #7
0
 private static void outputCounter(NodeCounter counter, TextWriter output)
 {
     output.Write("Total:");
     output.Write("\t");
     output.Write("");
     output.Write("\t");
     output.Write(nodesString(counter.totalNodes));
     output.Write("\t");
     output.Write(npsString(counter.totalTime, counter.totalNodes));
     output.Write("\t");
     output.Write(counter.totalTime.TotalSeconds.ToString("0.0") + " s");
     output.WriteLine("\t");
 }
コード例 #8
0
        private static void processBoard(string[] boardParts, TextWriter output, NodeCounter counter)
        {
            // check params first
            if (boardParts.Length < 2)
            {
                output.Write("Error: not enough arguments supplied.\t");
                return;
            }
            Chess[,] board = parseBoard(boardParts[0]);
            if (board == null)
            {
                output.Write("Error: board not recognized.\t");
                return;
            }

            Chess mover = parseMover(boardParts[1]);

            if (mover == Chess.AVAILABLE)
            {
                output.Write("Error: mover not recognized.\t");
                return;
            }

            bool wld = false, warmup = false;
            int  mid = 0;

            for (int i = 2; i < boardParts.Length; i++)
            {
                string option = boardParts[i].ToUpper();
                if (option == "WLD")
                {
                    wld = true;
                }
                else if (option == "WARMUP")
                {
                    warmup = true;
                }
                else if (option.StartsWith("MID"))
                {
                    Int32.TryParse(option.Substring(3), out mid);
                    if (mid < 0)
                    {
                        mid = 0;
                    }
                }
            }

            Engine.clearCache();
            Engine engine = new Engine();

            engine.setBoard(board);

            DateTime     timeStart = DateTime.Now;
            SearchResult res       = (mid == 0) ? engine.solveExact(mover, wld) : engine.solve(mover, mid, false);
            TimeSpan     timeSpan  = DateTime.Now - timeStart;

            SearchStats stats = engine.getSearchStats();

            engine.Dispose();

            output.Write(resultString(res, wld, mid));
            output.Write("\t");
            output.Write(moveString(res));
            output.Write("\t");
            output.Write(nodesString(stats.EvaluationCount));
            output.Write("\t");
            output.Write(npsString(timeSpan, stats.EvaluationCount));
            output.Write("\t");
            output.Write(timeSpan.TotalSeconds.ToString("0.0") + " s");
            output.Write("\t");

            if (!warmup)
            {
                counter.totalNodes += stats.EvaluationCount;
                counter.totalTime  += timeSpan;
            }
        }