Exemplo n.º 1
0
        public static string[][] GenRandom(string password, string alphabet, int n)
        {
            GenPasswordHash(password);

            var source = StringToArray(alphabet);

            var result = new string[n][];

            for (var i = 0; i < n; i++)
            {
                result[i] = RandomSelect <string> .Group(source);
            }

            return(result);
        }
Exemplo n.º 2
0
        static void DrunkWalkItr(NMap map, NLocate currentLoc, Stack <NLocate> rounte, byte val, int step = 1)
        {
            if (rounte.Count > map.DataSize() / (4 * step))
            {
                Console.WriteLine("I am awake !!!");
                return;
            }

            map.SetBlock(currentLoc, val);
            List <NLocate> locs           = new List <NLocate>();
            List <NLocate> stepAroundLocs = new List <NLocate>();

            stepAroundLocs.Add(new NLocate(currentLoc.X + step, currentLoc.Y));
            stepAroundLocs.Add(new NLocate(currentLoc.X - step, currentLoc.Y));
            stepAroundLocs.Add(new NLocate(currentLoc.X, currentLoc.Y + step));
            stepAroundLocs.Add(new NLocate(currentLoc.X, currentLoc.Y - step));
            //Console.WriteLine(map.Print());
            foreach (var l in stepAroundLocs)
            {
                if ((map.GetBlock(l) != val) && (map.WithIn(l)))
                {
                    locs.Add(l);
                }
            }
            if (locs.Count > 0)
            {
                var dLoc = RandomSelect <NLocate> .Select(locs);

                Line(map, currentLoc, dLoc, val);
                rounte.Push(dLoc);
                DrunkWalkItr(map, dLoc, rounte, val);
            }
            else
            {
                rounte.Pop();
                if (rounte.Count > 0)
                {
                    DrunkWalkItr(map, rounte.Peek(), rounte, val);
                }
                else
                {
                    Console.WriteLine("no way!!!");
                    return;
                }
            }
        }
Exemplo n.º 3
0
        private string RollSelectionMessage(RandomSelect randomSelect)
        {
            StringBuilder builder = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(randomSelect.Title))
            {
                builder.AppendLine(randomSelect.Title);
            }
            else
            {
                builder.AppendLine($@"骰子骰子咕噜转…………");
            }
            builder.Append($@"结果是:""");
            builder.Append($@"{randomSelect.Next()}");
            builder.Append(@"""");

            return(builder.ToString());
        }
Exemplo n.º 4
0
        public static NMap CaveWallMap(int width, int height, float rate, int holeLeft)//dig map
        {
            NMap map = new NMap(width, height);

            map.Noise(rate);
            CellularAutomata2D rule = new CellularAutomata2D("s45678b5678");

            map = rule.Run(map, 3);
            var blobs = NBlob.Find(map, 255);

            blobs.FillByLeftBlob(map, holeLeft, 0);
            blobs.NoiseConnect(map, 255);

            map = map.InverseVal();
            bool    HorV     = RandomNum.Roll(0.5f);
            NLocate Entrance = new NLocate();
            NLocate Exit     = new NLocate();

            if (HorV)
            {
                Entrance = RandomSelect <NLocate> .Select(new List <NLocate>(map.LeftLocates(0))).Right();

                Exit = RandomSelect <NLocate> .Select(new List <NLocate>(map.RightLocates(0))).Left();
            }
            else
            {
                Entrance = RandomSelect <NLocate> .Select(new List <NLocate>(map.TopLocates(0))).Down();

                Exit = RandomSelect <NLocate> .Select(new List <NLocate>(map.BottomLocates(0))).Up();
            }
            map.SetBlock(Entrance.Square(1), 0);
            map.SetBlock(Exit.Square(1), 0);
            map.SetBlock(Entrance, (byte)DungeonBuilding.Port);
            map.SetBlock(Exit, (byte)DungeonBuilding.Port);

            NLocationRecogition.FindTreasure(map, 3);
            NLocationRecogition.FindDeadEnd(map, 3);

            NLocationRecogition.FindPassage(map, 4);

            return(map);
        }
Exemplo n.º 5
0
        bool RollSelection(TelegramBotClient bot, Message message, string messageBody)
        {
            string[] lines = messageBody.Split('\n');

            if (!lines[0].StartsWith("#", StringComparison.Ordinal))
            {
                return(false);
            }
            string       title        = lines[0].Substring(1);
            RandomSelect randomSelect = new RandomSelect(title, lines.Skip(1).ToArray());

            bot.SendTextMessageAsync(
                message.Chat.Id,
                RollSelectionMessage(randomSelect),
                Telegram.Bot.Types.Enums.ParseMode.Markdown,
                replyToMessageId: message.MessageId
                );

            return(true);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            RandomSelect rs = new RandomSelect();

            //rs.ResetData();

            Process process = new Process();

            process.StartInfo.FileName = rs.RandomStart();

            try
            {
                process.Start();
            }
            catch (Exception)
            {
                rs.ResetData();
                throw;
            }
        }
Exemplo n.º 7
0
 public string[] Words(int numberWords)
 {
     return(RandomSelect <string> .Group(_randomWords, numberWords));
 }