Ejemplo n.º 1
0
        private double MaxValue(TGameState state, OpertorsMethodType operatorFunc, double currentCost)
        {
            if (_cuffOFFunc(state))
            {
                return(_Eval(state) - currentCost);
            }

            double max = double.MinValue;

            foreach (var action in operatorFunc(state))
            {
                var        res      = action(state);
                TGameState newState = res.State;
                double     newCost  = currentCost;
                if (_cooperative)
                {
                    newCost += res.Cost;
                }
                else
                {
                    if (operatorFunc == _Operators1)
                    {
                        newCost += res.Cost;
                    }
                }
                max = Math.Max(max, MaxValue(newState, switchOperators(operatorFunc), newCost));
            }

            return(max);
        }
Ejemplo n.º 2
0
 public ActionType Run(TGameState initialState, OpertorsMethodType OpertorsFunc1, OpertorsMethodType OpertorsFunc2,
                       GoalMethodType cuttFunc, HuristicMethodType evalFunc)
 {
     _cuffOFFunc = cuttFunc;
     _Operators1 = OpertorsFunc1;
     _Operators2 = OpertorsFunc2;
     _Eval       = evalFunc;
     return(Run(initialState));
 }
Ejemplo n.º 3
0
 private OpertorsMethodType switchOperators(OpertorsMethodType operatorFunc)
 {
     if (operatorFunc == _Operators1)
     {
         return(_Operators2);
     }
     if (operatorFunc == _Operators2)
     {
         return(_Operators1);
     }
     throw new Exception("operators can't be not one of two players");
 }
        public override SearchPath Run(TSeachState initialState, OpertorsMethodType releventOpertorsFunc, GoalMethodType goalFunc, HuristicMethodType huristicFunc)
        {
            var path = base.Run(initialState, releventOpertorsFunc, goalFunc, huristicFunc);

            if (path == null)
            {
                var res = openSet.DequeueItem();
                return(reconstruct_path(res));
            }
            else
            {
                return(path);
            }
        }
Ejemplo n.º 5
0
        public override SearchPath Run(TSearchState initialState, OpertorsMethodType releventOpertorsFunc,
                                       GoalMethodType goalFunc, HuristicMethodType huristicFunc)
        {
            init(initialState);
            while (!openSet.IsEmpty && !toStop())
            {
                var current = openSet.DequeueItem();
                if (goalFunc(current))
                {
                    return(reconstruct_path(current));
                }

                closedSet.Add(current);
                ++Expansations;
                var operators = releventOpertorsFunc(current);
                if (operators == null)
                {
                    operators = new ActionsCollection();
                }
                foreach (var opertor in operators)
                {
                    var neighboorStateAndCost = opertor(current);
                    var neighboor             = neighboorStateAndCost.State;

                    //if the state exists at the closedSet it means  that is have a better f already
                    // so no need to calculate the huristic
                    if (closedSet.Contains(neighboor))
                    {
                        continue;
                    }

                    double gValue = neighboorStateAndCost.Cost + g[current];
                    double fValue = gValue + huristicFunc(neighboor);
                    SearchStateAndAction stateAndAction = new SearchStateAndAction()
                    {
                        state = current, action = opertor
                    };
                    HandleDuplicatesInOpenSet(neighboor, gValue, fValue, stateAndAction);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
 public abstract SearchPath Run(TSearchState initialState, OpertorsMethodType releventOpertorsFunc,
                                GoalMethodType goalFunc, HuristicMethodType huristicFunc);