Exemple #1
0
    // Initialisation des agents, du runner et du GameState
    public void InitializeGame(int agent1, int agent2)
    {
        switch (agent1)
        {
        case 0:
            PlayerOne.GetComponent <HumanPlayerScript>().ControlType = 0;
            agentP1 = new HumanPlayerAgent(PlayerOne.GetComponent <HumanPlayerScript>());
            break;

        case 1:
            PlayerOne.GetComponent <HumanPlayerScript>().ControlType = 1;
            agentP1 = new HumanPlayerAgent(PlayerOne.GetComponent <HumanPlayerScript>());
            break;

        case 2:
            agentP1 = new RandomAgent();
            break;

        case 3:
            agentP1 = new RandomRolloutAgent(RandomRNbIteration, x, z);
            break;
        }
        switch (agent2)
        {
        case 0:
            PlayerTwo.GetComponent <HumanPlayerScript>().ControlType = 0;
            agentP2 = new HumanPlayerAgent(PlayerTwo.GetComponent <HumanPlayerScript>());
            break;

        case 1:
            PlayerTwo.GetComponent <HumanPlayerScript>().ControlType = 1;
            agentP2 = new HumanPlayerAgent(PlayerTwo.GetComponent <HumanPlayerScript>());
            break;

        case 2:
            agentP2 = new RandomAgent();
            break;

        case 3:
            agentP2 = new RandomRolloutAgent(RandomRNbIteration, x, z);
            break;
        }
        gs     = new PacManGameState(x, z, PlayerOne.transform.position, PlayerTwo.transform.position, Obstacles, Doors);
        runner = new PacManRunner(agentP1, agentP2, gs, speed);
        InGame = true;
        GumBall.transform.position = gs.GetGumVector();
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            InGame = !InGame;
        }
        if (!InGame)
        {
            return;
        }
        //Run a frame in the runner
        bool[] frameResult = runner.RunFrame();
        gs = runner.GetState();
        PlayerOne.transform.position = gs.GetP1Vector();
        PlayerTwo.transform.position = gs.GetP2Vector();
        // Test des booléen
        if (gs.GetGumStatus() == false)
        {
            Timetokill -= Time.deltaTime;
            if (gs.GetP1Status() && GumBall.activeInHierarchy)
            {
                GumBall.SetActive(false);
                Timetokill = TimeKiller;
                gs.SetPositionGumball(-100, -100, -100);
                GumBall.transform.position = gs.GetGumVector();
                PlayerOne.GetComponent <Renderer>().material = MatKiller;
            }
            else if (gs.GetP2Status() && GumBall.activeInHierarchy)
            {
                GumBall.SetActive(false);
                Timetokill = TimeKiller;
                gs.SetPositionGumball(-100, -100, -100);
                GumBall.transform.position = gs.GetGumVector();
                PlayerTwo.GetComponent <Renderer>().material = MatKiller;
            }
        }
        else
        {
            PlayerOne.GetComponent <Renderer>().material = MatOne;
            PlayerTwo.GetComponent <Renderer>().material = MatTwo;
        }

        if (gs.getP1Winner())
        {
            InGame = false;
            WinOne.SetActive(true);
            LoseTwo.SetActive(true);
            EndMenu.SetActive(true);
        }
        else if (gs.getP2Winner())
        {
            InGame = false;
            WinTwo.SetActive(true);
            LoseOne.SetActive(true);
            EndMenu.SetActive(true);
        }
        if (Timetokill <= 0)
        {
            Timetokill = 0.1f;
            gs.SetBoolP1(false);
            gs.SetBoolP2(false);
            gs.RandomizeGumball();
            GumBall.transform.position = gs.GetGumVector();
            gs.SetGumStatus(true);
            GumBall.SetActive(true);
        }
        if (frameResult[2])//if state is terminal
        {
            InGame = false;
            //TODO Affichage du joueur/agent gagnant et perdant
        }
    }