public RuleOutcome RunRulesEngine(GameState currentGameState) { try { RuleOutcome outcome; GameState gameStateBeforeStep = RulesEngineHelper.GetInitialGameState(currentGameState); do { outcome = ReplayAndChooseNextMove(gameStateBeforeStep, currentGameState); if (AfterEachRepetition != null) { AfterEachRepetition(this, gameStateBeforeStep, currentGameState, outcome); } }while (Repeat && outcome.Status == RuleStatus.NoFurtherSuggestions); if (outcome.Status == RuleStatus.NextMoveSuggested || outcome.Status == RuleStatus.NoFurtherSuggestions) { AfterStep(this, gameStateBeforeStep, currentGameState, outcome); } return(outcome); } catch (Exception exc) { RuleOutcome outcome = new RuleOutcome { Status = RuleStatus.ExceptionThrown, ExceptionThrown = exc }; return(outcome); } }
public static RuleOutcome MoveToPositionAlongAnyRoute(GameState mutableGameState, GameState actualGameState, ref int nextMoveNumber, Position targetPosition) { RuleOutcome outcome; bool isTargetReachable = mutableGameState.IsCellStateReachableByPlayer(PlayerType.You, mutableGameState[targetPosition]); List <Position> positionsOnRouteToTarget = mutableGameState.GetPositionsOnAnyRouteToTheTargetPosition(PlayerType.You, targetPosition); foreach (Position pos in positionsOnRouteToTarget) { nextMoveNumber++; outcome = RulesEngineHelper.MoveToNextPosition(mutableGameState, actualGameState, pos, nextMoveNumber); if (outcome.Status != RuleStatus.NoFurtherSuggestions) { return(outcome); } } outcome = new RuleOutcome { Status = RuleStatus.NoFurtherSuggestions }; return(outcome); }