Ejemplo n.º 1
0
 private void Reset()
 {
     if (MessageBox.Show("This will attempt to restart GNU Go and resume " +
                         "the game. Do you want to proceed?",
                         "Reset",
                         MessageBoxButtons.YesNo,
                         MessageBoxIcon.Question,
                         MessageBoxDefaultButton.Button1) == DialogResult.Yes)
     {
         timer.Enabled = false;
         playing       = false;
         if ((gnugoColor == GnuGoColor.Black && blackToPlay ||
              gnugoColor == GnuGoColor.White && !blackToPlay) &&
             Game.MoveNumber > 0)
         {
             ApplyUndo(1);
             blackToPlay = !blackToPlay;
         }
         System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
         try
         {
             SGFWriter.SaveGame(Game, GNUGoFile);
             gtp = reset(GNUGoFile);
             Init();
         }
         catch (GnuGoException)
         {
             MessageBox.Show("Unable to restart GNU Go",
                             "Error",
                             MessageBoxButtons.OK,
                             MessageBoxIcon.Exclamation,
                             MessageBoxDefaultButton.Button1);
             CloseGTP();
             UpdateStatus();
             RemoveSGF();
         }
         catch (Exception e)
         {
             MessageBox.Show("Error while restarting GNU Go: " + e.Message,
                             "Error",
                             MessageBoxButtons.OK,
                             MessageBoxIcon.Exclamation,
                             MessageBoxDefaultButton.Button1);
             CloseGTP();
             UpdateStatus();
             RemoveSGF();
         }
         System.Windows.Forms.Cursor.Current = Cursors.Default;
     }
 }
Ejemplo n.º 2
0
        public GnuGoView(Size size, GoGame game, GameRenderer renderer,
                         GTP gtp, GnuGoColor gnugoColor, GTPReset reset) :
            base(size, game, renderer)
        {
            this.gtp        = gtp;
            this.reset      = reset;
            this.gnugoColor = gnugoColor;
            blackToPlay     = true;

            AllowCursor     = true;
            AllowNavigation = false;

            timer = new Timer()
            {
                Interval = 50,
            };
            timer.Tick += (s, e) => this.gtp.Update();

            Close += (s, e) => CloseGTP();

            statusLabel = new Label()
            {
                Dock = DockStyle.Bottom,
            };

            using (var graphics = CreateGraphics())
            {
                var textSize = graphics.MeasureString("Text", statusLabel.Font);
                statusLabel.Height = (int)textSize.Height;
            }

            OnResize();

            Controls = new List <Control>()
            {
                statusLabel
            };

            Init();
        }
Ejemplo n.º 3
0
        private GnuGoLauncher(GnuGoSettings settings, string sgfFile)
        {
            var path = WinCEUtils.PathTo("gnugoce.exe");

            if (!File.Exists(path))
            {
                throw new GnuGoException(GnuGoError.ExecutableNotFound);
            }

            StopGnuGo();

            var info = new ProcessStartInfo(path, "--mode gtp --quiet --port " + Port)
            {
                UseShellExecute  = false,
                WorkingDirectory = WinCEUtils.GetCurrentDirectory()
            };

            gnugo = Process.Start(info);
            if (gnugo.HasExited)
            {
                throw new GnuGoException(GnuGoError.CouldNotStart);
            }

            client = new TcpClient("localhost", Port);
            if (!client.Client.Connected)
            {
                throw new GnuGoException(GnuGoError.CouldNotConnect);
            }

            stream = client.GetStream();
            buffer = new byte[4096];

            gtp = new GTP(this,
                          settings.BoardSize,
                          settings.Handicap,
                          settings.Komi,
                          settings.Level,
                          sgfFile);
        }