private void Run() { SensoryInformation si; bool shuffle = true; for (int b = 0; b < numBlocks; b++) { Console.Write("Starting block # " + (b + 1)); if (shuffle) { Console.WriteLine("... Shuffling pegs."); for (int i = 0; i < 5; i++) { corelations[i] = rand.Next(5); while (corelations[i] == i) { corelations[i] = rand.Next(5); } Console.WriteLine("Starting Peg " + (i + 1) + " --> Target Peg " + (corelations[i] + 1)); } } else { Console.WriteLine(); } int progress = 0; for (int i = 0; i < numTrials; i++) { si = World.NewSensoryInformation(John); int peg = 0; switch (rand.Next(5)) { case 0: si.Add(p1, 1); si.Add(p2, 0); si.Add(p3, 0); si.Add(p4, 0); si.Add(p5, 0); peg = 1; break; case 1: si.Add(p1, 0); si.Add(p2, 1); si.Add(p3, 0); si.Add(p4, 0); si.Add(p5, 0); peg = 2; break; case 2: si.Add(p1, 0); si.Add(p2, 0); si.Add(p3, 1); si.Add(p4, 0); si.Add(p5, 0); peg = 3; break; case 3: si.Add(p1, 0); si.Add(p2, 0); si.Add(p3, 0); si.Add(p4, 1); si.Add(p5, 0); peg = 4; break; case 4: si.Add(p1, 0); si.Add(p2, 0); si.Add(p3, 0); si.Add(p4, 0); si.Add(p5, 1); peg = 5; break; } Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "For block " + (b + 1) + ", trial # " + (i + 1) + ": The starting peg is " + peg + ", the target peg is " + (corelations[peg - 1] + 1)); John.Perceive(si); ExternalActionChunk chosen = John.GetChosenExternalAction(si); if (corelations[peg - 1] + 1 == (int)chosen.First().Value.AsIComparable) { Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was correct"); John.ReceiveFeedback(si, 1); numCorrect++; } else { Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was incorrect"); John.ReceiveFeedback(si, 0); } progress = (int)(((double)(i + 1) / (double)numTrials) * 100); Console.CursorLeft = 0; Console.Write(progress + "% Complete.."); } Console.WriteLine(); Console.WriteLine("Block " + (b + 1) + " is finished. Let's see how John did..."); Console.WriteLine("John's performance on block " + (b + 1) + ": " + Math.Round(((double)numCorrect / (double)numTrials) * 100) + "%"); Console.WriteLine("Rules John learned:"); foreach (var r in John.GetInternals(Agent.InternalContainers.ACTION_RULES)) { Console.WriteLine(r); } Console.Write("For the next block, would you like to shuffle the pegs to see if John can adjust (y = yes, n = no, x = exit)?"); char ans = Console.ReadKey().KeyChar; Console.WriteLine(); if (ans == 'y') { shuffle = true; } else if (ans == 'n') { shuffle = false; } else if (ans == 'x') { break; } numCorrect = 0; } //Kill the agent to end the task Console.WriteLine("Killing John to end the program"); John.Die(); Console.WriteLine("John is Dead"); Console.WriteLine("The Simple Tower of Hanoi Task has finished"); Console.Write("Press any key to exit"); Console.ReadKey(true); }