public override Locomotion.MoveDirection GetNextMove(BoardInfo boardInfo, CellInfo currentPos, CellInfo[] goals) { //Si el archivo existe lo cargamos y cambiamos la variable loaded a true y mostramos el epsilon actual if (File.Exists(Application.dataPath + "/Scripts/Grupo/Solucion3/QLearningInfo" + seed + ".dat")) { if (!loaded) { load(); loaded = !loaded; Epsilontext.text = "Epsilon: " + Mathf.Round(aprender.getE() * 10000) / 10000; } } //Si no existe el archivo creamos el objeto y lo guardamos, cambiamos los buleanos necesarios a true y mostramos epsilon else { if (!initialized) { aprender = new QLearning(boardInfo, seed); initialized = true; loaded = !loaded; Epsilontext.text = "Epsilon: " + aprender.getE().ToString(); } } /* * invocamos el método nextStep del objeto creado aprender que nos devuelve el siguiente paso a realizar */ int next = aprender.nextStep(currentPos, boardInfo); if (next == 0) { //Si la posición a la que nos vamos a mover es la meta Guardamos todos los valores y recargamos la escena Vector2 pos = new Vector2(currentPos.GetPosition.x, currentPos.GetPosition.y + 1); if (pos == goals[0].GetPosition || aprender.maxIterations <= 0) { save(); reloadGame(); } //Reducimos el máximo de iteraciones aprender.maxIterations--; //activamos animaciones anim.SetFloat("velocityY", 1f); anim.SetFloat("velocityX", 0f); return(Locomotion.MoveDirection.Up); } else if (next == 1) { //Si la posición a la que nos vamos a mover es la meta Guardamos todos los valores y recargamos la escena Vector2 pos = new Vector2(currentPos.GetPosition.x, currentPos.GetPosition.y - 1); if (pos == goals[0].GetPosition || aprender.maxIterations <= 0) { save(); reloadGame(); } //Reducimos el máximo de iteraciones aprender.maxIterations--; //activamos animaciones anim.SetFloat("velocityY", -1f); anim.SetFloat("velocityX", 0f); return(Locomotion.MoveDirection.Down); } else if (next == 2) { //Si la posición a la que nos vamos a mover es la meta Guardamos todos los valores y recargamos la escena Vector2 pos = new Vector2(currentPos.GetPosition.x - 1, currentPos.GetPosition.y); if (pos == goals[0].GetPosition || aprender.maxIterations <= 0) { save(); reloadGame(); } //Reducimos el máximo de iteraciones aprender.maxIterations--; //activamos animaciones anim.SetFloat("velocityX", -1f); anim.SetFloat("velocityY", 0f); return(Locomotion.MoveDirection.Left); } else if (next == 3) { //Si la posición a la que nos vamos a mover es la meta Guardamos todos los valores y recargamos la escena Vector2 pos = new Vector2(currentPos.GetPosition.x + 1, currentPos.GetPosition.y); if (pos == goals[0].GetPosition || aprender.maxIterations <= 0) { save(); reloadGame(); } //Reducimos el máximo de iteraciones aprender.maxIterations--; //activamos animaciones anim.SetFloat("velocityX", 1f); anim.SetFloat("velocityY", 0f); return(Locomotion.MoveDirection.Right); } else { //Actualizamos las animaciones para que no haga nada anim.SetFloat("velocityX", 0f); anim.SetFloat("velocityY", 0f); return(Locomotion.MoveDirection.None); } }