public override Locomotion.MoveDirection GetNextMove(BoardInfo boardInfo, CellInfo currentPos, CellInfo[] goals) { if (!startedLearn) { if (File.Exists("qtable.csv") && !forgetPreviousLearning) { qtable = QTable.LoadFromCsv("qtable.csv", boardInfo); episode = numberOfEpisodes; } else { StartCoroutine(Learn(boardInfo)); } startedLearn = true; } if (episode == numberOfEpisodes) { // Proxima celda aleatoria Locomotion.MoveDirection nextDirection = (Locomotion.MoveDirection)qtable.GetHighestQDirection(currentPos); return(nextDirection); } return(Locomotion.MoveDirection.None); }
/// <summary> /// Calcula la posición dentro de la tabla para un estado y una acción /// </summary> /// <param name="state">Estado</param> /// <param name="action">Acción</param> /// <returns>Indice dentro de la tabla Q</returns> private int GetArrayPosition(CellInfo state, Locomotion.MoveDirection action) { int row = state.RowId * this.boardColumns + state.ColumnId; int column = (int)action; return(row * numActions + column); }
/// <summary> /// Acceso mediante estado (CellInfo) y acción (MoveDirection) /// </summary> /// <param name="state">Estado</param> /// <param name="action">Acción</param> public float this[CellInfo state, Locomotion.MoveDirection action] { get { return(table[GetArrayPosition(state, action)]); } set { table[GetArrayPosition(state, action)] = value; } }
/// <summary> /// Node constructor. /// </summary> /// <param name="father">Father of the Node.</param> /// <param name="cell">Information of this Node.</param> /// <param name="goals">Objectives of this Node.</param> public Node(Node father, CellInfo cell, CellInfo[] goals) { this.id = numberNodes; this.cell = cell; this.Father = father; this.movement = GetDirection(); this.totalWalkCost = CalculateWalkCost(); this.distance = CalculateDistance(goals); if (this.Father == null) { this.horizon = 1; } else { this.horizon = this.Father.horizon + 1; } numberNodes++; }
public Nodo(CellInfo _estado, Nodo _padre, Locomotion.MoveDirection _direction, float cost) { estado = _estado; nodoPadre = _padre; direction = _direction; }
public Node(Node parent, CellData cell, Locomotion.MoveDirection action) { this.parent = parent; this.cell = cell; this.actionNeeded = action; }