Esempio n. 1
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();
        }
Esempio n. 2
0
        /// <summary>
        /// Dynamically loads all ai which implement SimpleGoPlayer, that are in 
        /// C:\Users\QuentinBrooks\Dropbox\Go AI\AIs (put all release builds here)
        /// </summary>
        void CreateAI()
        {
            QuitAIs(goAis);

            goAis.Clear();

            string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
            if (Environment.OSVersion.Version.Major >= 6)
            {
                path = Directory.GetParent(path).ToString();
            }

            path += @"\Dropbox\Go AI\AIs\";

            ProcessWrapper gnuGoAI = new ProcessWrapper(
               path + @"gnugo-3.8\gnugo.exe",
               "--mode gtp", new ProcessWrapper.lineReceived(ReadOutput));

            ProcessWrapper amigo = new ProcessWrapper(
                path + @"amigogtp-1.7\amigogtp.exe",
                new ProcessWrapper.lineReceived(ReadOutput));

            ProcessWrapper pachi = new ProcessWrapper(
                path + @"pachi-5.00\pachi.exe",
                new ProcessWrapper.lineReceived(ReadOutput));

            //goAis.Add(new ProcessBasedPlayer(gnuGoAI)); //takes long turns
            //goAis.Add(new ProcessBasedPlayer(pachi)); //takes long turns
            goAis.Add((new ProcessBasedPlayer(amigo))); //fast turns (but really sucks)
            //goAis.Add(new TestDotNetGoPlayer());

            DynamicallyLoadAI();

            Controller.time_settings(1, 3, 5, pachi);
        }
Esempio n. 3
0
 public static string SendAndReceiveReponse(string command_name, ProcessWrapper proc)
 {
     return SendAndReceiveReponse(command_name, new List<Entity>(), proc);
 }
Esempio n. 4
0
 public ProcessBasedPlayer(ProcessWrapper _proc)
 {
     proc = _proc;
 }
Esempio n. 5
0
 //command_name OR, just the entire command (created from above or manually)
 public static void SendCommand(string command_name, ProcessWrapper proc)
 {
     proc.sendLine(command_name);
 }
Esempio n. 6
0
 public static void quit(ProcessWrapper proc)
 {
     proc.sendLine("quit");
     proc.readNextLine();
     proc.stopAllReadingAndQuit();
 }
Esempio n. 7
0
        public static void SendCommand(string command_name, List<Entity> entities, ProcessWrapper proc)
        {
            foreach (Entity entity in entities)
                command_name += " " + entity.ToString();

            SendCommand(command_name, proc);
        }
Esempio n. 8
0
 public static void SendCommand(int id, string command_name, ProcessWrapper proc)
 {
     SendCommand(id.ToString() + " " + command_name, proc);
 }
Esempio n. 9
0
 public static void SendCommand(int id, string command_name,
     List<Entity> entities, ProcessWrapper proc)
 {
     SendCommand(id.ToString() + " " + command_name, entities, proc);
 }
Esempio n. 10
0
        //One or both of id and response may be empty
        public static void GetNextReponse(out int id, out string response, ProcessWrapper proc)
        {
            //Starts with an equal sign, if it has a non \n, then thats id,
            //after that is either space then response, or \n\n.
            //After response is \n\n

            //=id response\n\n
            //=id\n\n
            //= response\n\n
            //=\n\n

            string curLine = proc.readNextLine().Trim();

            while (!curLine.Contains("=") && !curLine.Contains("?"))
                curLine = proc.readNextLine().Trim();

            while (curLine.Length == 0)
            {
                throw new Exception("Recieved empty line? This may be a problem?");
                curLine = proc.readNextLine().Trim();
            }

            if (curLine[0] == '?')
            {
                string error = "";
                error += curLine;
                while (curLine.Length != 0) //Go until we find \n\n (so an empty line)
                {
                    curLine = proc.readNextLine();
                    error += " " + curLine;
                }
                throw new Exception(error);
            }
            else if (curLine[0] != '=')
                throw new Exception("Error expected = or ? on all responses!");

            if (curLine == "=") //No id or response
            {
                curLine = proc.readNextLine(); //read next line still though as we are expecting
                //another line break

                id = -1; //Should be ignored anyway, this is NOT A SENTINEL
                response = null;

                return;
            }
            //else
            if (curLine[1] == ' ') //Just response, no id
            {
                id = -1; //Should be ignored anyway, this is NOT A SENTINEL
                curLine = curLine.Substring(1);
            }
            else
            {
                string[] delimitter = { " " };

                string[] parts = curLine.Split(delimitter, StringSplitOptions.RemoveEmptyEntries);

                id = Convert.ToInt32(parts[0].Substring(0));

                if (parts.Length <= 1) //No response
                {
                    response = null;
                }

                curLine = curLine.Substring(parts[0].Length + 1);
            }

            //There is a response at this point for sure
            response = "";
            do
            {
                string[] delimitter = { " " };

                string[] parts = curLine.Split(delimitter, StringSplitOptions.RemoveEmptyEntries);

                if (response.Length > 0) //Sort of a hack to keep the line stucture
                    response += "\n";

                foreach (string part in parts)
                    response += part + " ";

            } while ((curLine = proc.readNextLine()) != "");
        }
Esempio n. 11
0
        public static string SendAndReceiveReponse(string command_name, List<Entity> entities, ProcessWrapper proc)
        {
            proc.clearOutAllLines();

            //If we use an id we can insure we get the correct response,
            //if we are not getting the correct response we should add this

            if (entities.Count == 0)
                SendCommand(command_name, proc);
            else
                SendCommand(command_name, entities, proc);

            int id;
            string response;

            GetNextReponse(out id, out response, proc);

            return response;
        }