public void Bake(IHasState<ISharlotkaState> sharlotka)
 {
     _bakeCount++;
     if (_bakeCount >= 5) {
         sharlotka.State = _successor;
     }
 }
Beispiel #2
0
 public void Store(IHasState x, IHasState y, bool value)
 {
     if (this.cache.ContainsKey(x) == false)
         this.cache[x] = new Dictionary<IHasState, bool>(
             CompareByReference.Instance);
     this.cache[x].Add(y, value);
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new population from an existing one and an additional member
 /// </summary>
 public EventPopulation(EventPopulation source, IHasState newMember)
     : this(source.members.Capacity)
 {
     this.members.AddRange(source.members);
     foreach (IHasState member in source.membersHashed)
         this.membersHashed.Add(member);
     this.Add(newMember);
 }
 public PlaceStationsState(IHasState state, Map map) : base(state, map)
 {
     Map.StationTiles.ForEach(p =>
     {
         p.CanHighlight  = true;
         p.IsValidTarget = true;
     });
 }
 public PlaceMineState(IHasState gameLogic, Map map) : base(gameLogic, map)
 {
     Map.CenterTiles.ForEach(p => p.CanHighlight = true);
     Map.CenterTiles.Where(p => p.IsMountain)
     .SelectMany(p => Map.GetAdjacentTiles(p))
     .OfType <CenterTile>()
     .Where(p => !p.IsMountain)
     .ForEach(p => p.IsValidTarget = true);
 }
Beispiel #6
0
 /// <summary>
 /// Returns all SmartObjects such that the subject has the
 /// given relations towards them
 /// </summary>
 public static IEnumerable<IHasState> ByRelationFrom(
     IHasState subject,
     IEnumerable<IHasState> candidates,
     IList<RelationName> tags)
 {
     foreach (IHasState candidate in candidates)
         if (subject.State.Require(candidate.State.Id, tags) == true)
             yield return candidate;
     yield break;
 }
Beispiel #7
0
 public bool? Get(IHasState x, IHasState y)
 {
     Dictionary<IHasState, bool> result;
     if (this.cache.TryGetValue(x, out result) == false)
         return null;
     bool value;
     if (result.TryGetValue(y, out value) == false)
         return null;
     return value;
 }
Beispiel #8
0
	// Use this for initialization
	void Start() 
    {
        foreach (EventSignature sig in EventLibrary.Instance.GetSignatures())
            Debug.Log(sig.ToString());

        EventSignature sig2 = EventLibrary.Instance.GetSignaturesOfType(typeof(DummyEvent2)).First();
        EventSignature sig3 = EventLibrary.Instance.GetSignaturesOfType(typeof(DummyEvent3)).First();

        obj1.State.Set(new[] { StateName.RoleActor, StateName.IsStanding, StateName.HoldingBall });
        obj2.State.Set(new[] { StateName.RoleChair, StateName.IsOccupied });

        IHasState[] allObjs = new IHasState[] { obj1, obj2 };

        // Should fail because param 0 needs to be a float
        Debug.Log("sig2.Check(new object[] { obj1, obj1, obj2 }, true), should fail because of parameters...");
        Debug.Log(sig2.CheckTypes(new IHasState[] { obj1, obj1, obj2 }));
        Debug.Log(sig2.CheckRequirements(new IHasState[] { obj1, obj1, obj2 }, allObjs));

        Debug.Log("sig2.Check(new object[] { 0.1f, obj1, obj2 }, true), should fail because of state...");
        Debug.Log(sig2.CheckTypes(new IHasState[] { obj1, obj2 }));
        Debug.Log(sig2.CheckRequirements(new IHasState[] { obj1, obj1, obj2 }, allObjs));

        obj2.State.Set(new[] { ~StateName.IsOccupied });

        Debug.Log("sig2.Check(new object[] { 0.1f, obj1, obj2 }, true), should succeed now...");
        Debug.Log(sig2.CheckTypes(new IHasState[] { obj1, obj2 }));
        Debug.Log(sig2.CheckRequirements(new IHasState[] { obj1, obj1, obj2 }, allObjs));

        Debug.Log("sig3.Check(new object[] { 0.1f, obj1, obj2 }, true), should fail because of relation...");
        Debug.Log(sig3.CheckTypes(new IHasState[] { obj1, obj2 }));
        Debug.Log(sig2.CheckRequirements(new IHasState[] { obj1, obj1, obj2 }, allObjs));

        obj1.State.Set(obj2.Id, new[] { RelationName.IsFriendOf });

        Debug.Log("sig3.Check(new object[] { 0.1f, obj1, obj2 }, true), should succeed now...");
        Debug.Log(sig3.CheckTypes(new IHasState[] { obj1, obj2 }));
        Debug.Log(sig2.CheckRequirements(new IHasState[] { obj1, obj1, obj2 }, allObjs));
	}
Beispiel #9
0
    public static bool IsRuleSatisfied(
        IEnumerable<IHasState> scope,
        RuleName rule,
        IHasState X,
        IHasState Y)
    {
        int checksum = GetScopeCheckSum(scope);
        if (DEBUG_scopeChecksum.HasValue == true)
            if (checksum != DEBUG_scopeChecksum.Value)
                Debug.LogError("Scope checksum mismatch with cached checksum");
        DEBUG_scopeChecksum = checksum;

        bool? cached = CheckCache(rule, X, Y);
        if (cached.HasValue == true)
            return cached.Value;

        bool evaluated = EvaluateRule(scope, rule, X, Y);
        StoreCache(rule, X, Y, evaluated);
        return evaluated;
    }
 public void Serve(IHasState<ISharlotkaState> sharlotka)
 {
     throw new WrongStateException();
 }
Beispiel #11
0
 protected GameState(IHasState state, Map map)
 {
     State = state;
     Map   = map;
 }
Beispiel #12
0
 /// <summary>
 /// Inspects passed entity for state methods matching supplied Enum, and returns a stateMachine instance used to trasition states.
 /// </summary>
 public static IState Create <T>(IHasState entity, State <T> state, T startState) where T : struct, IConvertible, IComparable
 {
     state = (State <T>)Create(entity, state);
     state.ChangeState(startState);
     return(state);
 }
Beispiel #13
0
 /// <summary>
 /// Adds an object to the population if the object does not already
 /// exist in the population
 /// </summary>
 /// <param name="obj"></param>
 public void Add(IHasState obj)
 {
     this.isDirty = true;
     this.members.Add(obj);
     this.membersHashed.Add(obj);
 }
Beispiel #14
0
 /// <summary>
 /// Creates a new population with an initial member
 /// </summary>
 /// <param name="capacity"></param>
 /// <param name="firstMember"></param>
 public EventPopulation(int capacity, IHasState firstMember)
     : this(capacity)
 {
     this.Add(firstMember);
 }
Beispiel #15
0
    private static bool CheckContains(
        EventDescriptor evtDesc,
        EventPopulation currentPop,
        IHasState newMember)
    {
        IList<IHasState> currentMembers = currentPop.Members;
        int newIndex = currentMembers.Count;

        for (int i = 0; i < currentMembers.Count; i++)
        {
            IHasState currentMember = currentMembers[i];
            if (evtDesc.CanEqual(i, newIndex) == false)
                if (object.ReferenceEquals(currentMember, newMember) == true)
                    return true;
        }

        return false;
    }
 public void SetUp()
 {
     _sharlotka = MockRepository.GenerateStub<IHasState<ISharlotkaState>>();
     _state = new ReadyToServeState();
 }
 public void AddApples(IHasState<ISharlotkaState> sharlotka)
 {
     sharlotka.State = _successor;
 }
 public void AddBatter(IHasState<ISharlotkaState> sharlotka)
 {
     sharlotka.State = _successor;
 }
Beispiel #19
0
 private static bool? CheckCache(RuleName name, IHasState x, IHasState y)
 {
     RuleCache cache;
     if (cacheRules == null)
         return null;
     if (cacheRules.TryGetValue(name, out cache) == false)
         return null;
     return cache.Get(x, y);
 }
Beispiel #20
0
 private static bool EvaluateRule(
     IEnumerable<IHasState> scope,
     RuleName rule,
     IHasState X,
     IHasState Y)
 {
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         return true;
     return false;
 }
 public bool GetIsReady(IHasState<ISharlotkaState> sharlotka)
 {
     return false;
 }
 public void SetUp()
 {
     _sharlotka = MockRepository.GenerateStub<IHasState<ISharlotkaState>>();
     _successor = MockRepository.GenerateStub<ISharlotkaState>();
     _state = new ReadyToAddBatterState(_successor);
 }
 public void DustWithSugar(IHasState<ISharlotkaState> sharlotka)
 {
     throw new WrongStateException();
 }
Beispiel #24
0
 private static void StoreCache(
     RuleName rule,
     IHasState x,
     IHasState y,
     bool value)
 {
     if (cacheRules == null)
         cacheRules = new Dictionary<RuleName, RuleCache>();
     if (cacheRules.ContainsKey(rule) == false)
         cacheRules[rule] = new RuleCache();
     cacheRules[rule].Store(x, y, value);
 }
 public void Serve(IHasState<ISharlotkaState> sharlotka)
 {
 }
Beispiel #26
0
 /// <summary>
 /// Returns true iff this population contains an object
 /// </summary>
 public bool Contains(IHasState obj)
 {
     return this.membersHashed.Contains(obj);
 }
 public void AddApples(IHasState<ISharlotkaState> sharlotka)
 {
     throw new WrongStateException();
 }
Beispiel #28
0
 /// <summary>
 /// Inspects passed entity for state methods matching supplied Enum, and returns a stateMachine instance used to trasition states.
 /// </summary>
 public static IState Create <T>(IHasState entity, State <T> state) where T : struct, IConvertible, IComparable
 {
     entity.State?.Cleanup();
     entity.State = state;
     return(state);
 }
Beispiel #29
0
 private static IEnumerable<IHasState> GetLHSSatisfiers(
     IEnumerable<IHasState> scope,
     RuleName rule,
     IHasState Y)
 {
     Variable X = new Variable();
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         yield return X.GetValue<IHasState>();
 }
 public bool GetIsReady(IHasState<ISharlotkaState> sharlotka)
 {
     throw new WrongStateException();
 }
Beispiel #31
0
    /// <summary>
    /// Checks to see if an IHasState meets a slot's state requirements
    /// </summary>
    public bool CheckStateRequirements(
        int index,
        IHasState obj,
        IEnumerable<StateName> filter = null)
    {
        IList<StateName> requirements = this.StateRequirements[index];
        DebugUtil.Assert(
            requirements != null,
            "Requirements on slot " + index + " of " + this.Name);

        // Filter by the given states if we have any
        if (filter != null)
            requirements = Filter.StateList(requirements, filter);

        return obj.State.Require(requirements);
    }
 public void TurnOut(IHasState<ISharlotkaState> sharlotka)
 {
     throw new WrongStateException();
 }
 public void SetUp()
 {
     _sharlotka = MockRepository.GenerateStub<IHasState<ISharlotkaState>>();
     _successor = MockRepository.GenerateStub<ISharlotkaState>();
     _state = new ReadyToDustWithCinnamonState(_successor);
 }
 public void DustWithCinnamon(IHasState<ISharlotkaState> sharlotka)
 {
     sharlotka.State = _successor;
 }
 public void DustWithSugar(IHasState<ISharlotkaState> sharlotka)
 {
     sharlotka.State = _successor;
 }