コード例 #1
0
ファイル: RivalsEval.cs プロジェクト: limonana/AI_Course
        public double Run(TravelGameState state)
        {
            int a     = 10;
            int b     = 5;
            int c     = 2;
            int d     = 1;
            var world = state.ToWorld();

            bool   real;
            double distanceFromGoal = GetDistanceFromGoal(world, state.locations[_player], _player.Goal.Value, out real);

            if (!real)
            {
                a -= 2;
            }

            double avoidPenality = (_totalMoves - state.totalMoves[_player]) - distanceFromGoal;
            int    rivalDistance = 0;
            double rivalPenality = 0;

            if (_rival.Goal != null)
            {
                bool realRivalDest;
                rivalDistance = GetDistanceFromGoal(world, state.locations[_rival], _rival.Goal.Value, out realRivalDest);
                if (!realRivalDest)
                {
                    b += 2;
                }
                rivalPenality = (_totalMoves - state.totalMoves[_rival]) - rivalDistance;
            }


            return(-a * distanceFromGoal + b * rivalDistance + c * avoidPenality - d * rivalPenality);
        }
コード例 #2
0
        private IEnumerable <ActionType> getFireActions(TravelGameState state, TravelWorld world)
        {
            List <ActionType> res = new List <ActionType>();
            var ways = world.GetClearWays(state.locations[this]);

            foreach (var way in ways)
            {
                int dest   = way.getAnotherPlace(state.locations[this]);
                var action = new ActionType(w => startAfire(w, dest));
                res.Add(action);
            }
            return(res);
        }
コード例 #3
0
        protected virtual TravelGameState ToState(TravelWorld newWorld)
        {
            var newState = new TravelGameState();

            newState.CarryWatter     = CarryWater;
            newState.locations       = new Dictionary <BaseTraveler, int>(newWorld.GetPlayersLocations());
            newState.locations[this] = CurrentLocation;
            newState.totalMoves      = new Dictionary <BaseTraveler, int>();
            foreach (var item in newState.locations.Keys)
            {
                newState.totalMoves.Add(item, 0);
            }
            newState.WaterPlaces = new List <int>(newWorld.GetWaterPlaces());
            newState.FireWays    = new List <TravelEdge>(newWorld.GetFireWays());
            newState.WorldGraph  = newWorld.GetGraph();
            return(newState);
        }
コード例 #4
0
        public virtual StateActionsCollection getActions(TravelGameState state)
        {
            //TODO:edit
            //only pickup water and drive
            TravelWorld            world = state.ToWorld();
            StateActionsCollection res   = new StateActionsCollection();

            if (CanPickupWaterNow(state, world))
            {
                if (!_actionsMap.ContainsKey(PickupWater))
                {
                    ActionType      action      = pickupWater;
                    StateActionType stateAction = PickupWater;
                    _actionsMap.Add(stateAction, action);
                }
                res.Add(PickupWater);
            }

            var actions = getDriveActions(state, world);

            foreach (var action in actions)
            {
                var stateAction = ConvertToStateAction(action);
                _actionsMap.Add(stateAction, action);
                res.Add(stateAction);
            }

            actions = getFireActions(state, world);
            foreach (var action in actions)
            {
                var stateAction = ConvertToStateAction(action);
                _actionsMap.Add(stateAction, action);
                res.Add(stateAction);
            }

            //last because is last prefable
            if (!_actionsMap.ContainsKey(noOperation))
            {
                ActionType      action      = noOpertion;
                StateActionType stateAction = noOperation;
                _actionsMap.Add(stateAction, action);
            }
            res.Add(noOperation);
            return(res);
        }
コード例 #5
0
        private StateAndCost rollBackAction(TravelGameState state, ActionType action)
        {
            backup();
            CurrentLocation = state.locations[this];
            CarryWater      = state.CarryWatter;
            var  newWorld = state.ToWorld();
            bool sucseed  = action(newWorld);

            if (!sucseed)
            {
                throw new WrongActionException();
            }
            var neweState = ToState(newWorld);

            neweState.totalMoves        = new Dictionary <BaseTraveler, int>(state.totalMoves);
            neweState.totalMoves[this] += 1;
            double cost = _cost - _prevCost;

            rollBack();
            return(new StateAndCost(neweState, cost));
        }
コード例 #6
0
        protected IEnumerable <ActionType> getDriveActions(TravelGameState state, TravelWorld world)
        {
            List <ActionType>        res = new List <ActionType>();
            IEnumerable <TravelEdge> ways;

            if (state.CarryWatter)
            {
                ways = world.GetWays(state.locations[this]);
            }
            else
            {
                ways = world.GetClearWays(state.locations[this]);
            }

            foreach (var way in ways)
            {
                int dest   = way.getAnotherPlace(state.locations[this]);
                var action = new ActionType(w => drive(w, dest));
                res.Add(action);
            }
            return(res);
        }
コード例 #7
0
 public bool Run(TravelGameState state)
 {
     return
         ((state.totalMoves[_player1] >= _depth && state.totalMoves[_player2] >= _depth) ||
          (state.locations[_player1] == _player1.Goal.Value && state.locations[_player2] == _player2.Goal.Value));
 }
コード例 #8
0
 protected bool CanPickupWaterNow(TravelGameState state, TravelWorld world)
 {
     return(!state.CarryWatter && world.HaveWater(state.locations[this]));
 }
コード例 #9
0
 protected StateAndCost noOperation(TravelGameState state)
 {
     return(rollBackAction(state, noOpertion));
 }
コード例 #10
0
 protected StateAndCost PickupWater(TravelGameState state)
 {
     return(rollBackAction(state, pickupWater));
 }