Esempio n. 1
0
        private Reply HandleCommand <Reply, Command>(Command tohandle, CoreCommand.IManager manager)
        {
            MemoryStream inp = new MemoryStream();
            MemoryStream oup = new MemoryStream();

            Serializer.Serialize(tohandle, inp);
            inp.Position = 0;
            if (!manager.CallCommand(manager.GetCommandName(typeof(Command)), inp, oup))
            {
                oup.Position = 0;
                throw new Exception(BinarySerializer.Serializer.Deserialize <String>(oup));
            }
            oup.Position = 0;
            BinarySerializer.Serializer.Deserialize <Command>(oup);
            return(BinarySerializer.Serializer.Deserialize <Reply>(oup));
        }
Esempio n. 2
0
        private void MoreOrLessExecuter(CoreCommand.IManager manager, UInt32 funcID)
        {
            int mystery_number = 47;

            int i = 0;

            CoreCommand.Command.Function.Call command = new CoreCommand.Command.Function.Call
            {
                FuncId     = funcID,
                Parameters = new Dictionary <string, string>
                {
                    { "lastResult", "2" }
                }
            };
            CoreCommand.Command.Function.Call.Reply reply;
            int given;

            do
            {
                reply = HandleCommand <CoreCommand.Command.Function.Call.Reply, CoreCommand.Command.Function.Call>(command, manager);

                given = Int32.Parse(reply.Returns["result"]);

                Console.WriteLine("IA said: " + given.ToString());

                if (given > mystery_number)
                {
                    command.Parameters["lastResult"] = "1"; //less
                    Console.WriteLine("==> It's Less");
                }
                else if (given < mystery_number)
                {
                    command.Parameters["lastResult"] = "0"; //more
                    Console.WriteLine("==> It's More");
                }
                ++i;
            } while (given != mystery_number && i < 10);

            Assert.IsTrue(given == mystery_number);

            Console.WriteLine("AI found the mystery number " + mystery_number + " in " + i + " hits");
        }