示例#1
0
        static void CommandReader_commandRecieved(object sender, CommandReader.CommandEvent e)
        {
            //Extra command recieved function, commands are send to this
            //(just because I have to due to EventHandler instantiation ?)
            //And they are send to the GTP.CommandReader, which spawns them
            //off to the appropriate events (which I can subscribe too).

            Console.WriteLine("ENGINE <-- " + e.command);
        }
示例#2
0
        static void Main(string[] args)
        {
            ProcessWrapper gnuGoAI = new ProcessWrapper(
                @"C:\Users\quentin\Dropbox\Go AI\AIs\gnugo-3.8\gnugo.exe",
                "--mode gtp", new ProcessWrapper.lineReceived(lineRecieved));

            Controller.play("b", 5, 3, gnuGoAI);

            //int protocol_version = Controller.protocol_version(gnuGoAI);
            //string name = Controller.name(gnuGoAI);
            //string version = Controller.version(gnuGoAI);

            //bool knowPlay = Controller.known_command("play", gnuGoAI);
               // bool knowRandom = Controller.known_command("random", gnuGoAI);

            //string[] allCommands = Controller.list_commands(gnuGoAI);

            //Controller.boardsize(9, gnuGoAI);
            //Controller.clear_board(gnuGoAI);
            //Controller.komi(3.3f, gnuGoAI);
            Controller.play("b", 5, 3, gnuGoAI);
            //Ent_vertex vertex = Controller.genmove("b", gnuGoAI);

            Controller.quit(gnuGoAI);

            //gnuGoAI.sendLine("boardsize 9");

            //GTP.CommandReader reader = new GTP.CommandReader();

            //Setup the engine
            commandRecieved = new EventHandler<CommandReader.CommandEvent>(CommandReader_commandRecieved);
            CommandReader reader = new CommandReader(ref commandRecieved);

            reader.boardsize += new CommandReader.boardsize_delegate(reader_boardsize);

            //Talk to it using the controller code
            Controller.boardsize(8, SndRec);

            Console.Read();
        }
示例#3
0
        void CommandReader_commandRecieved(object sender, CommandReader.CommandEvent e)
        {
            string[] delimitter = { " " };
            string[] parts = e.command.Split(delimitter, StringSplitOptions.None);

            if (parts.Length <= 0)
                throw new Exception("Recieved an empty string, this is not a command");

            Ent_int id = null; //Null if no id was recieved

            int tempId;
            int pos = 0;

            if (Int32.TryParse(parts[0], out tempId))
            {
                id = new Ent_int(tempId);
                pos++;
            }

            string command_name = parts[pos++];
            string arguments = e.command.Substring(e.command.IndexOf(command_name) + command_name.Length);

            command_name = command_name.ToLower();

            //Call appropriate events
            try
            {
                e.response = "=";
                if (id != null)
                    e.response += id.data.ToString();

                e.response += " ";

                switch (command_name)
                {
                    //case "protocol_version":
                    //   e.response += protocol_version();
                    //    break;

                    case "protocol_version": e.response += protocol_version(); break;
                    case "name": e.response += name(); break;
                    case "version": e.response += version(); break;
                    case "known_command": e.response += known_command(arguments); break;
                    case "list_commands": e.response += list_commands(); break;
                    case "quit": quit(); break;
                    case "boardsize": boardsize(new Ent_int(arguments).data); break;
                    case "clear_board": clear_board(); break;
                    case "komi": komi(new Ent_float(arguments).data); break;
                    case "play": Ent_move move = new Ent_move(arguments); play(move.color.ToString(), move.vertex.xPos, move.vertex.yPos); break;
                    case "genmove": e.response += genmove(new Ent_color(arguments).ToString()); break;
                    case "undo": undo(); break;
                    case "showboard": e.response += showboard(); break;

                    case "fixed_handicap": List<Ent_vertex> fixedVertices = fixed_handicap(new Ent_int(arguments).data);
                        foreach (Ent_vertex vertex in fixedVertices)
                            e.response += " " + version.ToString();
                        break;

                    case "place_free_handicap": List<Ent_vertex> placeFreeVertices = place_free_handicap(new Ent_int(arguments).data);
                        foreach (Ent_vertex vertex in placeFreeVertices)
                            e.response += " " + version.ToString();
                        break;

                    case "set_free_handicap":
                        List<Ent_vertex> setFreeVertices = new List<Ent_vertex>();
                        while (pos < parts.Length)
                            setFreeVertices.Add(new Ent_vertex(parts[pos++]));
                        set_free_handicap(setFreeVertices);
                        break;

                    case "time_settings": time_settings(new Ent_int(parts[pos]).data, new Ent_int(parts[pos + 1]).data, new Ent_int(parts[pos + 2]).data); break;
                    case "time_left": time_left(new Ent_color(parts[pos]).ToString(), new Ent_int(parts[pos + 1]).data, new Ent_int(parts[pos + 2]).data); break;
                    case "final_score": e.response += final_score(); break;

                    case "final_status_list": List<Ent_vertex> finalStatusVertices = final_status_list(parts[pos]);
                        foreach (Ent_vertex vertex in finalStatusVertices)
                            e.response += " " + version.ToString(); break;
                }

                if (e.response.EndsWith(" "))
                    e.response = e.response.Substring(0, e.response.Length - 1);

                e.response += "\n\n";
            }
            catch (Exception error)
            {
                e.response = "? ";
                if (id != null)
                    e.response += id.data.ToString() + " ";

                //Sort of hackish, but it saves me time in adding a check to every case
                if (error.Message == "Object reference not set to an instance of an object.")
                    e.response += command_name + " command known, but not handled.";
                else
                    e.response += error.Message;

                e.response += "\n\n";
            }

            //fill in e.response
            //return [id] [response] \n\n
        }