public void RemoveStates(StatesCollection removingStates)
 {
     for (int i = 0; i < removingStates.states.Count; i++)
     {
         states.Remove(removingStates.states[i]);
     }
 }
 public void AddStates(StatesCollection addingStates)
 {
     for (int i = 0; i < addingStates.states.Count; i++)
     {
         if (!states.Contains(addingStates.states[i]))
         {
             states.Add(addingStates.states[i]);
         }
     }
 }
 public void AddState(StrategyState state)
 {
     try
     {
         StatesCollection.DeleteMany(FilterDefinition <StrategyState> .Empty);
         StatesCollection.InsertOne(state);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
    public int CompareStates(StatesCollection comparingState)
    {
        int difference = 0;

        for (int c = 0; c < comparingState.states.Count; c++)
        {
            if (!states.Contains(comparingState.states[c]))
            {
                difference++;
            }
        }

        return(difference);
    }
        /// <summary>
        /// Initializes a new instance of the ReliableUdpConnectionControlBlock
        /// with specified size of transmission packet
        /// </summary>
        /// <exception cref="System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. </exception>
        public ReliableUdpConnectionControlBlock()
        {
            IncomingStreams  = new ConcurrentDictionary <Tuple <EndPoint, Int32>, byte[]>();
            OutcomingStreams = new ConcurrentDictionary <Tuple <EndPoint, Int32>, byte[]>();


            m_listOfHandlers = new ConcurrentDictionary <Tuple <EndPoint, Int32>, ReliableUdpConnectionRecord>();
            m_subscribers    = new List <ReliableUdpSubscribeObject>();

            States = new StatesCollection();

            m_randomCrypto = new RNGCryptoServiceProvider();

            this.m_socketIn = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.m_socketIn.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        }
 public StrategyState LastState()
 {
     try
     {
         var restored = StatesCollection
                        .AsQueryable()
                        .OrderByDescending(it => it.Time)
                        .FirstOrDefault();
         if (restored == null)
         {
             return(new StrategyState());
         }
         restored.RestoresAmount++;
         return(restored);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(new StrategyState());
     }
 }
 public StatesCollection(StatesCollection copyStates)
 {
     states = new List <string>(copyStates.states);
 }
        /// <summary>
        /// Initializes a new instance of the ReliableUdpConnectionControlBlock 
        /// with specified size of transmission packet
        /// </summary>
        /// <exception cref="System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. </exception>
        public ReliableUdpConnectionControlBlock()
        {
            IncomingStreams = new ConcurrentDictionary<Tuple<EndPoint, Int32>, byte[]>();
              OutcomingStreams = new ConcurrentDictionary<Tuple<EndPoint, Int32>, byte[]>();

              m_listOfHandlers = new ConcurrentDictionary<Tuple<EndPoint, Int32>, ReliableUdpConnectionRecord>();
              m_subscribers = new List<ReliableUdpSubscribeObject>();

              States = new StatesCollection();

              m_randomCrypto = new RNGCryptoServiceProvider();

              this.m_socketIn = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
              this.m_socketIn.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        }
Exemple #9
0
    public void Plan()
    {
        currentAction = null;
        currentPlan.Clear();

        Stack <StatesCollection> simWorldState = new Stack <StatesCollection>();
        Stack <ActionGoap>       simActions    = new Stack <ActionGoap>();
        Stack <int> simDepths = new Stack <int>();

        ActionGoap[] simPlan = new ActionGoap[planDepth];

        int minDepth = int.MaxValue;

        simWorldState.Push(new StatesCollection(worldState));
        simDepths.Push(0);
        simActions.Push(null);

        while (simWorldState.Count != 0)
        {
            StatesCollection cSimState = simWorldState.Pop();
            int        cDepth          = simDepths.Pop();
            ActionGoap cSimActions     = simActions.Pop();

            simPlan[cDepth] = cSimActions;

            if (cDepth > minDepth) // Bigger than previous plan thus inefficient
            {
                continue;
            }

            if (cSimState.CompareStates(goals[selectedGoal].desiredStates) == 0 || cDepth >= planDepth)
            {
                if (cDepth < minDepth)
                {
                    minDepth = cDepth;
                    currentPlan.Clear();
                    for (int i = 0; i < simPlan.Length; i++)
                    {
                        if (simPlan[i] != null)
                        {
                            currentPlan.Enqueue(simPlan[i]);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    if (cSimState.CompareStates(actions[i].requiredStates) == 0 && cSimState.CompareStates(actions[i].outcomeStates) > 0) // has to be possible and has to cause something
                    {
                        StatesCollection newState = new StatesCollection(cSimState);
                        newState.AddStates(actions[i].outcomeStates);
                        simWorldState.Push(newState);
                        simActions.Push(actions[i]);
                        simDepths.Push(cDepth + 1);
                    }
                }
            }
        }
    }