Esempio n. 1
0
 public TextTable()
 {
     if (Singleton == null)
     {
         Singleton = this;
         _textConfig = new ConfigOperator();
     }
     else
     {
         throw new System.Exception();			//if singleton exist, throw a Exception
     }
 }
Esempio n. 2
0
    public static TextTable Parse(TextReader reader)
    {
        TextTable table = new TextTable();

        if (regularExpressionParser == null)
            loadRegEx ();

        string tableString = reader.ReadToEnd ();

        MatchCollection matches = regularExpressionParser.Matches (tableString);

        foreach (Match m in matches)
        {
            if(!m.Success)
            {
                string logError = "Error: Could not parse string in file matching \"" + m.Value + "\"";
                Debug.LogError(logError);
                return null;
            }

            string key = m.Groups["tag"].Value;
            Group group = m.Groups["text"];

            string s = "";
            foreach(Capture c in group.Captures)
            {
                s += c.Value + "\n";
            }

            if(s.Length > 0)
                s = s.Substring(0, s.Length - 1);

            table.AddEntry(key, s);
        }

        return table;
    }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad (this.gameObject);
     stringsList = txtParser.Parse (stringsFile);
     parseStrings ();
 }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad(this.gameObject);
     stringsList = txtParser.Parse(stringsFile);
     parseStrings();
 }
Esempio n. 5
0
        public static void stats(Arg arg)
        {
            TextTable table = new TextTable();

            table.AddColumn("id");
            table.AddColumn("name");
            table.AddColumn("time");
            table.AddColumn("kills");
            table.AddColumn("deaths");
            table.AddColumn("suicides");
            table.AddColumn("player");
            table.AddColumn("building");
            table.AddColumn("entity");
            Action <ulong, string> action = delegate(ulong id, string name)
            {
                ServerStatistics.Storage storage = ServerStatistics.Get(id);
                string text2  = TimeSpanEx.ToShortString(TimeSpan.FromSeconds(storage.Get("time")));
                string text3  = storage.Get("kill_player").ToString();
                string text4  = (storage.Get("deaths") - storage.Get("death_suicide")).ToString();
                string text5  = storage.Get("death_suicide").ToString();
                string text6  = storage.Get("hit_player_direct_los").ToString();
                string text7  = storage.Get("hit_player_indirect_los").ToString();
                string text8  = storage.Get("hit_building_direct_los").ToString();
                string text9  = storage.Get("hit_building_indirect_los").ToString();
                string text10 = storage.Get("hit_entity_direct_los").ToString();
                string text11 = storage.Get("hit_entity_indirect_los").ToString();
                table.AddRow(id.ToString(), name, text2, text3, text4, text5, text6 + " / " + text7, text8 + " / " + text9, text10 + " / " + text11);
            };
            ulong uInt = arg.GetUInt64(0, 0uL);

            if (uInt == 0L)
            {
                string @string = arg.GetString(0);
                foreach (BasePlayer activePlayer in BasePlayer.activePlayerList)
                {
                    try
                    {
                        if (BaseEntityEx.IsValid(activePlayer))
                        {
                            string text = activePlayer.displayName.QuoteSafe();
                            if (@string.Length <= 0 || text.Contains(@string, CompareOptions.IgnoreCase))
                            {
                                action(activePlayer.userID, text);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        table.AddRow(activePlayer.UserIDString, ex.Message.QuoteSafe());
                    }
                }
            }
            else
            {
                string     arg2       = "N/A";
                BasePlayer basePlayer = BasePlayer.FindByID(uInt);
                if ((bool)basePlayer)
                {
                    arg2 = basePlayer.displayName.QuoteSafe();
                }
                action(uInt, arg2);
            }
            arg.ReplyWith(table.ToString());
        }
Esempio n. 6
0
        public static void carstats(Arg arg)
        {
            HashSet <ModularCar> allCarsList = ModularCar.allCarsList;
            TextTable            textTable   = new TextTable();

            textTable.AddColumn("id");
            textTable.AddColumn("sockets");
            textTable.AddColumn("modules");
            textTable.AddColumn("complete");
            textTable.AddColumn("engine");
            textTable.AddColumn("health");
            textTable.AddColumn("location");
            int count = allCarsList.Count;
            int num   = 0;
            int num2  = 0;
            int num3  = 0;

            foreach (ModularCar item in allCarsList)
            {
                string text  = item.net.ID.ToString();
                string text2 = item.TotalSockets.ToString();
                string text3 = item.NumAttachedModules.ToString();
                string text4;
                if (item.IsComplete())
                {
                    text4 = "Complete";
                    num++;
                }
                else
                {
                    text4 = "Partial";
                }
                string text5;
                if (item.HasAnyWorkingEngines())
                {
                    text5 = "Working";
                    num2++;
                }
                else
                {
                    text5 = "Broken";
                }
                string text6 = ((item.TotalMaxHealth() != 0f) ? $"{item.TotalHealth() / item.TotalMaxHealth():0%}" : "0");
                string text7;
                if (item.IsOutside())
                {
                    text7 = "Outside";
                }
                else
                {
                    text7 = "Inside";
                    num3++;
                }
                textTable.AddRow(text, text2, text3, text4, text5, text6, text7);
            }
            string text8 = "";

            text8 = ((count != 1) ? (text8 + $"\nThe world contains {count} modular cars.") : (text8 + "\nThe world contains 1 modular car."));
            text8 = ((num != 1) ? (text8 + $"\n{num} ({(float)num / (float)count:0%}) are in a completed state.") : (text8 + $"\n1 ({1f / (float)count:0%}) is in a completed state."));
            text8 = ((num2 != 1) ? (text8 + $"\n{num2} ({(float)num2 / (float)count:0%}) are driveable.") : (text8 + $"\n1 ({1f / (float)count:0%}) is driveable."));
            arg.ReplyWith(string.Concat(str1: (num3 != 1) ? (text8 + $"\n{num3} ({(float)num3 / (float)count:0%}) are sheltered indoors.") : (text8 + $"\n1 ({1f / (float)count:0%}) is sheltered indoors."), str0: textTable.ToString()));
        }
Esempio n. 7
0
        private static void SetCell(TextTable tt, int col, int row, Dictionary <string, string> items)
        {
            string str = null;

            if (items.Values.Distinct().Count() == 1)
            {
                str = items.Values.First();
            }
            else
            {
                // Try numbers
                var strs1 = new List <string>();
                for (char n = '1'; n <= '3'; n++)
                {
                    var tItems = items.Where(p => p.Key.StartsWith(n)).ToArray();
                    if ("ASDF".All(ch => items.ContainsKey(n.ToString() + ch)))
                    {
                        var biggestGroup = tItems.GroupBy(p => p.Value).MaxElement(g => g.Count());
                        if (biggestGroup.Count() == 1)
                        {
                            biggestGroup = null;
                        }
                        foreach (var tItem in tItems)
                        {
                            if (biggestGroup == null || !biggestGroup.Any(p => p.Key == tItem.Key))
                            {
                                strs1.Add($"{tItem.Key}={tItem.Value}");
                            }
                        }
                        if (biggestGroup != null)
                        {
                            strs1.Add($"{n}={biggestGroup.First().Value}");
                        }
                    }
                    else
                    {
                        strs1.AddRange(tItems.Select(p => $"{p.Key}={p.Value}"));
                    }
                }

                // Try letters
                var strs2 = new List <string>();
                foreach (char l in "ASDF")
                {
                    var tItems = items.Where(p => p.Key.EndsWith(l)).ToArray();
                    if ("123".All(ch => items.ContainsKey(ch + l.ToString())))
                    {
                        var biggestGroup = tItems.GroupBy(p => p.Value).MaxElement(g => g.Count());
                        if (biggestGroup.Count() == 1)
                        {
                            biggestGroup = null;
                        }
                        foreach (var tItem in tItems)
                        {
                            if (biggestGroup == null || !biggestGroup.Any(p => p.Key == tItem.Key))
                            {
                                strs2.Add($"{tItem.Key}={tItem.Value}");
                            }
                        }
                        if (biggestGroup != null)
                        {
                            strs2.Add($"{l}={biggestGroup.First().Value}");
                        }
                    }
                    else
                    {
                        strs2.AddRange(tItems.Select(p => $"{p.Key}={p.Value}"));
                    }
                }

                str = (strs1.Count > strs2.Count ? strs2 : strs1).JoinString("\n");
            }
            tt.SetCell(col, row, str);
        }
Esempio n. 8
0
        public static void Simulations()
        {
            const int iterations    = 100000;
            const int quadrantCount = 5;

            var getQuadrantCounts = Ut.Lambda((bool[][] arr) =>
            {
                var qCounts = new int[4];
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        if (arr[x][y])
                        {
                            qCounts[(y / 4) * 2 + (x / 4)]++;
                        }
                    }
                }
                return(qCounts);
            });

            var quadrantCountRule = Ut.Lambda((bool white) => new Tuple <string, Func <bool[][], Edgework, int> >(
                                                  $"Exactly one quadrant has {quadrantCount} or fewer {(white ? "white" : "black")} pixels ⇒ number of {(white ? "white" : "black")} pixels in the other 3 quadrants",
                                                  (arr, edgework) =>
            {
                var qCounts = getQuadrantCounts(arr);
                if ((white ? qCounts.Count(sum => sum <= quadrantCount) : qCounts.Count(sum => sum >= (16 - quadrantCount))) != 1)
                {
                    return(0);
                }
                var qIx = (white ? qCounts.IndexOf(sum => sum <= quadrantCount) : qCounts.IndexOf(sum => sum >= (16 - quadrantCount))) + 1;
                return((qCounts.Where((sum, ix) => ix != qIx).Sum() + 3) % 4 + 1);
            }));

            var totalCountRule = Ut.Lambda((int num, bool white) => new Tuple <string, Func <bool[][], Edgework, int> >(
                                               $"The entire bitmap has {num} or more {(white ? "white" : "black")} pixels ⇒ number of {(white ? "white" : "black")} pixels",
                                               (arr, edgework) =>
            {
                var sum = 0;
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        sum += (arr[x][y] ^ white) ? 0 : 1;
                    }
                }
                if (sum >= num)
                {
                    return(((sum + 3) % 4) + 1);
                }
                return(0);
            }));

            var rowColumnRule = new Tuple <string, Func <bool[][], Edgework, int> >(
                "Exactly one row or column is completely white or completely black ⇒ x- or y-coordinate",
                (arr, edgework) =>
            {
                int answer = 0;
                for (int x = 0; x < 8; x++)
                {
                    var isWhite = arr[x][0];
                    for (int y = 1; y < 8; y++)
                    {
                        if (arr[x][y] != isWhite)
                        {
                            goto next;
                        }
                    }

                    if (answer != 0)
                    {
                        return(0);
                    }
                    // The coordinate is 0-based, but the answer needs to be 1-based.
                    answer = (x % 4) + 1;

                    next:;
                }
                for (int y = 0; y < 8; y++)
                {
                    var isWhite = arr[0][y];
                    for (int x = 1; x < 8; x++)
                    {
                        if (arr[x][y] != isWhite)
                        {
                            goto next;
                        }
                    }

                    if (answer != 0)
                    {
                        return(0);
                    }
                    // The coordinate is 0-based, but the answer needs to be 1-based.
                    answer = (y % 4) + 1;

                    next:;
                }
                return(answer);
            });

            var squareRule = new Tuple <string, Func <bool[][], Edgework, int> >(
                "There is a 3×3 square that is completely white or completely black ⇒ x-coordinate of center of first in reading order",
                (arr, edgework) =>
            {
                for (int x = 1; x < 7; x++)
                {
                    for (int y = 1; y < 7; y++)
                    {
                        var isWhite = arr[x][y];
                        for (int xx = -1; xx < 2; xx++)
                        {
                            for (int yy = -1; yy < 2; yy++)
                            {
                                if (arr[x + xx][y + yy] != isWhite)
                                {
                                    goto next;
                                }
                            }
                        }
                        // x is 0-based, but the answer needs to be 1-based.
                        return((x % 4) + 1);

                        next:;
                    }
                }
                return(0);
            });

            var quadrantMajorityRule = Ut.Lambda((string name, Func <int, int, Edgework, bool> compare, Func <int, int, Edgework, bool[][], int> getAnswer) => new Tuple <string, Func <bool[][], Edgework, int> >(
                                                     name,
                                                     (arr, widgets) =>
            {
                var quadrantCounts = new int[4];
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        if (arr[x][y])
                        {
                            quadrantCounts[(x / 4) * 2 + (y / 4)]++;
                        }
                    }
                }
                var w = quadrantCounts.Count(q => q > 8);
                var b = quadrantCounts.Count(q => q < 8);
                return(compare(b, w, widgets) ? ((getAnswer(b, w, widgets, arr) + 3) % 4) + 1 : 0);
            }));

            var rules = Ut.NewArray(
                quadrantCountRule(true),
                quadrantMajorityRule("There are as many mostly-white quadrants as there are lit indicators ⇒ number of batteries", (b, w, widgets) => w == widgets.GetNumLitIndicators(), (b, w, widgets, arr) => widgets.GetNumBatteries()),
                rowColumnRule,
                quadrantMajorityRule("There are fewer mostly-white quadrants than mostly-black quadrants ⇒ number of mostly-black quadrants", (b, w, widgets) => w < b, (b, w, widgets, arr) => b),
                totalCountRule(36, true),
                quadrantMajorityRule("There are more mostly-white quadrants than mostly-black quadrants ⇒ smallest number of black in any quadrant", (b, w, widgets) => w > b, (b, w, widgets, arr) => 16 - getQuadrantCounts(arr).Max()),
                quadrantCountRule(false),
                quadrantMajorityRule("There are as many mostly-black quadrants as there are unlit indicators ⇒ number of ports", (b, w, widgets) => b == widgets.GetNumUnlitIndicators(), (b, w, widgets, arr) => widgets.GetNumPorts()),
                squareRule,
                quadrantMajorityRule("There are as many mostly-white quadrants as mostly-black quadrants ⇒ first numeric digit of the serial number", (b, w, widgets) => w == b, (b, w, widgets, arr) => Rnd.Next(0, 10)));

            var counts = new int[rules.Length, 4];

            for (int iter = 0; iter < iterations; iter++)
            {
                var edgework  = Edgework.Generate();
                var bitmap    = Ut.NewArray(8, 8, (_, __) => Rnd.Next(0, 2) == 0);
                var startRule = Rnd.Next(0, rules.Length);

                var    answer = 0;
                string rule;
                int    ruleIndex;
                for (int r = 0; r < rules.Length; r++)
                {
                    ruleIndex = (r + startRule) % rules.Length;
                    var tup = rules[ruleIndex];
                    answer = tup.Item2(bitmap, edgework);
                    if (answer != 0)
                    {
                        rule = tup.Item1;
                        goto found;
                    }
                }
                Console.WriteLine(rules.Select(r => r.Item2(bitmap, edgework)).JoinString(", "));
                System.Diagnostics.Debugger.Break();
                break;

                found :;
                counts[ruleIndex, answer - 1]++;
            }

            var tt = new TextTable {
                ColumnSpacing = 2
            };
            var ruleCounts = new int[rules.Length];

            for (int a = 0; a < 4; a++)
            {
                tt.SetCell(a + 1, 0, (a + 1).ToString().Color(ConsoleColor.White), alignment: HorizontalTextAlignment.Right);
                tt.SetCell(a + 1, rules.Length + 1, ((Enumerable.Range(0, rules.Length).Sum(r => counts[r, a]) * 100 / (double)iterations).ToString("0.0") + "%").Color(ConsoleColor.Green), alignment: HorizontalTextAlignment.Right);
            }

            for (int r = 0; r < rules.Length; r++)
            {
                tt.SetCell(0, r + 1, rules[r].Item1.Color(ConsoleColor.Cyan).Apply(s => s.ColorSubstring(s.IndexOf('⇒'), ConsoleColor.DarkCyan)), alignment: HorizontalTextAlignment.Right);
                for (int a = 0; a < 4; a++)
                {
                    tt.SetCell(a + 1, r + 1, ((counts[r, a] * 100 / (double)iterations).ToString("0.0") + "%").Color(ConsoleColor.Magenta), alignment: HorizontalTextAlignment.Right);
                }
                tt.SetCell(5, r + 1, ((Enumerable.Range(0, 4).Sum(a => counts[r, a]) * 100 / (double)iterations).ToString("0.0") + "%").Color(ConsoleColor.White), alignment: HorizontalTextAlignment.Right);
                ruleCounts[r] += Enumerable.Range(0, 4).Sum(a => counts[r, a]);
            }

            tt.WriteToConsole();
            Console.WriteLine();
            ConsoleUtil.WriteLine("Ratio of most likely to least likely rule: {0/White:0.0}".Color(ConsoleColor.White).Fmt(ruleCounts.Max() / (double)ruleCounts.Min()));
        }
Esempio n. 9
0
 public static void AddHeadTo(TextTable table)
 {
     table.Add("").Add("Name").Add("Type").Add("Default value").Add("Possible/current values");
 }
Esempio n. 10
0
        private TextTable CreateTextTable(Type typeofTextTable, string langCode)
        {
            var textTable = new TextTable(typeofTextTable, langCode, this.FetchTextTableAsync);

            return(textTable);
        }
Esempio n. 11
0
        public static void aiDebug_toggle(Arg args)
        {
            int @int = args.GetInt(0);

            if (@int == 0)
            {
                return;
            }
            BaseEntity baseEntity = BaseNetworkable.serverEntities.Find((uint)@int) as BaseEntity;

            if (baseEntity == null)
            {
                return;
            }
            NPCPlayerApex nPCPlayerApex = baseEntity as NPCPlayerApex;

            if (nPCPlayerApex != null)
            {
                TextTable textTable = new TextTable();
                textTable.AddColumn("type");
                textTable.AddColumn("state");
                textTable.AddColumn("posSync");
                textTable.AddColumn("health");
                textTable.AddColumn("stuckTime");
                textTable.AddColumn("hasPath");
                textTable.AddColumn("hasEnemyTarget");
                textTable.AddColumn("isMounted");
                textTable.AddRow(nPCPlayerApex.Family.ToString(), nPCPlayerApex.IsDormant ? "dormant" : "awake", nPCPlayerApex.syncPosition.ToString(), nPCPlayerApex.health.ToString("N2"), nPCPlayerApex.stuckDuration.ToString("N2"), nPCPlayerApex.HasPath.ToString(), (nPCPlayerApex.AttackTarget != null).ToString(), nPCPlayerApex.isMounted ? "true" : "false");
                args.ReplyWith(textTable.ToString());
                return;
            }
            BaseAnimalNPC baseAnimalNPC = baseEntity as BaseAnimalNPC;

            if (baseAnimalNPC != null)
            {
                TextTable textTable2 = new TextTable();
                textTable2.AddColumn("type");
                textTable2.AddColumn("state");
                textTable2.AddColumn("posSync");
                textTable2.AddColumn("health");
                textTable2.AddColumn("stuckTime");
                textTable2.AddColumn("hasPath");
                textTable2.AddColumn("hasEnemyTarget");
                textTable2.AddColumn("hasFoodTarget");
                textTable2.AddRow(baseAnimalNPC.Stats.Family.ToString(), baseAnimalNPC.IsDormant ? "dormant" : "awake", baseAnimalNPC.syncPosition.ToString(), baseAnimalNPC.health.ToString("N2"), baseAnimalNPC.stuckDuration.ToString("N2"), baseAnimalNPC.HasPath.ToString(), (baseAnimalNPC.AttackTarget != null).ToString(), (baseAnimalNPC.FoodTarget != null).ToString());
                args.ReplyWith(textTable2.ToString());
            }
            else
            {
                HTNPlayer hTNPlayer = baseEntity as HTNPlayer;
                if (hTNPlayer != null)
                {
                    TextTable textTable3 = new TextTable();
                    textTable3.AddColumn("type");
                    textTable3.AddColumn("state");
                    textTable3.AddColumn("posSync");
                    textTable3.AddColumn("health");
                    textTable3.AddColumn("hasEnemyTarget");
                    textTable3.AddColumn("isMounted");
                    textTable3.AddRow(hTNPlayer.Family.ToString(), hTNPlayer.IsDormant ? "dormant" : "awake", hTNPlayer.syncPosition.ToString(), hTNPlayer.health.ToString("N2"), (hTNPlayer.MainTarget != null).ToString(), hTNPlayer.isMounted ? "true" : "false");
                    args.ReplyWith(textTable3.ToString());
                }
            }
        }