Exemplo n.º 1
0
        public void ProcessLine(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }

            string lLine = line.TrimEnd('\n').TrimEnd('\r');

            if (Verbose)
            {
                Console.Error.WriteLine("STATUS: W< " + lLine);
            }

            string[] lCmds = lLine.Split('\t');

            if (lCmds.Length < 2)
            {
                Server.SendLine("?\t");
                return;
            }

            if (lCmds[0] == "disconnect")
            {
                Server.Disconnect();
                return;
            }

            if (lCmds[0] == "terminate")
            {
                Server.Terminate = true;
                Server.Disconnect();
                return;
            }

            List <string> lParameters = new List <string>();

            for (int lIndex = 2; lIndex < lCmds.Length; lIndex++)
            {
                lParameters.Add(lCmds[lIndex]);
            }

            WorkerFunctions.Execute(lCmds[1], lCmds[0], lParameters, Board, SearchEngine, Server.SendLine);
        }
Exemplo n.º 2
0
 public void Disconnect()
 {
     lock (this)
     {
         Console.Error.WriteLine("STATUS: Disconnecting Connection");
         State   = ConnectionState.Disconnecting;
         NagNode = null;
         NagCoordinator.Disconnected(this);
         Worker.Disconnect(true);
     }
 }
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;
            }
        }