static void Main(string[] args) { var view = new Regulus.Utility.ConsoleViewer(); var input = new Regulus.Utility.ConsoleInput(view); var application = new Regulus.Project.SamebestKeys.Console(view, input); _BuildGameData(view); BotSet bots = new BotSet(); application.SetLogMessage(Regulus.Utility.Console.LogFilter.All); Regulus.Utility.Updater updater = new Regulus.Utility.Updater(); updater.Add(application); updater.Add(input); updater.Add(bots); bool exit = false; application.Command.Register("quit", () => { exit = true; }); application.Command.Register<string,int>("SetBotIp", (ip,port) => { Bot.Port = port; Bot.IpAddress = ip; }); application.Command.Register<int>("BotSn", (sn) => { bots.Sn = sn; }); application.Command.Register<int>("Bot", (count) => { bots.Create(count); }); application.SelectSystemEvent += (selector) => { var value = selector.Use("remoting"); value.OnValue += _SpawnController; value.OnValue += (requester) => { bots.Requester = requester; }; }; Regulus.Utility.TimeCounter fps = new Regulus.Utility.TimeCounter(); ; while (exit == false) { updater.Update(); fps.Reset(); } application.Command.Unregister("SetBotIp"); application.Command.Unregister("BotSn"); application.Command.Unregister("Bot"); application.Command.Unregister("quit"); application.Stop(); }
internal void Update() { if (new System.TimeSpan(_Timer.Ticks).TotalSeconds > 0.5) { _Timer.Reset(); if (_CommandStrings.Count > 0) { var c = _CommandStrings.Dequeue(); _Command.Run(c.Name, c.Args); } } }
static void Main(string[] args) { var view = new Regulus.Utility.ConsoleViewer(); var input = new Regulus.Utility.ConsoleInput(view); var application = new Regulus.Project.SamebestKeys.Console(view, input); BotSet bots = new BotSet(); application.SetLogMessage(Regulus.Utility.Console.LogFilter.All); Regulus.Utility.Updater<Regulus.Utility.IUpdatable> updater = new Regulus.Utility.Updater<Regulus.Utility.IUpdatable>(); updater.Add(application); updater.Add(input); updater.Add(bots); bool exit = false; application.Command.Register("quit", () => { exit = true; }); application.Command.Register<int>("Bot", (count) => { bots.Create(count); }); application.SelectSystemEvent += (selector) => { var value = selector.Use("remoting"); value.OnValue += _SpawnController; value.OnValue += (requester) => { bots.Requester = requester; }; }; Regulus.Utility.TimeCounter fps = new Regulus.Utility.TimeCounter(); ; while (exit == false) { if (fps.Second > 1.0 / 60) { updater.Update(); fps.Reset(); } } application.Command.Unregister("Bot"); application.Command.Unregister("quit"); application.Stop(); }
public List <Suit> Find(PropertyValue[] filter_propertys, int out_amount) { object suitSetLock = new object(); List <Suit> suitSet = new List <Suit>(); var rangePartitioner = System.Collections.Concurrent.Partitioner.Create(0, _Total()); object readLock = new object(); int reads = 0; System.Threading.SpinWait sw = new System.Threading.SpinWait(); Parallel.ForEach(rangePartitioner, (range, loopState) => { Regulus.Utility.TimeCounter time = new Regulus.Utility.TimeCounter(); List <Suit> suits = new List <Suit>(); int count = 0; //var range = new {Item1 = 0 , Item2 = _Total()}; for (long i = range.Item2 - 1; i >= range.Item1; --i, ++count) { int[] indexs = _GetIndexs(i); var s = new Suit( _GetCard(0, indexs[0]), _GetCard(1, indexs[1]), _GetCard(2, indexs[2]), _GetCard(3, indexs[3]), _GetCard(4, indexs[4]), _GetCard(5, indexs[5]), _GetCard(6, indexs[6]), _GetCard(7, indexs[7])); bool pass = (from filter in filter_propertys where s.GetValue(filter) < filter.Value select false).Count() == 0; sw.SpinOnce(); if (pass) { suits.Add(s); } if (time.Second > 1) { lock (readLock) { reads += count; count = 0; } _UpdateSet(ref suitSet, filter_propertys, out_amount, suitSetLock, reads, suits); suits.Clear(); time.Reset(); sw.SpinOnce(); } } lock (readLock) { reads += count; count = 0; } _UpdateSet(ref suitSet, filter_propertys, out_amount, suitSetLock, reads, suits); }); var result = suitSet.OrderByDescending((suit) => suit.GetValue(filter_propertys[0])); foreach (var property in filter_propertys.Skip(1)) { result = result.ThenByDescending((suit) => suit.GetValue(property)); } return(result.ToList()); }
static void Main(string[] args) { CardSet set = CardSet.Instance; System.Console.WriteLine("劍靈八卦牌計算器"); System.Console.WriteLine("讀取資源檔data.txt..."); try { var text = System.IO.File.ReadAllText("data.txt"); set.Load(text); } catch { System.Console.WriteLine("找不到data.txt"); return; } var filterSuits = _ShowSuitFilter(); PropertyValue[] filterPropertys = _InputProperty(); System.Console.Write("\n輸出格式1.csv 2.html(預設1):"); var fileFormat = System.Console.ReadLine(); System.Console.Write("\n輸出最大筆數:"); var outCount = System.Console.ReadLine(); int outAmount = 0; int.TryParse(outCount, out outAmount); Property[] propertys = filterPropertys.ToArray(); Card[] cards = set.Find(propertys, filterSuits); var cards1 = cards.Assort(1).Fill(CardSet.Instance, 1); var cards2 = cards.Assort(2).Fill(CardSet.Instance, 2); var cards3 = cards.Assort(3).Fill(CardSet.Instance, 3); var cards4 = cards.Assort(4).Fill(CardSet.Instance, 4); var cards5 = cards.Assort(5).Fill(CardSet.Instance, 5); var cards6 = cards.Assort(6).Fill(CardSet.Instance, 6); var cards7 = cards.Assort(7).Fill(CardSet.Instance, 7); var cards8 = cards.Assort(8).Fill(CardSet.Instance, 8); System.Int64 total = cards1.Count() * cards2.Count() * cards3.Count() * cards4.Count() * cards5.Count() * cards6.Count() * cards7.Count() * cards8.Count(); System.Console.WriteLine(string.Format("{0}筆資料比對中...請稍候", total)); Regulus.Utility.TimeCounter runTime = new Regulus.Utility.TimeCounter(); var suitFinder = new SuitFinder(cards1, cards2, cards3, cards4, cards5, cards6, cards7, cards8); Regulus.Utility.TimeCounter secondCounter = new Regulus.Utility.TimeCounter(); suitFinder.ProgressEvent += (count, amount, found) => { if (secondCounter.Second > 1 || count / amount == 1) { System.Console.WriteLine(string.Format("{1}/{2} ({3:0.00}%)...{0}(已找到)", found, count, amount, (float)count / (float)amount * 100)); secondCounter.Reset(); } }; List <Suit> suits = suitFinder.Find(filterPropertys, outAmount); //List<Suit> suits = _SingThread(filterPropertys, outAmount, propertys, cards1, cards2, cards3, cards4, cards5, cards6, cards7, cards8, total); System.Console.WriteLine(string.Format("花費秒數{0}", runTime.Second)); System.Console.WriteLine(string.Format("檔案寫入中...")); string path; if (fileFormat == "1") { path = _WriteCSV(_GetFileName(filterPropertys), suits.ToArray(), outAmount); } else if (fileFormat == "2") { path = _WriteHTML(_GetFileName(filterPropertys), suits.ToArray(), outAmount); } else { path = _WriteCSV(_GetFileName(filterPropertys), suits.ToArray(), outAmount); } System.Console.WriteLine("寫入完成."); _ShowThank(); System.Console.ReadKey(); System.Diagnostics.Process.Start(path); }
private static List <Suit> _SingThread(PropertyValue[] filterPropertys, int outAmount, Property[] propertys, Card[] cards1, Card[] cards2, Card[] cards3, Card[] cards4, Card[] cards5, Card[] cards6, Card[] cards7, Card[] cards8, System.Int64 total) { int count = 0; Regulus.Utility.TimeCounter timeCounter = new Regulus.Utility.TimeCounter(); List <Suit> suits = new List <Suit>(); foreach (var card1 in cards1) { foreach (var card2 in cards2) { foreach (var card3 in cards3) { foreach (var card4 in cards4) { foreach (var card5 in cards5) { foreach (var card6 in cards6) { foreach (var card7 in cards7) { foreach (var card8 in cards8) { if (timeCounter.Second > 1) { var orders = suits.OrderBy((suit) => suit.GetValue(propertys[0])); foreach (var property in propertys.Skip(1)) { orders = orders.ThenBy((suit) => suit.GetValue(property)); } suits = orders.ToList(); if (suits.Count > outAmount) { suits.RemoveRange(0, suits.Count - outAmount); } System.Console.WriteLine(string.Format("{0}/{1}...{2}", count, total, suits.Count)); timeCounter.Reset(); } var s = new Suit(card1, card2, card3, card4, card5, card6, card7, card8); bool pass = (from filter in filterPropertys where s.GetValue(filter) < filter.Value select false).Count() == 0; if (pass) { suits.Add(s); } count++; } } } } } } } } var result = suits.OrderByDescending((suit) => suit.GetValue(propertys[0])); foreach (var property in propertys.Skip(1)) { result = result.ThenByDescending((suit) => suit.GetValue(property)); } suits = result.ToList(); return(suits); }