Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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;
            }
        }
Beispiel #4
0
        /// <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++;
        }
Beispiel #5
0
 public Nodo(CellInfo _estado, Nodo _padre, Locomotion.MoveDirection _direction, float cost)
 {
     estado    = _estado;
     nodoPadre = _padre;
     direction = _direction;
 }
Beispiel #6
0
 public Node(Node parent, CellData cell, Locomotion.MoveDirection action)
 {
     this.parent       = parent;
     this.cell         = cell;
     this.actionNeeded = action;
 }