private void LearnerTester(string input, string output, string rewards) { Learner learner = new Learner(); bool firstRun = true; // talk for (int i = 0; i < input.Length; i++) { if (firstRun) { firstRun = false; } else { learner.RegisterReward(rewards.Substring(i, 1)); } // reply string reply = learner.Answer(input.Substring(i, 1)); Assert.AreEqual(output.Substring(i, 1), reply, "Unexpected answer in step " + (i + 1)); } }
static void Main() { using (var client = new PairSocket()) { client.Connect("tcp://127.0.0.1:5556"); client.SendFrame("hello"); bool firstRun = true; // talk while (true) { // receive reward string reward = client.ReceiveFrameString(); if (reward == "-1") { reward = "-"; } else if (reward == "1") { reward = "+"; } else { reward = " "; } if (firstRun) { reward = string.Empty; firstRun = false; } else { if (!Interactive) { Learner.RegisterReward(reward); } } // receive teacher/env char string teacherChar = client.ReceiveFrameString(); Display.ShowStep(reward, teacherChar); // reply string reply; if (Interactive) { var key = Console.ReadKey(); reply = key.KeyChar.ToString(); } else { reply = Learner.Answer(teacherChar); } Display.ShowReply(reply); client.SendFrame(reply); } } }