コード例 #1
0
ファイル: VolcanoGame.cs プロジェクト: skotz/volcanoes
        private void BackgroundWork(object sender, DoWorkEventArgs e)
        {
            EngineCancellationToken token = new EngineCancellationToken(_worker);

            try
            {
                BackgroundError = null;

                CurrentState.Transcript = GetTranscriptLine();

                var timer = Stopwatch.StartNew();

                if (CurrentState.Player == Player.One)
                {
                    e.Result = _playerOneEngine.GetBestMove(CurrentState, SecondsPerEngineMove, token);
                }
                else if (CurrentState.Player == Player.Two)
                {
                    e.Result = _playerTwoEngine.GetBestMove(CurrentState, SecondsPerEngineMove, token);
                }

                if (timer.ElapsedMilliseconds > SecondsPerEngineMove * 1000 + _graceTimeout)
                {
                    e.Result = new SearchResult {
                        Timeout = true
                    };
                }
            }
            catch (Exception ex)
            {
                BackgroundError = ex;

                try
                {
                    using (StreamWriter w = new StreamWriter("errors.txt", true))
                    {
                        w.WriteLine(DateTime.Now.ToString() + "\r\nFailed to get a move from an engine!\r\n" + ex.ToString() + "\r\n\r\n");
                    }
                }
                catch { /* TODO */ }

                e.Result = new SearchResult();
            }

            if (token.Cancelled)
            {
                e.Cancel = true;
            }
        }
コード例 #2
0
        private void BackgroundWork(object sender, DoWorkEventArgs e)
        {
            EngineCancellationToken token = new EngineCancellationToken(_worker);

            try
            {
                BackgroundError = null;

                if (CurrentState.Player == Player.One)
                {
                    e.Result = _playerOneEngine.GetBestMove(CurrentState, SecondsPerEngineMove, token);
                }
                else if (CurrentState.Player == Player.Two)
                {
                    e.Result = _playerTwoEngine.GetBestMove(CurrentState, SecondsPerEngineMove, token);
                }
            }
            catch (Exception ex)
            {
                BackgroundError = ex;

                try
                {
                    using (StreamWriter w = new StreamWriter("errors.txt", true))
                    {
                        w.WriteLine("Failed to get a move from an engine! :: " + ex.Message);
                    }
                }
                catch { /* TODO */ }

                e.Result = new SearchResult();
            }

            if (token.Cancelled)
            {
                e.Cancel = true;
            }
        }