Exemplo n.º 1
0
 private ExplainedScore Evaluate(State state, IGameAction action)
 {
     using (action.ApplyTo(state))
     {
         return(evaluator.Evaluate(state, 0));
     }
 }
Exemplo n.º 2
0
        private ExplainedScore Evaluate(State state, IGameAction action, Countdown countdown, int playerIndex = 0)
        {
            using (action.ApplyTo(state))
            {
                //if (playerIndex == 0)
                //{
                //    var bestEnemyAction = FindBestEnemyAction(state, countdown);
                //    if (bestEnemyAction != null)
                //        using (bestEnemyAction.ApplyTo(state))
                //        {
                var movedCellLocation = state.GetUnits(playerIndex)[action.UnitIndex];
                return(evaluator.Evaluate(state, playerIndex, movedCellLocation));
                //}

                //    {
                //        var movedCellLocation = state.GetUnits(playerIndex)[action.UnitIndex];
                //        return evaluator.Evaluate(state, playerIndex, movedCellLocation);
                //    }
                //}
                //else
                //{
                //    var movedCellLocation = state.GetUnits(playerIndex)[action.UnitIndex];
                //    return evaluator.Evaluate(state, playerIndex, movedCellLocation);
                //}
            }
        }
Exemplo n.º 3
0
    public virtual void CheckHealth()
    {
        var results = new Stack <ProbeResult>();

        var tasks = _probes
                    .Select(async o => { results.Push(await o.Check().ConfigureAwait(false)); })
                    .ToArray();

        Task.WaitAll(tasks);

        var now = DateTime.UtcNow;

        _journalLock.EnterWriteLock();

        try
        {
            //cleanup state records
            _journal.RemoveAll(o => o.Time < now.Subtract(RetentionPeriod));

            _journal.Add(new JournalRecord(now, results));
        }
        finally
        {
            _journalLock.ExitWriteLock();
        }

        //Recalculate state
        var state = _stateEvaluator.Evaluate(State, StateChangedDate, _journal);

        if (!EqualityComparer <TState> .Default.Equals(State, state))
        {
            ChangeState(state, results.Where(o => !o.Success).Select(o => o.ProbeName));
        }

        OnHealthChecked(now, results);
    }