public void CleanUp() { thisPercept = Percepts.None; //sgeTemp.Clear(); stTemp.Clear(); //htTemp.Clear(); ntTemp.Clear(); ocTemp.Clear(); }
public void Execute() { while (isAlive == LiveStatus.IsAlive && puzzle != null && IsPuzzleSolved() == false) { thisPercept = GetPerceptForRound(); switch (thisPercept) { case Percepts.None: Console.WriteLine("No strategy can be executed this round."); Debug.WriteLine("No strategy can be exceuted this round."); break; case Percepts.AreOnlyChoice: onlyChoiceStrategy.AlgorithmInterface(ocTemp); Console.WriteLine("Only Choice Strategy executed this round"); Debug.WriteLine("Only Choice Strategy executed this round."); break; case Percepts.AreSinglePossibilities: singlePossibilityStrategy.AlgorithmInterface(stTemp); break; case Percepts.SubgroupExclusion: subgroupExclusionStrategy.AlgorithmInterface(sgeTemp); Console.WriteLine("Subgroup Exclusion executed this round"); Debug.WriteLine("Subgroup Exclusion executed this round."); break; case Percepts.FindingNakedTwin: nakedTwinExclusionStrategy.AlgorithmInterface(ntTemp); //stuck on infinite loop here. THe issue appears to be that a list of twins are returned BUT none of the twin's neighbors have twin values as possibilities Console.WriteLine("Naked Twin Strategy executed this round"); Debug.WriteLine("Naked Twin Strategy executed this round."); break; //case Percepts.FindingHiddenTwin: // hiddenTwinExclusionStrategy.AlgorithmInterface(htTemp); // Console.WriteLine("Hidden Twin Strategy executed this round"); // Debug.WriteLine("Hidden Twin Strategy executed this round."); // break; default: break; } if (IsPuzzleSolved()) //execute this if statement at the end of the while loop { isAlive = LiveStatus.IsDead; //Draw Board? Console.WriteLine("The puzzle is solved."); CleanUp(); } } }
public void PerceiveCurrentPosition(Percepts percepts) { PerceptedPlaces[CurrentPosition] = percepts; KnowledgeOfPlaces[CurrentPosition] = new Knowledge(); if (percepts.Glitter) { FoundGold = true; } var newPlacesToGo = PossibleMoves().Where(pos => !PerceptedPlaces.ContainsKey(pos)); foreach (var position in newPlacesToGo) { var hasKnowledge = KnowledgeOfPlaces.ContainsKey(position); if (hasKnowledge) { var knowledge = KnowledgeOfPlaces[position]; if (!percepts.Stench && knowledge.MightHaveWumpus) { knowledge.MightHaveWumpus = false; } if (!percepts.Breeze && knowledge.MightHavePit) { knowledge.MightHavePit = false; } } else { KnowledgeOfPlaces[position] = new Knowledge { MightHaveWumpus = percepts.Stench, MightHavePit = percepts.Breeze }; } } }
/// <summary> /// the function called when a perception event is received /// </summary> void Perceived(Hashtable param) { if (!param.ContainsKey("OBJECT")) { return; } GameObject perceivedObject = (GameObject)(param ["OBJECT"]); Percept percept; if (Percepts.TryGetValue(perceivedObject.GetInstanceID(), out percept)) { Percepts [perceivedObject.GetInstanceID()].Entity = perceivedObject; } else { IPerceivable perceivable = perceivedObject.GetComponent <IPerceivable> (); if (perceivable != null) { Percepts.Add(perceivedObject.GetInstanceID(), new Percept(perceivedObject, 0)); } } }
void Update() { // cleanup missing entity due to being destroyed var perceptKeys = Percepts.Keys.ToArray(); bool alerted = false; for (int i = 0; i < perceptKeys.Length; i++) { GameObject entity = Percepts [perceptKeys [i]].Entity; if (entity == null) { Percepts.Remove(perceptKeys [i]); } else { // keeps track whether this perception component should be alerted or not if ((Vector3.Distance(entity.transform.position, this.transform.position) <= Range) && ((entity.GetComponent <IPerceivable> ().Tag & AlertMask) != 0)) { alerted = true; } } } //invoke alert and unalerted accordingly if (alerted && (OnAlerted != null) && !Alerted) { Alerted = alerted; OnAlerted.Invoke(); } else if (!alerted && (OnUnalerted != null) && Alerted) { Alerted = alerted; OnUnalerted.Invoke(); } }