public string SaveSGF(Guid gameId) { // Get a Fuego instance and start it up. FuegoInstance inst = null; try { inst = GetFuegoInstance(gameId, GoOperation.Undo); inst.EnsureRunning(); var svg = inst.SaveSGF(); return(svg); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
public void LoadSGF(Guid gameId, string sgf) { // Get a Fuego instance and start it up. FuegoInstance inst = null; try { inst = GetFuegoInstance(gameId, GoOperation.Undo); inst.EnsureRunning(); inst.LoadSGF(sgf); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
public GoGameState Undo(Guid gameId) { // Get a Fuego instance and start it up. FuegoInstance inst = null; try { inst = GetFuegoInstance(gameId, GoOperation.Undo); inst.EnsureRunning(); inst.Undo(); inst.CurrentOperation = GoOperation.Idle; return(_goGRepository.GetGameState(gameId)); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
public GoMove Hint(Guid gameId, GoColor color) { // Get a Fuego instance and start it up. FuegoInstance inst = null; try { inst = GetFuegoInstance(gameId, GoOperation.Hint); inst.EnsureRunning(); var result = inst.Hint(color); return(result); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
public void GenMove(Guid gameId, GoColor color, out GoMove newMove, out GoMoveResult result) { // Get a Fuego instance and start it up. FuegoInstance inst = null; try { inst = GetFuegoInstance(gameId, GoOperation.GenMove); inst.EnsureRunning(); inst.GenMove(color, out newMove, out result); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
public GoMoveResult Play(Guid gameId, GoMove move) { if (move == null) { throw new ArgumentNullException("move"); } // Get a Fuego instance and start it up. FuegoInstance inst = null; try { GoOperation op; switch (move.MoveType) { case MoveType.Normal: op = GoOperation.NormalMove; break; case MoveType.Pass: op = GoOperation.Pass; break; case MoveType.Resign: op = GoOperation.Resign; break; default: throw new Exception("Unrecognized move type: " + move.MoveType); } inst = GetFuegoInstance(gameId, op); inst.EnsureRunning(); var result = inst.Play(move); return(result); } // ReSharper disable RedundantCatchClause catch (Exception) { throw; } // ReSharper restore RedundantCatchClause finally { if (inst != null) { inst.CurrentOperation = GoOperation.Idle; } } }
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; } } }
private void Setup(ILogger logger, IGoGRepository goGRepository) { _logger = logger; _goGRepository = goGRepository; var cleanupInMinutess = Convert.ToInt32(ConfigurationManager.AppSettings["CleanupIntervalInMinutes"]); _cleanupInterval = TimeSpan.FromMinutes(cleanupInMinutess); _instances = new HashSet <FuegoInstance>(); _maxInstances = Convert.ToByte(ConfigurationManager.AppSettings["FuegoInstances"]); var gb = Convert.ToDecimal(ConfigurationManager.AppSettings["GBPerFuegoInstance"]); _memoryPerInstance = (long)Decimal.Round((decimal)1024 * 1024 * 1024 * gb); Cleanup(); // Spin up copies of fuego.exe up to instance limit. for (int i = 0; i < Instance._maxInstances; i++) { var instance = new FuegoInstance(_goGRepository, _memoryPerInstance, _logger); _instances.Add(instance); } }