Example #1
0
        static void coinTest()
        {
            // Create new app
            CoinApplication <CoinInteractionState, CoinInteraction <CoinInteractionState> > app = new CoinApplication <CoinInteractionState, CoinInteraction <CoinInteractionState> > ();

            // Create an initial histogram (distribution).
            ConcurrentDictionary <CoinInteractionState, double> initialHistogram = new ConcurrentDictionary <CoinInteractionState, double>();
            // Create an initial state, with number of heads set to 0.
            CoinInteractionState initialState = new CoinInteractionState();

            // Set the distribution to have only one state, with probability 1.
            initialHistogram.AddOrUpdate(initialState, 1.0, (key, oldValue) => 1.0);

            // Initialize app with the initial histogram.
            // Pass true for shouldGraph so that we get the realtime graphing.
            app.initialize(SolutionConstants.tagIds.Count, SolutionConstants.numModalities, initialHistogram, false);

            // Run the application.
            app.run();

            // Wait endlessly for user to exit, so that console output doesn't disappear.
            while (true)
            {
            }
        }
Example #2
0
        /*****************
        *  Note that we don't need to implement initialize since we'll just use
        *  the base class' implementation.
        *****************/

        private void setDesiredStateToTouched()
        {
            // Randomly select which tag we want to be touched next.
            // In this simple application, there is only one tag.
            this.desiredState = new CoinInteractionState();
            this.desiredState.setHeads(0.0);
            Console.WriteLine("Simon says: Touch the tag!");
        }
Example #3
0
        // Need to override Equals method.
        public override bool Equals(Object obj)
        {
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            CoinInteractionState state = (CoinInteractionState)obj;

            return(this.heads == state.heads);
        }
Example #4
0
 public override void afterUpdate()
 {
     // Report the status of the tag (covered/uncovered) if we are more than 95% sure.
     this.mostLikelyState = (CoinInteractionState)this.interaction.getMostLikelyStateIfProbable(.95);
     if (this.mostLikelyState == null)
     {
         return;
     }
     if (this.mostLikelyState.Equals(this.desiredState))
     {
         Console.WriteLine("Good job!");
         if (this.desiredState.getHeads() == 1.0)
         {
             this.setDesiredStateToTouched();
         }
         else
         {
             this.setDesiredStateToUntouched();
         }
     }
     this.interaction.displayHistogram();
 }
Example #5
0
 private void setDesiredStateToUntouched()
 {
     this.desiredState = new CoinInteractionState();
     this.desiredState.setHeads(1.0);
     Console.WriteLine("Simon says: Don't touch the tag!");
 }