示例#1
0
    static public void testGenerateNewBoard()
    {
        GenerateRandomBoard ranBoard = new GenerateRandomBoard(17, Pentago_GameBoard.whites_turn);

        ranBoard.generateNewBoard();
        ranBoard.Pentago_gb.print_board();
        ranBoard.generateNewBoard();
        ranBoard.Pentago_gb.print_board();
    }
示例#2
0
    static public void testPerformnace(int numOfBorads)
    {
        Pentago_GameBoard[] testBoardsWhites = new Pentago_GameBoard[numOfBorads];
        Pentago_GameBoard[] testBoardsBlacks = new Pentago_GameBoard[numOfBorads];

        for (int i = 0; i < numOfBorads; i++)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(0, 17);
            Console.WriteLine("Num of pieces " + numPieces);
            GenerateRandomBoard rndBoard;

            Console.WriteLine("white");

            rndBoard = new GenerateRandomBoard(numPieces - 1, true); // -1 prencipio de iguldade de peças do tabuleiro
            rndBoard.generateNewBoard();
            testBoardsWhites[i] = rndBoard.Pentago_gb;
            testBoardsWhites[i].print_board();

            Console.WriteLine("black");

            rndBoard = new GenerateRandomBoard(numPieces, false);
            rndBoard.generateNewBoard();
            testBoardsBlacks[i] = rndBoard.Pentago_gb;
            testBoardsBlacks[i].print_board();
        }

        Pentago_Rules wrules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.controlHeuristic,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_WHITES, false);
        MINMAX        test_w = new MINMAX(MINMAX.VERSION.minmax, wrules, 6);
        Pentago_Rules brules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.controlHeuristic,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX test_b = new MINMAX(MINMAX.VERSION.minmax, brules, 6);

        TimeSpan test1 = Performance.PerformanceTimes(test_w, testBoardsWhites);
        TimeSpan test2 = Performance.PerformanceTimes(test_b, testBoardsBlacks);

        TimeSpan ts = test1.Add(test2);

        string elapsedTime1 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            test1.Hours, test1.Minutes, test1.Seconds,
                                            test1.Milliseconds / 10);

        string elapsedTime2 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            test2.Hours, test2.Minutes, test2.Seconds,
                                            test2.Milliseconds / 10);

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                           ts.Hours, ts.Minutes, ts.Seconds,
                                           ts.Milliseconds / 10);

        Console.WriteLine("RunTime " + elapsedTime);
        Console.WriteLine("RunTime 1 " + elapsedTime1);
        Console.WriteLine("RunTime 2 " + elapsedTime2);
    }
示例#3
0
    static public void testPerformance(int numOfBorads, int numpieces, int depth, MINMAX[] toTest)
    {
        Pentago_GameBoard[] testBoards = new Pentago_GameBoard[numOfBorads];
        String filename_compareP       = "CompareMinmaxsWithEqualPieces/comp_D" + depth.ToString();

        add2File(filename_compareP, numpieces.ToString(), false);

        if (numpieces % 2 == 0)
        {
            for (int i = 0; i < numOfBorads; i++)
            {
                GenerateRandomBoard rndBoard = new GenerateRandomBoard(numpieces / 2, true);
                rndBoard.generateNewBoard();
                testBoards[i] = rndBoard.Pentago_gb;
            }
        }
        else
        {
            for (int i = 0; i < numOfBorads; i++)
            {
                GenerateRandomBoard rndBoard = new GenerateRandomBoard((numpieces + 1) / 2, false);
                rndBoard.generateNewBoard();
                testBoards[i] = rndBoard.Pentago_gb;
            }
        }

        for (int i = 0; i < toTest.Length; ++i)
        {
            if (numpieces % 2 == 0)
            {
                ((Pentago_Rules)toTest[i].rules).IA_PIECES = Pentago_Rules.IA_PIECES_WHITES;
            }
            else
            {
                ((Pentago_Rules)toTest[i].rules).IA_PIECES = Pentago_Rules.IA_PIECES_BLACKS;
            }

            long   test    = Performance.PerformanceTimeMilisecs(toTest[i], testBoards);
            string timeStr = test.ToString();

            String vers            = toTest[i].version.ToString() + "_" + ((Pentago_Rules)toTest[i].rules).nsf.ToString() + "_" + ((Pentago_Rules)toTest[i].rules).remove_repeated_states_on_nextStates.ToString();
            String filename_depth  = "CheckComplexityPieces/" + vers + "_D" + depth.ToString();
            String filename_pieces = "CheckComplexityDepth/" + vers + "_P" + numpieces;

            add2File(filename_depth, numpieces.ToString() + ";" + timeStr);
            add2File(filename_pieces, depth.ToString() + ";" + timeStr);
            add2File(filename_compareP, ";" + timeStr, false);
        }
        add2File(filename_compareP, "");
    }
示例#4
0
    static public void testPerformnace(int numOfBorads)
    {
        using (Process p = Process.GetCurrentProcess())
        {
            p.PriorityClass = ProcessPriorityClass.High;
        }

        Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

        Pentago_GameBoard[] testBoardsWhites = new Pentago_GameBoard[numOfBorads];
        Pentago_GameBoard[] testBoardsBlacks = new Pentago_GameBoard[numOfBorads];

        for (int i = 0; i < numOfBorads; i++)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(0, 16);
            GenerateRandomBoard rndBoard = new GenerateRandomBoard(numPieces, true);
            rndBoard.generateNewBoard();
            testBoardsWhites[i] = rndBoard.Pentago_gb;
        }

        for (int i = 0; i < numOfBorads; i++)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(0, 16);
            GenerateRandomBoard rndBoard = new GenerateRandomBoard(numPieces, false);
            rndBoard.generateNewBoard();
            testBoardsBlacks[i] = rndBoard.Pentago_gb;
        }



        Pentago_Rules wrulesm = new Pentago_Rules(Pentago_Rules.EvaluationFunction.one,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_WHITES, false);
        Pentago_Rules brulesm = new Pentago_Rules(Pentago_Rules.EvaluationFunction.one,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX   test_wm = new MINMAX(MINMAX.VERSION.minmax, wrulesm, 4);
        MINMAX   test_bm = new MINMAX(MINMAX.VERSION.minmax, brulesm, 4);
        TimeSpan test1m  = Performance.PerformanceTimes(test_wm, testBoardsWhites);
        TimeSpan test2m  = Performance.PerformanceTimes(test_bm, testBoardsBlacks);

        TimeSpan tsm = test1m.Add(test2m);

        // Format and display the TimeSpan value.
        string elapsedTimem = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            tsm.Hours, tsm.Minutes, tsm.Seconds,
                                            tsm.Milliseconds / 10);

        Console.WriteLine("RunTime " + elapsedTimem);



        Pentago_Rules wrules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.one,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_WHITES, false);
        Pentago_Rules brules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.one,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX test_w = new MINMAX(MINMAX.VERSION.alphabeta, wrules, 4);
        MINMAX test_b = new MINMAX(MINMAX.VERSION.alphabeta, brules, 4);

        TimeSpan test1 = Performance.PerformanceTimes(test_w, testBoardsWhites);
        TimeSpan test2 = Performance.PerformanceTimes(test_b, testBoardsBlacks);

        TimeSpan ts = test1.Add(test2);

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                           ts.Hours, ts.Minutes, ts.Seconds,
                                           ts.Milliseconds / 10);

        Console.WriteLine("RunTime " + elapsedTime);
    }
示例#5
0
    // testa qual a euristica mais rápida entre heuristics1 e heuristicsA
    static public void testPerformnace1(int numOfBorads)
    {
        Pentago_GameBoard[] testBoardsWhites = new Pentago_GameBoard[numOfBorads];
        Pentago_GameBoard[] testBoardsBlacks = new Pentago_GameBoard[numOfBorads];

        for (int i = 0; i < numOfBorads; i++)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(0, 17);
            Console.WriteLine("Num of pieces " + numPieces);
            GenerateRandomBoard rndBoard;

            Console.WriteLine("white");

            rndBoard = new GenerateRandomBoard(numPieces == 0? 0: numPieces - 1, true); // -1 prencipio de iguldade de peças do tabuleiro
            rndBoard.generateNewBoard();
            testBoardsWhites[i] = rndBoard.Pentago_gb;
            testBoardsWhites[i].print_board();

            Console.WriteLine("black");

            rndBoard = new GenerateRandomBoard(numPieces, false);
            rndBoard.generateNewBoard();
            testBoardsBlacks[i] = rndBoard.Pentago_gb;
            testBoardsBlacks[i].print_board();
        }

        // heuristics1
        Pentago_Rules wrules1 = new Pentago_Rules(Pentago_Rules.EvaluationFunction.heuristic1,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_WHITES, false);
        MINMAX        test_w1 = new MINMAX(MINMAX.VERSION.minmax, wrules1, 4);
        Pentago_Rules brules1 = new Pentago_Rules(Pentago_Rules.EvaluationFunction.heuristic1,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX test_b1 = new MINMAX(MINMAX.VERSION.minmax, brules1, 4);

        // heuristicsA
        Pentago_Rules wrulesA = new Pentago_Rules(Pentago_Rules.EvaluationFunction.heuristicA,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_WHITES, false);
        MINMAX        test_wA = new MINMAX(MINMAX.VERSION.minmax, wrulesA, 4);
        Pentago_Rules brulesA = new Pentago_Rules(Pentago_Rules.EvaluationFunction.heuristicA,
                                                  Pentago_Rules.NextStatesFunction.all_states,
                                                  Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX test_bA = new MINMAX(MINMAX.VERSION.minmax, brulesA, 4);



        TimeSpan test1_1 = Performance.PerformanceTimes(test_w1, testBoardsWhites);
        TimeSpan test2_1 = Performance.PerformanceTimes(test_b1, testBoardsBlacks);

        TimeSpan ts_1 = test1_1.Add(test2_1);

        // Format and display the TimeSpan value.
        string elapsedTime_1 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                             ts_1.Hours, ts_1.Minutes, ts_1.Seconds,
                                             ts_1.Milliseconds / 10);

        Console.WriteLine("RunTime heuristic1 " + elapsedTime_1);
        //////////////////////////////////////////////////////////////////////////////
        TimeSpan test1_A = Performance.PerformanceTimes(test_wA, testBoardsWhites);
        TimeSpan test2_A = Performance.PerformanceTimes(test_bA, testBoardsBlacks);

        TimeSpan ts_A = test1_A.Add(test2_A);

        // Format and display the TimeSpan value.
        string elapsedTime_A = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                             ts_A.Hours, ts_A.Minutes, ts_A.Seconds,
                                             ts_A.Milliseconds / 10);

        Console.WriteLine("RunTime heuristicA " + elapsedTime_A);
    }
示例#6
0
    public static void RUN()
    {
        testBoards = new Pentago_GameBoard[number_of_games_div4_pertest * 2];

        int i = 0;

        for (; i < number_of_games_div4_pertest; ++i)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(1, 12);
            GenerateRandomBoard rndBoard = new GenerateRandomBoard(numPieces, true);
            rndBoard.generateNewBoard();
            testBoards[i] = rndBoard.Pentago_gb;
        }

        int aux = number_of_games_div4_pertest * 2;

        for (; i < aux; ++i)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(1, 12);
            GenerateRandomBoard rndBoard = new GenerateRandomBoard(numPieces, false);
            rndBoard.generateNewBoard();
            testBoards[i] = rndBoard.Pentago_gb;
        }

        //using AUTO depth  - - - - - - - - - - -
        //minimum is 4, gets bigger when there are more pieces on the board

        if (test_with_control_auto)
        {
            printLatexTableHeader();
            //control heuristic
            test00();
            printseparator();
            System.Threading.Thread.Sleep(1000);
            //heuristic1 vs control
            test01_0();
            test01_1();
            test02_0();
            test02_1();
            test03_0();
            test03_1();

            System.Threading.Thread.Sleep(1000);
            printseparator();
            //heuristic1.2 relaxed vs control
            test1dot2vsC_0(0);
            test1dot2vsC_0(1);
            test1dot2vsC_0(2);
            test1dot2vsC_0(3);
            test1dot2vsC_0(4);
            test1dot2vsC_0(5);
            test1dot2vsC_1(0);
            test1dot2vsC_1(1);
            test1dot2vsC_1(2);
            test1dot2vsC_1(3);
            test1dot2vsC_1(4);
            test1dot2vsC_1(5);

            printLatexTableFooter();
            Console.WriteLine();
            Console.WriteLine("%===========================================");
            Console.WriteLine();
            printLatexTableHeader();

            System.Threading.Thread.Sleep(1000);
            printseparator();
            //heuristicA vs control
            testAvsC_0(EVFC.A, 1);
            testAvsC_0(EVFC.A, 2);
            testAvsC_0(EVFC.A, 3);
            testAvsC_0(EVFC.A, 4);
            testAvsC_1(EVFC.A, 1);
            testAvsC_1(EVFC.A, 2);
            testAvsC_1(EVFC.A, 3);
            testAvsC_1(EVFC.A, 4);

            System.Threading.Thread.Sleep(1000);
            printseparator();
            //heuristicAstar vs control
            testAvsC_0(EVFC.Astar, 1);
            testAvsC_0(EVFC.Astar, 2);
            testAvsC_0(EVFC.Astar, 3);
            testAvsC_0(EVFC.Astar, 4);
            testAvsC_1(EVFC.Astar, 1);
            testAvsC_1(EVFC.Astar, 2);
            testAvsC_1(EVFC.Astar, 3);
            testAvsC_1(EVFC.Astar, 4);

            System.Threading.Thread.Sleep(1000);
            printseparator();
            //heuristicAhacked relaxed vs control
            testAvsC_0(EVFC.AplusDiagHack, 1);
            testAvsC_0(EVFC.AplusDiagHack, 2);
            testAvsC_0(EVFC.AplusDiagHack, 3);
            testAvsC_0(EVFC.AplusDiagHack, 4);
            testAvsC_1(EVFC.AplusDiagHack, 1);
            testAvsC_1(EVFC.AplusDiagHack, 2);
            testAvsC_1(EVFC.AplusDiagHack, 3);
            testAvsC_1(EVFC.AplusDiagHack, 4);

            printLatexTableFooter();
        }


        if (test_with_others_auto_suite1)
        {
            printLatexTableHeader();

            test_versus();

            printLatexTableFooter();
        }

        if (test_with_others_auto_suite2)
        {
            printLatexTableHeader();

            test_h12_notrelaxed1();
            test_h12_notrelaxed2();
            test_AstarNoRot1();
            test_AstarNoRot2();

            printLatexTableFooter();
        }

        //using depth 6 - - - - - - - - - - -
        //NOT SO SURE ABOUT USING 6

        if (test_with_control_d6)
        {
            //heuristic1 vs control

            System.Threading.Thread.Sleep(1000);
            //heuristic1.2 relaxed vs control

            System.Threading.Thread.Sleep(1000);
            //heuristicA relaxed vs control

            System.Threading.Thread.Sleep(1000);
            //heuristicAhacked relaxed vs control
        }

        if (test_with_others_d6)
        {
            System.Threading.Thread.Sleep(1000);
            //1.2 relaxed vs A

            System.Threading.Thread.Sleep(1000);
            //1.2 vs 1.2

            System.Threading.Thread.Sleep(1000);
            //A vs A

            System.Threading.Thread.Sleep(1000);
            //A vs Ahacked
        }
    }