public override double Calculate(AbstractState start, AbstractState goal)
        {
            if (!(start is MazeState) && !(goal is MazeState))
                throw new ArgumentException("Only MazeState allowed");

            var startMazeState = (MazeState)start;
            var goalMazeState = (MazeState)goal;

            double heuristic = Math.Pow(
                Math.Pow(startMazeState.ActiveCellXCoord - goalMazeState.ActiveCellXCoord, 2) +
                Math.Pow(startMazeState.ActiveCellXCoord - goalMazeState.ActiveCellXCoord, 2), 0.5);

            return heuristic;
        }
        public override double Calculate(AbstractState start, AbstractState goal)
        {
            if (!(start is TilesState) || !(goal is TilesState))
                throw new ArgumentException("Only TileStates are allowed");

            TilesState startState = (TilesState)start;
            TilesState goalState = (TilesState)goal;
            double heuristic = 0;

            for (int i = 0; i < TilesState.rows; i++)
            {
                for (int j = 0; j < TilesState.columns; j++)
                {
                    Tuple<int, int> indexesInGoal = getIndexes(startState.GetTiles()[i, j], goalState.GetTiles());
                    heuristic += Math.Abs(indexesInGoal.Item1 - i) + Math.Abs(indexesInGoal.Item2 - j);
                }
            }

            return heuristic;
        }
Пример #3
0
 public Node(AbstractState State)
 {
     this.Id = currentId++;
     this.State = State;
     this.Children = new List<Tuple<Node, AbstractAction>>();
 }
 public abstract Double Calculate(AbstractState start, AbstractState goal);