Esempio n. 1
0
        //public GoMoveResult Undo()
        //{
        //    WriteCommand("undo");
        //    ReadResponse();
        //    SaveStones();
        //    var rval = new GoMoveResult();
        //    return rval;
        //}

//        public void Quit()
//        {
//            WriteCommand("quit");
//            ReadResponse();
//            if (Process != null)
//            {
//                try
//                {
//                    Process.Kill();
//                }
//// ReSharper disable EmptyGeneralCatchClause
//                catch
//// ReSharper restore EmptyGeneralCatchClause
//                {
//                }
//            }
//            Process = null;
//        }

        //public string Name()
        //{
        //    WriteCommand("name");
        //    string code, msg;
        //    ReadResponse(out code, out msg);
        //    return msg;
        //}

        //public string Version()
        //{
        //    WriteCommand("version");
        //    string code, msg;
        //    ReadResponse(out code, out msg);
        //    return msg;
        //}

        //public bool IsFunctioning
        //{
        //    get
        //    {
        //        try
        //        {
        //            if (Process == null)
        //                return false;
        //            if (!Process.Responding)
        //                return false;
        //            if (Process.HasExited)
        //                return false;
        //            if (Process.ExitTime > Process.StartTime)
        //                return true;
        //            Name(); // if this causes an exception, we're in a bad state
        //        }
        //        catch (Exception)
        //        {
        //            return false;
        //        }

        //        return true;
        //    }
        //}

        ///// <summary>
        ///// Engine must be running or this will throw an error.
        ///// </summary>
        //public bool CompareEngineState(GoGameState clientState)
        //{
        //    // Get black and white positions from exe.
        //    SaveStones();

        //    // This does a deep comparison.
        //    var rval = Equals(clientState, _state);
        //    return rval;
        //}

        #endregion Public Methods

        #region Private Helpers

        private void ReopenGame()
        {
            try
            {
                State.WinMargin = 0;
                State.Status    = GoGameStatus.Active;

                // Save to database.
                _goGRepository.SaveGameState(CurrentGameId, State);
            }
            catch (DbEntityValidationException)
            {
                // Setting State to null will cause it to be loaded from database the next time
                // a client initiates an operation.
                State = null;
                throw;
            }
        }
Esempio n. 2
0
        public void Start(Guid gameId, GoGameState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            bool exists = _goGRepository.GetGameExists(gameId);

            if (exists)
            {
                throw new GoEngineException(GoResultCode.GameAlreadyExists, null);
            }

            // Get a Fuego instance and start it up.
            FuegoInstance inst = null;

            try
            {
                inst = GetFuegoInstance(gameId, GoOperation.Starting);
                inst.Start(state);

                // Save as the new game state.
                _goGRepository.SaveGameState(gameId, state);
            }
// ReSharper disable RedundantCatchClause
            catch (Exception)
            {
                throw;
            }
// ReSharper restore RedundantCatchClause
            finally
            {
                if (inst != null)
                {
                    inst.CurrentOperation = GoOperation.Idle;
                }
            }
        }