当前位置: 首页>>代码示例>>C#>>正文


C# Cell.GetRowIndex方法代码示例

本文整理汇总了C#中Cell.GetRowIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.GetRowIndex方法的具体用法?C# Cell.GetRowIndex怎么用?C# Cell.GetRowIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cell的用法示例。


在下文中一共展示了Cell.GetRowIndex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBestDirection

        /// <summary>
        /// Gets the best direction to go from the Q-Table for a given cell
        /// </summary>
        /// <param name="cell">The originating cell</param>
        /// <returns>The best direction for the cell. If all directions have no Q-values > 0 then Direction.NONE will be returned</returns>
        public Direction GetBestDirection(Cell cell)
        {
            allowedDirections = new List<Direction>();
            Direction bestDirection = Direction.NONE;
            double maxQValue = 0;

            if (gridWorld.CanMove(Direction.UP, cell.GetRowIndex(), cell.GetColumnIndex()))
            {
                allowedDirections.Add(Direction.UP);

                if (GetQValue(cell, Direction.UP) > maxQValue)
                {
                    maxQValue = GetQValue(cell, Direction.UP);
                    bestDirection = Direction.UP;
                }
            }

            if (gridWorld.CanMove(Direction.DOWN, cell.GetRowIndex(), cell.GetColumnIndex()))
            {
                allowedDirections.Add(Direction.DOWN);

                if (GetQValue(cell, Direction.DOWN) > maxQValue)
                {
                    maxQValue = GetQValue(cell, Direction.DOWN);
                    bestDirection = Direction.DOWN;
                }
            }

            if (gridWorld.CanMove(Direction.LEFT, cell.GetRowIndex(), cell.GetColumnIndex()))
            {
                allowedDirections.Add(Direction.LEFT);

                if (GetQValue(cell, Direction.LEFT) > maxQValue)
                {
                    maxQValue = GetQValue(cell, Direction.LEFT);
                    bestDirection = Direction.LEFT;
                }
            }

            if (gridWorld.CanMove(Direction.RIGHT, cell.GetRowIndex(), cell.GetColumnIndex()))
            {
                allowedDirections.Add(Direction.RIGHT);

                if (GetQValue(cell, Direction.RIGHT) > maxQValue)
                {
                    maxQValue = GetQValue(cell, Direction.RIGHT);
                    bestDirection = Direction.RIGHT;
                }
            }

            // Get the direction with the highest QValue
            return bestDirection;
        }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:58,代码来源:QLearning.cs

示例2: GetHeuristicEstimate

 /// <summary>
 /// Calculates the Euclidean distance between two cells
 /// </summary>
 /// <param name="neighbor">The neighbor cell</param>
 /// <param name="reward">The reward cell</param>
 /// <returns>The Euclidean distance between the two cells</returns>
 public double GetHeuristicEstimate(Cell neighbor, Cell reward)
 {
     // Return the Euclidean distance
     return Math.Sqrt(Math.Pow(rewardCell.GetColumnIndex() - neighbor.GetColumnIndex(), 2) +
                      Math.Pow(rewardCell.GetRowIndex() - neighbor.GetRowIndex(), 2));
 }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:12,代码来源:AStar.cs

示例3: Run

        /// <summary>
        /// Runs a tick of the A* search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Run(object sender, EventArgs e)
        {
            System.Console.Out.WriteLine("Running A*; Step Count: " + stepCount++);

            while (true)
            {
                if (unvisitedCells.Count == 0)
                {
                    return;
                }

                currentCell = unvisitedCells.Last.Value;
                unvisitedCells.RemoveLast();

                if (currentCell.HasBeenSearched())
                {
                    continue;
                }

                break;
            }

            currentCell.SetHasBeenSearched(true);

            visitedCells.AddLast(currentCell);

            if (currentCell.IsRewardCell())
            {
                System.Console.Out.WriteLine("Found the reward");
                return;
            }

            // Check if cell is a neighbor of the currentCell
            // If so, set the cost and add to unvisitedCells in ProcessNeighbor()

            if (gridWorld.CanMove(Direction.UP, currentCell.GetRowIndex(), currentCell.GetColumnIndex()))
            {
                ProcessNeighbor(gridWorld.GetCells()[currentCell.GetRowIndex() - 1, currentCell.GetColumnIndex()]);
            }

            if (gridWorld.CanMove(Direction.DOWN, currentCell.GetRowIndex(), currentCell.GetColumnIndex()))
            {
                ProcessNeighbor(gridWorld.GetCells()[currentCell.GetRowIndex() + 1, currentCell.GetColumnIndex()]);
            }

            if (gridWorld.CanMove(Direction.LEFT, currentCell.GetRowIndex(), currentCell.GetColumnIndex()))
            {
                ProcessNeighbor(gridWorld.GetCells()[currentCell.GetRowIndex(), currentCell.GetColumnIndex() - 1]);
            }

            if (gridWorld.CanMove(Direction.RIGHT, currentCell.GetRowIndex(), currentCell.GetColumnIndex()))
            {
                ProcessNeighbor(gridWorld.GetCells()[currentCell.GetRowIndex(), currentCell.GetColumnIndex() + 1]);
            }
        }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:60,代码来源:AStar.cs

示例4: UpdateQValue

        /// <summary>
        /// Updates the Q-Value in the Q-Table for a given cell and direction
        /// </summary>
        /// <param name="cell">The originating cell</param>
        /// <param name="direction">The direction of travel</param>
        public void UpdateQValue(Cell cell, Direction direction)
        {
            double currentQValue = GetQValue(cell, direction);

            Cell nextCell = gridWorld.GetCell(cell, direction);

            double nextCellReward = Reward(nextCell);

            double maxEstimate = 0;
            if (GetBestDirection(nextCell) != Direction.NONE)
            {
                maxEstimate = GetQValue(nextCell, GetBestDirection(nextCell));
            }

            qTable[cell.GetRowIndex(), cell.GetColumnIndex(), (int)direction] = QLearningRule(currentQValue, ALPHA, nextCellReward, GAMMA, maxEstimate);
        }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:21,代码来源:QLearning.cs

示例5: Run

        /// <summary>
        /// Runs a tick of the Q-Learning search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Run(object sender, EventArgs e)
        {
            // TODO: Implement
            System.Console.Out.WriteLine("Running Q-Learning; Step Count: " + stepCount++);

            if (stepCount > MAX_SEARCH_STEPS)
            {
                RestartEpisode(null);
            }

            if (episodeCount > NUMBER_OF_EPISODES)
            {
                training = false;
            }

            // Check to see if we found the reward
            if (currentCell.IsRewardCell())
            {
                System.Console.Out.WriteLine("Found the reward");
                return;
            }

            Direction bestDirection = GetBestDirection(currentCell);

            // In this stochastic implementation, use the transition function to get the actual direction to move
            Direction actualDirection = Transition(currentCell, bestDirection);

            currentCell = gridWorld.GetCell(currentCell, actualDirection);
            currentCell.SetHasBeenSearched(true);

            if (training)
            {
                // Update the Q-Table with the current cell
                foreach (Direction direction in Enum.GetValues(typeof(Direction)))
                {
                    if (direction != Direction.NONE &&
                        gridWorld.CanMove(direction, currentCell.GetRowIndex(), currentCell.GetColumnIndex()))
                    {
                        UpdateQValue(currentCell, direction);
                    }
                }
            }
        }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:48,代码来源:QLearning.cs

示例6: GetSumQValue

 /// <summary>
 /// Convenience method to sum to the Q-Values for all directions for a given cell
 /// </summary>
 /// <param name="cell">The cell to sum the Q-Values</param>
 /// <returns>The sum of Q-Values</returns>
 public double GetSumQValue(Cell cell)
 {
     return qTable[cell.GetRowIndex(), cell.GetColumnIndex(), (int)Direction.UP] +
         qTable[cell.GetRowIndex(), cell.GetColumnIndex(), (int)Direction.DOWN] +
         qTable[cell.GetRowIndex(), cell.GetColumnIndex(), (int)Direction.LEFT] +
         qTable[cell.GetRowIndex(), cell.GetColumnIndex(), (int)Direction.RIGHT];
 }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:12,代码来源:QLearning.cs

示例7: GetQValue

 /// <summary>
 /// Gets the Q-Value in the Q-Table for a cell and a direction
 /// </summary>
 /// <param name="cell">The originating cell</param>
 /// <param name="direction">The direction of travel</param>
 /// <returns>The current Q-Value in the Q-Table</returns>
 public double GetQValue(Cell cell, Direction direction)
 {
     return qTable[cell.GetRowIndex(),cell.GetColumnIndex(),(int)direction];
 }
开发者ID:xiaorong1176,项目名称:agent-path-planning,代码行数:10,代码来源:QLearning.cs


注:本文中的Cell.GetRowIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。