public MovementIntent Act(PacManGameState gs, int playerNumber) { int[,] grid; Grid g = MakeMapDiscrete(gs); var movementActionValues = (MovementIntent[])Enum.GetValues(typeof(MovementIntent)); PacManGameState gsCopy = new PacManGameState(gs); if (gsCopy.GetGumStatus()) { //Heuristique recompense quand il est au plus pres de la gum ball return((MovementIntent)movementActionValues.GetValue(1)); } else { //Si on est le joueur 1 if (playerNumber == 1) { //Heuristique recompence quand il est pres du joeur if (gs.GetP1Status()) { return((MovementIntent)movementActionValues.GetValue(1)); } //Heuristique recompence quand il est loin du joueur else { return((MovementIntent)movementActionValues.GetValue(1)); } } else { if (gs.GetP2Status()) { return((MovementIntent)movementActionValues.GetValue(1)); } else { return((MovementIntent)movementActionValues.GetValue(1)); } } } }
// 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 } }