Exemplo n.º 1
0
 private static bool ArenaFightQueue(List <PawnKindDef> lhs, List <PawnKindDef> rhs, Action <ArenaUtility.ArenaResult> callback, ArenaUtility.ArenaSetState state)
 {
     if (state.live < 15)
     {
         ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result)
         {
             state.live--;
             callback(result);
         });
         state.live++;
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        private static bool ArenaFightQueue(List <PawnKindDef> lhs, List <PawnKindDef> rhs, Action <ArenaUtility.ArenaResult> callback, ArenaUtility.ArenaSetState state)
        {
            bool result2;

            if (!ArenaUtility.ValidateArenaCapability())
            {
                result2 = false;
            }
            else if (state.live < 15)
            {
                ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result)
                {
                    state.live--;
                    callback(result);
                });
                state.live++;
                result2 = true;
            }
            else
            {
                result2 = false;
            }
            return(result2);
        }
        public static void PerformBattleRoyale(IEnumerable <PawnKindDef> kindsEnumerable)
        {
            if (!ArenaUtility.ValidateArenaCapability())
            {
                return;
            }
            List <PawnKindDef> kinds = kindsEnumerable.ToList <PawnKindDef>();
            Dictionary <PawnKindDef, float> ratings = new Dictionary <PawnKindDef, float>();

            foreach (PawnKindDef pawnKindDef in kinds)
            {
                ratings[pawnKindDef] = EloUtility.CalculateRating(pawnKindDef.combatPower, 1500f, 60f);
            }
            int currentFights  = 0;
            int completeFights = 0;

            Current.Game.GetComponent <GameComponent_DebugTools>().AddPerFrameCallback(delegate
            {
                if (currentFights >= 15)
                {
                    return(false);
                }
                PawnKindDef lhsDef = kinds.RandomElement <PawnKindDef>();
                PawnKindDef rhsDef = kinds.RandomElement <PawnKindDef>();
                float num          = EloUtility.CalculateExpectation(ratings[lhsDef], ratings[rhsDef]);
                float num2         = 1f - num;
                float num3         = num;
                float num4         = Mathf.Min(num2, num3);
                num2      /= num4;
                num3      /= num4;
                float num5 = Mathf.Max(num2, num3);
                if (num5 > 40f)
                {
                    return(false);
                }
                float num6             = 40f / num5;
                float num7             = (float)Math.Exp((double)Rand.Range(0f, (float)Math.Log((double)num6)));
                num2                  *= num7;
                num3                  *= num7;
                List <PawnKindDef> lhs = Enumerable.Repeat <PawnKindDef>(lhsDef, GenMath.RoundRandom(num2)).ToList <PawnKindDef>();
                List <PawnKindDef> rhs = Enumerable.Repeat <PawnKindDef>(rhsDef, GenMath.RoundRandom(num3)).ToList <PawnKindDef>();
                currentFights++;
                ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result)
                {
                    currentFights--;
                    completeFights++;
                    if (result.winner != ArenaUtility.ArenaResult.Winner.Other)
                    {
                        float value   = ratings[lhsDef];
                        float value2  = ratings[rhsDef];
                        float kfactor = 8f * Mathf.Pow(0.5f, Time.realtimeSinceStartup / 900f);
                        EloUtility.Update(ref value, ref value2, 0.5f, (float)((result.winner != ArenaUtility.ArenaResult.Winner.Lhs) ? 0 : 1), kfactor);
                        ratings[lhsDef] = value;
                        ratings[rhsDef] = value2;
                        Log.Message(string.Format("Scores after {0} trials:\n\n{1}", completeFights, (from v in ratings
                                                                                                      orderby v.Value
                                                                                                      select string.Format("  {0}: {1}->{2} (rating {2})", new object[]
                        {
                            v.Key.label,
                            v.Key.combatPower,
                            EloUtility.CalculateLinearScore(v.Value, 1500f, 60f).ToString("F0"),
                            v.Value.ToString("F0")
                        })).ToLineList(null)), false);
                    }
                });
                return(false);
            });
        }