Exemplo n.º 1
0
        static string[] PromptArgs()
        {
            Console.WriteLine(Translate.Get("prompt_args.first"));
            var first = Prompt();

            Console.WriteLine(Translate.Get("prompt_args.second"));
            var second = Prompt();

            Console.WriteLine();

            if (string.IsNullOrWhiteSpace(second))
            {
                return(new string[] { first });
            }

            return(new string[] { first, second });
        }
Exemplo n.º 2
0
        static string PatternToString(Pattern pattern)
        {
            var deckNames = pattern.Deck.Select(ids =>
            {
                var names = ids.Select(id =>
                {
                    var s = CardTable.FindNameById(id);

                    if (_options.HighlightCards.Contains(id))
                    {
                        s = $"*{s}*";
                    }

                    if (_options.StrongHighlightCards.Contains(id))
                    {
                        s = $"**{s}**";
                    }

                    return(s);
                });

                var namesS = string.Join("|", names);

                return(ids.Count == 1 ? namesS : $"({namesS})");
            });

            var deckS = string.Join(", ", deckNames);

            string initiativeS;

            if (pattern.Initiative == null)
            {
                initiativeS = Translate.Get("initiative.any");
            }
            else if (pattern.Initiative == true)
            {
                initiativeS = Translate.Get("initiative.player");
            }
            else
            {
                initiativeS = Translate.Get("initiative.cpu");
            }

            return(string.Format(Translate.Get("pattern2str_fmt"), initiativeS, deckS));
        }
Exemplo n.º 3
0
        static string FuzzyToString(string fuzzy)
        {
            var r = new List <string>();

            if (fuzzy.Contains('r'))
            {
                r.Add(Translate.Get("fuzzy.ranks"));
            }

            if (fuzzy.Contains('o'))
            {
                r.Add(Translate.Get("fuzzy.order"));
            }

            if (r.Count == 0)
            {
                return(Translate.Get("fuzzy.strict"));
            }

            return(string.Join(", ", r));
        }
Exemplo n.º 4
0
        static void RareSearch(uint state, Player player, bool counting = false)
        {
            var lastIncr = RareTimer(state, player);

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine(Translate.Get("prompt.rare_search"));
                var line = Prompt();

                if (string.IsNullOrEmpty(line))
                {
                    RareSearch(state, player, counting);
                }
                else if (line.StartsWith("h"))
                {
                    ShowPatternHelp();
                }
                else if (line.StartsWith("q"))
                {
                    Environment.Exit(0);
                }
                else
                {
                    var recoveryPattern = StringToPattern(line, player);

                    if (recoveryPattern == null)
                    {
                        continue;
                    }

                    var nextSearchType  = counting ? TSearchType.Counting : TSearchType.Recovery;
                    var recoveryScanner = OpeningScanner(state, player, nextSearchType, lastIncr);
                    StartSearch(recoveryScanner, recoveryPattern, player);
                }
            }
        }
Exemplo n.º 5
0
        static void StartSearch(Func <Pattern, bool, IEnumerable <ScanEntry> > scanner, Pattern pattern, Player player)
        {
            IEnumerable <ScanEntry> result = Enumerable.Empty <ScanEntry>();

            for (var i = 0; i < _options.Fuzzy.Length; i++)
            {
                var fuzzy = _options.Fuzzy[i];

                var fuzzyRanks = fuzzy.Contains('r');
                var fuzzyOrder = fuzzy.Contains('o');
                Console.WriteLine(new string('-', 60));
                Console.WriteLine(string.Format(Translate.Get("fuzzy.fmt"), FuzzyToString(fuzzy)));

                pattern = StringToPattern(pattern.Str, player, fuzzyRanks, silent: true);
                Console.WriteLine(PatternToString(pattern));

                var r   = scanner(pattern, fuzzyOrder);
                var msg = r.Count() == 0 ? "not" : r.Count().ToString();
                msg = msg + " found.";

                var lastp = (i == (_options.Fuzzy.Length - 1));

                if (!r.Any() && !lastp)
                {
                    msg = msg + " retry...";
                }

                Console.WriteLine(msg);

                if (r.Any())
                {
                    OutputSearchResults(r);
                    result = r;
                    break;
                }
            }

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine(Translate.Get("prompt.after_normal_search"));
                var line = Prompt();

                if (string.IsNullOrEmpty(line))
                {
                    var target = result.OrderBy(x => Math.Abs(x.Index)).FirstOrDefault();

                    if (target == null)
                    {
                        Console.WriteLine(Translate.Get("no_target"));
                        continue;
                    }

                    var lastState = target.Data.Opening.LastState;
                    RareSearch(lastState, player);
                }
                else if (line.StartsWith("h"))
                {
                    ShowPatternHelp();
                }
                else if (line.StartsWith("q"))
                {
                    Environment.Exit(0);
                }
                else
                {
                    var newPattern = StringToPattern(line, player, fuzzyRanks: false);

                    if (newPattern == null)
                    {
                        continue;
                    }

                    StartSearch(scanner, newPattern, player);
                }
            }
        }
Exemplo n.º 6
0
 static void ShowPatternHelp()
 {
     Console.WriteLine(Translate.Get("help.pattern"));
 }
Exemplo n.º 7
0
 static void ShowHelp()
 {
     Console.WriteLine(Translate.Get("help.first"));
     Console.WriteLine();
     Console.WriteLine(Translate.Get("help.last"));
 }
Exemplo n.º 8
0
        static (uint firstState, uint state, uint count, TSearchType searchType) ReadArgs(string[] args, bool silent = false)
        {
            var s = args[0];
            var earlyQuistisTable = EarlyQuistisStateTable.Get(_options.EarlyQuistis);
            var firstState        = 0U;
            var searchType        = TSearchType.First;
            var msg = "";

            switch (s)
            {
            case "0":     // Unused
                firstState = earlyQuistisTable.Unused;
                msg        = Translate.Get("read_argv.unused");
                break;

            case "1":     // Elastoid
                firstState = earlyQuistisTable.Elastoid;
                msg        = string.Format(Translate.Get("read_argv.pattern_fmt"), _options.EarlyQuistis.Capitalize(), Translate.Get("read_argv.elastoid"));
                break;

            case "2":     // Malboro
                firstState = earlyQuistisTable.Malboro;
                msg        = string.Format(Translate.Get("read_argv.pattern_fmt"), _options.EarlyQuistis.Capitalize(), Translate.Get("read_argv.malboro"));
                break;

            case "3":     // Wedge
                firstState = earlyQuistisTable.Wedge;
                msg        = string.Format(Translate.Get("read_argv.pattern_fmt"), _options.EarlyQuistis.Capitalize(), Translate.Get("read_argv.wedge"));
                break;

            default:     // Hex state
                firstState = Convert.ToUInt32(s, fromBase: 16) & 0xffff_ffff;
                searchType = TSearchType.Recovery;
                msg        = string.Format(Translate.Get("read_argv.direct_rng_state_fmt"), firstState);
                break;
            }

            if (searchType == TSearchType.First)
            {
                msg = string.Format(Translate.Get("read_argv.select_fmt"), msg);
                msg = string.Format("{0}: 0x{1:x8}", msg, firstState);
            }

            var state = firstState;
            var count = 0U;

            if (args.Length > 1)
            {
                count = uint.Parse(args[1]);
                var rng = new CardRng(firstState);

                for (var i = 0; i < count; i++)
                {
                    rng.Next();
                }

                msg += "\n" + string.Format(Translate.Get("read_argv.advanced_rng_fmt"), count, rng.State);

                state      = rng.State;
                searchType = TSearchType.Counting;
            }

            if (!silent)
            {
                Console.WriteLine(msg);
            }

            return(firstState, state, count, searchType);
        }
Exemplo n.º 9
0
        static Pattern StringToPattern(string s, Player player, bool fuzzyRanks = false, bool silent = false)
        {
            var rare = player.Rares.Any() ? player.Rares.First() : new int?();

            var cardRegex = new Regex("[0-9a]{4}", RegexOptions.IgnoreCase);
            var ranksArr  = cardRegex.Matches(s).Cast <Match>().Select(x => x.Value).Take(5).ToList();

            if (ranksArr.Count < (rare == null ? 5 : 4))
            {
                Console.WriteLine(string.Format(Translate.Get("str2pattern.UnmatchedInput_fmt"), s));
                return(null);
            }

            var regexInitiative = new Regex("[+-]");
            var initiative      = regexInitiative.Matches(s).Cast <Match>().Select(x => x.Value).Aggregate(new bool?(), (acc, x) => x == "+");

            var customRanksOrder = "urdl".Select(c => _options.RanksOrder.IndexOf(c));
            var urdlArr          = ranksArr.Select(ranks =>
            {
                var ranksNumber = ranks
                                  .Select(c => Convert.ToInt32(c.ToString(), fromBase: 16))
                                  .Select(x => x == 0 ? 10 : x);

                return(customRanksOrder.Select(idx => ranksNumber.ElementAt(idx)).ToArray());
            });

            var idsArr     = urdlArr.Select(urdl => CardTable.ListIdsByUrdl(urdl, fuzzyRanks)).ToList();
            var retryCount = 0;

            while (true)
            {
                if (idsArr.Any(x => x.Count == 0))
                {
                    var emptyNoArr = idsArr.Select((_, idx) => idx + 1).Where(no => idsArr[no - 1].Count == 0);
                    var emptyNoS   = string.Join(", ", emptyNoArr.Select(no => string.Format("#{0}:{1}", no, ranksArr[no - 1])));
                    var errorMsg   = string.Format(Translate.Get("str2pattern.EmptyIDs_fmt"), emptyNoS);

                    retryCount++;

                    if (fuzzyRanks || retryCount > 1)
                    {
                        Console.WriteLine(errorMsg);
                        return(null);
                    }

                    if (!silent)
                    {
                        Console.WriteLine(errorMsg);
                        Console.WriteLine(Translate.Get("str2pattern.read_as_fuzzy"));
                    }

                    idsArr = urdlArr
                             .Select((urdl, idx) => CardTable.ListIdsByUrdl(urdl, fuzzy: emptyNoArr.Contains(idx + 1)))
                             .ToList();

                    continue;
                }

                break;
            }

            var arrExceptUniq = idsArr.Select(ids =>
            {
                if (!fuzzyRanks)
                {
                    return(idsArr.Count(x => x.SequenceEqual(ids)) > 1 ? ids : null);
                }
                else
                {
                    return(ids.Count == 1 && idsArr.Count(x => x.SequenceEqual(ids)) > 1 ? ids : null);
                }
            }).ToList();

            if (arrExceptUniq.Where(x => x != null).Any())
            {
                var duplicatedNoArr = arrExceptUniq.Select((_, idx) => idx + 1).Where(no => arrExceptUniq[no - 1] != null);
                var duplicatedNoS   = string.Join(", ", duplicatedNoArr.Select(no => string.Format("#{0}:{1}", no, ranksArr[no - 1])));
                var errorMsg        = string.Format(Translate.Get("str2pattern.DuplicatedIDs_fmt"), duplicatedNoS);

                Console.WriteLine(errorMsg);
                return(null);
            }

            if (idsArr.Count == 4)
            {
                idsArr.Insert(0, new List <int>()
                {
                    rare.Value
                });
            }

            return(new Pattern()
            {
                Str = s,
                Deck = idsArr,
                Initiative = initiative
            });
        }
Exemplo n.º 10
0
        static uint RareTimer(uint state, Player player)
        {
            var fps = _options.ConsoleFps;

            var start = DateTime.Now.SecondsSinceEpoch();
            var delay = _options.DelayFrame / _options.GameFps;

            var incr       = 0U;
            var incrStart  = delay - (_options.ForcedIncr / _options.GameFps);
            var timerWidth = 8;
            var width      = Math.Min(Console.WindowWidth - 1 - timerWidth, 60);

            var header = "timer".PadRight(timerWidth) + "! " + Translate.Get("prompt.rare_timer");

            Console.WriteLine(header);
            Console.CursorVisible = false;

            while (true)
            {
                var duration = DateTime.Now.SecondsSinceEpoch() - start;

                incr = (uint)Math.Max(
                    Math.Round((duration - incrStart) * _options.GameFps),
                    _options.ForcedIncr + _options.AcceptDelayFrame
                    );

                if (incr <= _options.ForcedIncr + _options.AcceptDelayFrame)
                {
                    incr = _options.ForcedIncr;
                }

                var rareTbl = new int[width].Select((_, idx) => NextRare(state + incr + (uint)idx, player.RareLimit));

                var durationS = (duration - delay).ToString("0.00") + "s" + (rareTbl.First() ? "!" : "");

                var tableS = rareTbl.Select((x, i) =>
                {
                    if (x)
                    {
                        return("*");
                    }
                    else if (i == 0)
                    {
                        return("!");
                    }
                    else
                    {
                        return("-");
                    }
                }).Aggregate((acc, x) => acc + x);

                Console.Write(durationS.PadRight(timerWidth) + tableS + "\r");

                Thread.Sleep(1000 / fps);

                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
                {
                    Console.WriteLine();
                    Console.CursorVisible = true;
                    return(incr);
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            _args = args;

            try
            {
                var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
                _options = Options.ParseFromFile(settingsPath);
            }
            catch (Exception)
            {
                Console.WriteLine(Translate.Get("settings_error"));
                return;
            }

            if (_args.Length == 0)
            {
                if (_options.Interactive)
                {
                    _args = PromptArgs();
                }
                else
                {
                    ShowHelp();
                    return;
                }
            }

            var(firstState, state, count, searchType) = ReadArgs(_args);
            var player = PlayerTable.Get(_options.Player);

            if (searchType == TSearchType.First)
            {
                while (true)
                {
                    Console.WriteLine();
                    Console.WriteLine(Translate.Get("prompt.second_game_method"));
                    var line = Prompt();

                    if (line.StartsWith("h"))
                    {
                        ShowPatternHelp();
                    }
                    else if (line.StartsWith("q"))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        var pattern = StringToPattern(line, player);

                        if (pattern == null)
                        {
                            continue;
                        }

                        var scanner = OpeningScanner(state, player, searchType);
                        StartSearch(scanner, pattern, player);
                    }
                }
            }
            else
            {
                while (true)
                {
                    Console.WriteLine();
                    Console.WriteLine(Translate.Get("prompt.first_game_method"));
                    var line = Prompt();

                    if (line.StartsWith("h"))
                    {
                        ShowPatternHelp();
                    }
                    else if (line.StartsWith("q"))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        RareSearch(state, player, counting: searchType == TSearchType.Counting);
                    }
                }
            }
        }