Exemplo n.º 1
0
    static void testAvsC_1(EVFC heur, int config)
    {
        Pentago_Rules wrules = new Pentago_Rules(EVFC.control,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_WHITES, false);
        MINMAX        minmax_w = new MINMAX(MINMAX.VERSION.alphabeta, wrules, 0);
        Pentago_Rules brules   = new Pentago_Rules(heur,
                                                   Pentago_Rules.NextStatesFunction.all_states,
                                                   Pentago_Rules.IA_PIECES_BLACKS, false);

        if (config == 1)
        {
            brules.setA_setup1();
        }
        if (config == 2)
        {
            brules.setA_setup2();
        }
        if (config == 3)
        {
            brules.setA_setup3();
        }
        if (config == 4)
        {
            brules.setA_setup4();
        }

        MINMAX minmax_b = new MINMAX(MINMAX.VERSION.alphabeta, brules, 0);

        test_aux(minmax_w, minmax_b, false);
    }
Exemplo n.º 2
0
    public void startGame()
    {
        if (!hackedStart)
        {
            if (IA_SETTINGS.VS_IA == IA_SETTINGS.vsMode.PIA)
            {
                if (IA_SETTINGS.PLAYER_1ST)
                {
                    game_mode = GAME_MODE.PlayerVsIA;
                }
                else
                {
                    game_mode = GAME_MODE.IAvsPlayer;
                }
            }
            else if (IA_SETTINGS.VS_IA == IA_SETTINGS.vsMode.IAIA)
            {
                game_mode = GAME_MODE.IAvsIA;
            }
            else
            {
                game_mode = GAME_MODE.PlayerVSPlayer;
            }
        }

        if (game_mode == GAME_MODE.PlayerVSPlayer || game_mode == GAME_MODE.PlayerVsIA)
        {
            gameState = GAME_STATE.playerselecthole;
        }
        else
        {
            gameState = GAME_STATE.startIA;
        }

        if (game_mode != GAME_MODE.PlayerVSPlayer)
        {
            if (!hackedStart)
            {
                minmax_depth = IA_SETTINGS.IA_DEPTH;
                switch (IA_SETTINGS.IA_HEURISTIC)
                {
                case 0: heuristic = HEURISTIC.control; break;

                case 1: heuristic = HEURISTIC.one; break;

                case 2: heuristic = HEURISTIC.oneDotTwo; break;

                case 3: heuristic = HEURISTIC.A; break;

                case 4: heuristic = HEURISTIC.AplusDiagHack; break;

                case 5: heuristic = HEURISTIC.Astar; break;

                default:
                    break;
                }
            }

            rules = new Pentago_Rules(heuristic,
                                      Pentago_Rules.NextStatesFunction.check_symmetries,
                                      game_mode == GAME_MODE.IAvsIA ? Pentago_Rules.IA_PIECES_WHITES : (
                                          game_mode == GAME_MODE.PlayerVsIA ? Pentago_Rules.IA_PIECES_BLACKS : Pentago_Rules.IA_PIECES_WHITES),
                                      true);

            ia = new MINMAX(MINMAX.VERSION.cut_alphabeta, rules, minmax_depth * 2);
            ia.setCUT(Pentago_Rules.MAX_HEURISTIC_VALUE, Pentago_Rules.MIN_HEURISTIC_VALUE);
            //iaThread = new AI_thread(ia);
        }

        if (game_mode == GAME_MODE.IAvsIA)
        {
            minmax_depth2 = IA_SETTINGS.IA_DEPTH_2;
            switch (IA_SETTINGS.IA_HEURISTIC_2)
            {
            case 0: heuristic2 = HEURISTIC.control; break;

            case 1: heuristic2 = HEURISTIC.one; break;

            case 2: heuristic2 = HEURISTIC.oneDotTwo; break;

            case 3: heuristic2 = HEURISTIC.A; break;

            case 4: heuristic2 = HEURISTIC.AplusDiagHack; break;

            case 5: heuristic2 = HEURISTIC.Astar; break;

            default:
                break;
            }

            rules2 = new Pentago_Rules(heuristic2,
                                       Pentago_Rules.NextStatesFunction.check_symmetries,
                                       Pentago_Rules.IA_PIECES_BLACKS,
                                       true);

            ia2 = new MINMAX(MINMAX.VERSION.cut_alphabeta, rules2, minmax_depth2 * 2);
            ia2.setCUT(Pentago_Rules.MAX_HEURISTIC_VALUE, Pentago_Rules.MIN_HEURISTIC_VALUE);
        }
    }
Exemplo n.º 3
0
    public static void play(int depth, Pentago_Rules.EvaluationFunction ef, Pentago_Rules.NextStatesFunction nsf, bool remove_duplicates, bool ia_pieces)
    {
        Pentago_GameBoard gb          = new Pentago_GameBoard();
        bool?         winning_player  = null;
        Pentago_Rules rules           = new Pentago_Rules(ef, nsf, ia_pieces, remove_duplicates);
        MINMAX        alpha_beta_test = new MINMAX(MINMAX.VERSION.alphabeta, rules, depth);
        Stopwatch     sw = new Stopwatch();

        while (!gb.game_ended(out winning_player))
        {
            gb.print_board();

            if (gb.get_player_turn() != ia_pieces)
            {
                Console.WriteLine("Your turn");
                if (gb.get_turn_state() == Pentago_GameBoard.turn_state_addpiece)
                {
                    Console.WriteLine("Place a piece: square,x,y     square E[0,3]      x,y E[0,2]");
                    int[] input;
                    try
                    {
                        input = Console.ReadLine().Split(',').Select <string, int>(o => Convert.ToInt32(o)).ToArray();
                        if (input.Length < 3)
                        {
                            continue;
                        }
                    }
                    catch { continue; }
                    Pentago_Move pm = new Pentago_Move(input[0], input[1], input[2]);
                    if (!pm.is_move_possible(gb))
                    {
                        continue;
                    }
                    pm.apply_move2board(gb);
                }
                else
                {
                    Console.WriteLine("Rotate a square: square,dir     square E[0,3]      dir E[0-anti,1-clock]");
                    int[] input;
                    try
                    {
                        input = Console.ReadLine().Split(',').Select <string, int>(o => Convert.ToInt32(o)).ToArray();
                        if (input.Length < 2)
                        {
                            continue;
                        }
                    }
                    catch { continue; }
                    Pentago_Move pm = new Pentago_Move(input[0], input[1] == 0 ? Pentago_Move.rotate_anticlockwise : Pentago_Move.rotate_clockwise);
                    if (!pm.is_move_possible(gb))
                    {
                        continue;
                    }
                    pm.apply_move2board(gb);
                }
            }
            else
            {
                Console.WriteLine("IA's turn");
                sw.Start();
                applyMoves(alpha_beta_test.run(gb), gb);
                sw.Stop();
                Console.WriteLine("Time={0}", sw.Elapsed);
            }
        }
        if (winning_player == null)
        {
            Console.WriteLine("\nGAME ENDED IN DRAW");
        }
        else if (winning_player != ia_pieces)
        {
            Console.WriteLine("\nGAME ENDED - YOU WON");
        }
        else
        {
            Console.WriteLine("\nGAME ENDED - IA WON");
        }
    }