コード例 #1
0
        public async Task <GoHintResponse> HintAsync(Guid gameid, GoColor color)
        {
            GoHintResponse rval = null;

            try
            {
                await Task.Factory.StartNew(
                    () =>
                {
                    EnsureFuegoStarted().Wait();

                    _state.Operation = GoOperation.Hint;
                    SaveState();

                    var result =
                        ParseResponse(WriteCommand("reg_genmove", color == GoColor.Black ? "black" : "white"));

                    GoMove hint;
                    switch (result.Msg)
                    {
                    case "PASS":
                        hint = new GoMove(MoveType.Pass, color, null);
                        break;

                    case "resign":
                        hint = new GoMove(MoveType.Resign, color, null);
                        break;

                    default:
                        hint = new GoMove(MoveType.Normal, color, result.Msg);
                        break;
                    }
                    rval = new GoHintResponse(GoResultCode.Success, hint);

                    _state.Operation = GoOperation.Idle;
                    SaveState();
                });
            }
            catch (GoEngineException gex)
            {
                rval = new GoHintResponse(gex.Code, null);
            }
            catch (Exception ex)
            {
                rval = new GoHintResponse(GoResultCode.ServerInternalError, null);
            }

            Debug.Assert(rval != null, "rval != null");
            return(rval);
        }
コード例 #2
0
ファイル: Fuego.svc.cs プロジェクト: feathers88/gameofgo
        public GoHintResponse Hint(Guid gameid, GoColor color)
        {
            GoHintResponse rval;

            try
            {
                var result = FuegoEngine.Instance.Hint(gameid, color);
                rval = new GoHintResponse(GoResultCode.Success, result);
            }
            catch (GoEngineException gex)
            {
                _logger.LogEngineException(gameid, gex, "Color: " + color);
                rval = new GoHintResponse(gex.Code, null);
            }
            catch (Exception ex)
            {
                _logger.LogServerError(gameid, ex, "Color: " + color);
                rval = new GoHintResponse(GoResultCode.ServerInternalError, null);
            }
            return(rval);
        }
コード例 #3
0
ファイル: FuegoGameEngine.cs プロジェクト: outrera/gameofgo
        public async Task <GoHintResponse> HintAsync(Guid id, GoColor color)
        {
            await LoadState();

            GoHintResponse rval = null;

            try
            {
                await Task.Run(
                    async() =>
                {
                    await EnsureFuegoStartedAndMatchingGame(id);

                    _state.Operation = GoOperation.Hint;

                    // Remove limitation so we can get a good hint, even on lower
                    // difficulty levels.
                    SetDifficulty(true);

                    var result =
                        ParseResponse(WriteCommand("reg_genmove", color == GoColor.Black ? "black" : "white"));

                    GoMove hint;
                    switch (result.Msg)
                    {
                    case "PASS":
                        hint = new GoMove(MoveType.Pass, color, null);
                        break;

                    case "resign":
                        hint = new GoMove(MoveType.Resign, color, null);
                        break;

                    default:
                        hint = new GoMove(MoveType.Normal, color, result.Msg);
                        break;
                    }
                    rval = new GoHintResponse(GoResultCode.Success, hint);

                    _state.Operation = GoOperation.Idle;

                    await SaveState();
                });
            }
            catch (GoEngineException gex)
            {
                rval = new GoHintResponse(gex.Code, null);
            }
            catch (Exception)
            {
                rval = new GoHintResponse(GoResultCode.InternalError, null);
            }
            finally
            {
                try
                {
                    // Reset to configured difficulty level.
                    SetDifficulty();
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            Debug.Assert(rval != null, "rval != null");
            return(rval);
        }