static void testSimonInteractionStateEquals() { SimonInteractionState state1 = new SimonInteractionState(); SimonInteractionState state2 = new SimonInteractionState(); state1.setTagTouchState("tag1", Touch.touched); Console.WriteLine(state1.Equals(state2)); Console.WriteLine(state2.Equals(state1)); state2.setTagTouchState("tag1", Touch.touched); Console.WriteLine(state1.Equals(state2)); Console.WriteLine(state2.Equals(state1)); state2.setTagTouchState("tag1", Touch.untouched); Console.WriteLine(state1.Equals(state2)); Console.WriteLine(state2.Equals(state1)); state1.setTagTouchState("tag2", Touch.touched); state1.setTagTouchState("tag1", Touch.untouched); state2.setTagTouchState("tag2", Touch.touched); Console.WriteLine(state1.Equals(state2)); Console.WriteLine(state2.Equals(state1)); while (true) { } }
private void requestNewState() { // Select some number of the tags. HashSet <string> desiredTags = new HashSet <string>(); desiredTags.Add(this.tagIds[random.Next(this.tagIds.Count)]); foreach (string tag in this.tagIds) { if (random.Next(2) == 0) { desiredTags.Add(tag); } } // For each selected tag, ask the user to do something to the tag, // touch or move, but must be consistent with the current state of the tag. // Our new desired state will start as the last observed state and then we will make modifications. this.desiredState = (ObjectCopier.Clone <SimonInteractionState>(this.lastObservedState)); string instructions = "Simon says:\n"; foreach (string tag in desiredTags) { instructions += "\t" + this.requestNewTagAction(tag) + "\n"; } Console.WriteLine(instructions + " desired state: " + this.desiredState.ToString()); }
public override void afterInitialize() { base.afterInitialize(); this.lastMostLikelyState = new SimonInteractionState(); this.lastMostLikelyState.initialize(this.tagIds); this.lastObservedState = new SimonInteractionState(); this.lastObservedState.initialize(this.tagIds); this.requestNewState(); }
public override void afterUpdate() { // Check the most likely state. this.mostLikelyState = (SimonInteractionState)this.interaction.getMostLikelyStateIfProbable(this.snapThreshold); if (this.mostLikelyState == null) { return; } /* * // Update the state of the GUI to reflect which tags were touched. * List<string> desiredTouchedTags = this.desiredState.getTouchedTags(); * bool error = false; * foreach (string touchedTag in this.mostLikelyState.getTouchedTags()) * { * if (desiredTouchedTags.Contains(touchedTag)) { * Console.WriteLine("Yay!"); * this.form.markTagCorrect(touchedTag); * } * else * { * Console.WriteLine("Mistake..."); * this.form.markTagMistake(touchedTag); * error = true; * } * } * if (error) * { * // They lose, and it automatically starts again. * Console.WriteLine("You lose!"); * this.requestTagTouch(); * } */ // Check if we are in a new state, and then check if player followed Simon's instructions correctly. // Console.WriteLine("most likely state exists " + this.mostLikelyState); // Console.WriteLine(this.mostLikelyState); if (!this.mostLikelyState.Equals(this.lastObservedState)) { Console.WriteLine("noticed state change to " + this.mostLikelyState); this.lastObservedState = ObjectCopier.Clone <SimonInteractionState>(this.mostLikelyState); if (this.mostLikelyState.Equals(this.desiredState)) { // Player is correct. Console.WriteLine("Well done! Score "); } else { // Player is incorrect. Console.WriteLine("Incorrect. Simon is disappointed."); } this.requestNewState(); } }
static void simonTest() { // Create the app. SimonApplication <SimonInteractionState, SimonInteraction <SimonInteractionState> > app = new SimonApplication <SimonInteractionState, SimonInteraction <SimonInteractionState> >(); // Create the initial histogram. ConcurrentDictionary <SimonInteractionState, double> initialHistogram = new ConcurrentDictionary <SimonInteractionState, double>(); // Create an initial state, with no touches. SimonInteractionState initialState = new SimonInteractionState(); initialHistogram.AddOrUpdate(initialState, 1.0, (key, oldValue) => 1.0); // For now, we have just one tag, and we have only touch and velocity. int numTags = SolutionConstants.tagIds.Count; int numModalities = SolutionConstants.numModalities; // Initialize app. app.initialize(numTags, numModalities, initialHistogram, false); // Run app. app.run(); // Spin. while (true) { } }
// Need to override Equals method. public override bool Equals(Object obj) { // Check for null values and compare runtime types. if (obj == null || this.GetType() != obj.GetType()) { return(false); } SimonInteractionState state = (SimonInteractionState)obj; // Compare hashes. if (!(this.GetHashCode() == state.GetHashCode())) { return(false); } // Compare touchDict. if (this.touchDict.Count != state.touchDict.Count) { return(false); } foreach (var pair in this.touchDict) { if (!state.touchDict.ContainsKey(pair.Key)) { return(false); } if (!state.touchDict[pair.Key].Equals(pair.Value)) { return(false); } } foreach (string tag in state.touchDict.Keys) { if (!this.touchDict.ContainsKey(tag)) { return(false); } } // Compare motionDict. if (this.motionDict.Count != state.motionDict.Count) { return(false); } foreach (var pair in this.motionDict) { if (!state.motionDict.ContainsKey(pair.Key)) { return(false); } if (!state.motionDict[pair.Key].Equals(pair.Value)) { return(false); } } foreach (string tag in state.motionDict.Keys) { if (!this.motionDict.ContainsKey(tag)) { return(false); } } return(true); }