Exemplo n.º 1
0
 public GTPCommCGOS(string server, int portNbr, string userName, string password, int gamesToPlay, bool verbose)
 {
     Server          = new TCPConnection(server, portNbr, 15, 100, null, verbose);
     UserName        = userName;
     Password        = password;
     Verbose         = verbose;
     SupportTimeLeft = false;
     GamesToPlay     = gamesToPlay;
     WaitingForGame  = false;
     CGOSServer      = CGOSServerVersion.E0;
 }
Exemplo n.º 2
0
 public GTPCommCGOS(string server, int portNbr, string userName, string password, int gamesToPlay, bool verbose)
 {
     Server = new TCPConnection(server, portNbr, 15, 100, null, verbose);
     UserName = userName;
     Password = password;
     Verbose = verbose;
     SupportTimeLeft = false;
     GamesToPlay = gamesToPlay;
     WaitingForGame = false;
     CGOSServer = CGOSServerVersion.E0;
 }
Exemplo n.º 3
0
        public void ProcessLine(string line)
        {
            if (string.IsNullOrEmpty(line))
                return;

            string[] lCmds = line.TrimEnd('\n').TrimEnd('\r').Replace("\r", "").Split(' ');

            //if (Verbose)
            //	Console.Error.WriteLine("STATUS: C< " + lLine.ToString().Replace("\r", ""));

            switch (lCmds[0])
            {
                case "username":
                    {
                        Server.SendLine(UserName);
                        break;
                    }
                case "password":
                    {
                        Server.SendLine(Password);
                        break;
                    }
                case "protocol":
                    {
                        Server.SendLine("e1");
                        CGOSServer = CGOSServerVersion.E1;
                        break;
                    }
                case "successfully":
                    {
                        Server.SendLine("ping");
                        WaitingForGame = true;
                        break;
                    }
                case "you":	// You are already logged on!  Closing connection.
                    {
                        Server.Disconnect();
                        break;
                    }
                case "Error:":	// You are already logged on!  Closing connection.
                    {
                        Server.Disconnect();
                        break;
                    }
                case "setup": // for newer version of CGOS
                    {
                        WaitingForGame = false;

                        SendToEngine("boardsize " + lCmds[2] + "\n");
                        SendToEngine("clear_board\n");
                        SendToEngine("komi " + lCmds[3] + "\n");

                        if (SupportTimeLeft)
                        {
                            double lTimeLeft = 1000;

                            if (Double.TryParse(lCmds[4], out lTimeLeft))
                            {
                                SendToEngine("time_left b " + (lTimeLeft / 1000) + " 0 0\n");
                                SendToEngine("time_left w " + (lTimeLeft / 1000) + " 0 0\n");
                            }
                        }

                        int lArg = 0;

                        while ((lArg * 2) + 7 < lCmds.Length)
                        {
                            SendToEngine("play " + (lArg % 2 == 0 ? "b" : "w") + " " + lCmds[lArg * 2 + 7] + "\n");

                            lArg++;
                        }

                        FlushResponses();
                        break;
                    }
                case "newgame": // for older version of CGOS
                    {
                        WaitingForGame = false;

                        SendToEngine("boardsize " + lCmds[1] + "\n");
                        SendToEngine("clear_board\n");
                        SendToEngine("komi " + lCmds[2] + "\n");
                        if (SupportTimeLeft)
                        {
                            double lTimeLeft = 1000;

                            if (Double.TryParse(lCmds[3], out lTimeLeft))
                            {
                                SendToEngine("time_left b " + lTimeLeft + " 0 0\n");
                                SendToEngine("time_left w " + lTimeLeft + " 0 0\n");
                            }
                        }

                        FlushResponses();
                        break;
                    }
                case "play":
                    {
                        if (SupportTimeLeft)
                        {
                            double lTimeLeft = 1000;

                            if (Double.TryParse(lCmds[3], out lTimeLeft))
                                SendToEngine("time_left " + lCmds[1] + " " + (lTimeLeft / 1000) + " 0 0\n");

                            FlushResponses();
                        }

                        SendToEngine("play " + lCmds[1] + " " + lCmds[2] + "\n");
                        FlushResponses();
                        break;
                    }
                case "genmove":
                    {
                        FlushResponses();

                        if (SupportTimeLeft)
                        {
                            double lTimeLeft = 1000;

                            if (Double.TryParse(lCmds[2], out lTimeLeft))
                                SendToEngine("time_left " + lCmds[1] + " " + (lTimeLeft / 1000) + " 0 0\n");

                            FlushResponses();
                        }

                        SendToEngine("genmove " + lCmds[1] + "\n");

                        string lResponse = GetResponse();
                        Server.SendLine(lResponse.Replace('=', ' ').Trim());

                        break;
                    }
                case "gameover":
                    {
                        // todo: tell GTP engine...

                        WaitingForGame = true;
                        if (GamesToPlay <= 1)
                        {
                            Server.SendLine("");
                            Server.Terminate = true;
                            break;
                        }

                        if (CGOSServer == CGOSServerVersion.E0)
                            Server.SendLine("ok");
                        else
                            Server.SendLine("ready");

                        if (GamesToPlay > 0)
                            GamesToPlay--;

                        SendToEngine("boardsize " + lCmds[1] + "\n");
                        SendToEngine("clear_board\n");

                        SendToEngine("gotraxx-just_think\n");

                        FlushResponses();

                        if (Verbose)
                            Console.Error.WriteLine("STATUS: Games Left: " + GamesToPlay.ToString());

                        break;
                    }
                case "info":
                    {
                        break;
                    }
                case "time_left":
                    {
                        if (SupportTimeLeft)
                        {
                            SendToEngine("time_left " + lCmds[1] + " " + lCmds[2] + " 0\n");
                            FlushResponses();
                        }
                        break;
                    }
                default:
                    break;
            }
        }
Exemplo n.º 4
0
        public void ProcessLine(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }

            string[] lCmds = line.TrimEnd('\n').TrimEnd('\r').Replace("\r", "").Split(' ');

            //if (Verbose)
            //	Console.Error.WriteLine("STATUS: C< " + lLine.ToString().Replace("\r", ""));

            switch (lCmds[0])
            {
            case "username":
            {
                Server.SendLine(UserName);
                break;
            }

            case "password":
            {
                Server.SendLine(Password);
                break;
            }

            case "protocol":
            {
                Server.SendLine("e1");
                CGOSServer = CGOSServerVersion.E1;
                break;
            }

            case "successfully":
            {
                Server.SendLine("ping");
                WaitingForGame = true;
                break;
            }

            case "you":                         // You are already logged on!  Closing connection.
            {
                Server.Disconnect();
                break;
            }

            case "Error:":                      // You are already logged on!  Closing connection.
            {
                Server.Disconnect();
                break;
            }

            case "setup":                     // for newer version of CGOS
            {
                WaitingForGame = false;

                SendToEngine("boardsize " + lCmds[2] + "\n");
                SendToEngine("clear_board\n");
                SendToEngine("komi " + lCmds[3] + "\n");

                if (SupportTimeLeft)
                {
                    double lTimeLeft = 1000;

                    if (Double.TryParse(lCmds[4], out lTimeLeft))
                    {
                        SendToEngine("time_left b " + (lTimeLeft / 1000) + " 0 0\n");
                        SendToEngine("time_left w " + (lTimeLeft / 1000) + " 0 0\n");
                    }
                }

                int lArg = 0;

                while ((lArg * 2) + 7 < lCmds.Length)
                {
                    SendToEngine("play " + (lArg % 2 == 0 ? "b" : "w") + " " + lCmds[lArg * 2 + 7] + "\n");

                    lArg++;
                }

                FlushResponses();
                break;
            }

            case "newgame":                     // for older version of CGOS
            {
                WaitingForGame = false;

                SendToEngine("boardsize " + lCmds[1] + "\n");
                SendToEngine("clear_board\n");
                SendToEngine("komi " + lCmds[2] + "\n");
                if (SupportTimeLeft)
                {
                    double lTimeLeft = 1000;

                    if (Double.TryParse(lCmds[3], out lTimeLeft))
                    {
                        SendToEngine("time_left b " + lTimeLeft + " 0 0\n");
                        SendToEngine("time_left w " + lTimeLeft + " 0 0\n");
                    }
                }

                FlushResponses();
                break;
            }

            case "play":
            {
                if (SupportTimeLeft)
                {
                    double lTimeLeft = 1000;

                    if (Double.TryParse(lCmds[3], out lTimeLeft))
                    {
                        SendToEngine("time_left " + lCmds[1] + " " + (lTimeLeft / 1000) + " 0 0\n");
                    }

                    FlushResponses();
                }

                SendToEngine("play " + lCmds[1] + " " + lCmds[2] + "\n");
                FlushResponses();
                break;
            }

            case "genmove":
            {
                FlushResponses();

                if (SupportTimeLeft)
                {
                    double lTimeLeft = 1000;

                    if (Double.TryParse(lCmds[2], out lTimeLeft))
                    {
                        SendToEngine("time_left " + lCmds[1] + " " + (lTimeLeft / 1000) + " 0 0\n");
                    }

                    FlushResponses();
                }

                SendToEngine("genmove " + lCmds[1] + "\n");

                string lResponse = GetResponse();
                Server.SendLine(lResponse.Replace('=', ' ').Trim());

                break;
            }

            case "gameover":
            {
                // todo: tell GTP engine...

                WaitingForGame = true;
                if (GamesToPlay <= 1)
                {
                    Server.SendLine("");
                    Server.Terminate = true;
                    break;
                }

                if (CGOSServer == CGOSServerVersion.E0)
                {
                    Server.SendLine("ok");
                }
                else
                {
                    Server.SendLine("ready");
                }

                if (GamesToPlay > 0)
                {
                    GamesToPlay--;
                }

                SendToEngine("boardsize " + lCmds[1] + "\n");
                SendToEngine("clear_board\n");

                SendToEngine("gotraxx-just_think\n");

                FlushResponses();

                if (Verbose)
                {
                    Console.Error.WriteLine("STATUS: Games Left: " + GamesToPlay.ToString());
                }

                break;
            }

            case "info":
            {
                break;
            }

            case "time_left":
            {
                if (SupportTimeLeft)
                {
                    SendToEngine("time_left " + lCmds[1] + " " + lCmds[2] + " 0\n");
                    FlushResponses();
                }
                break;
            }

            default:
                break;
            }
        }