Esempio n. 1
0
File: bblocks.py Progetto: Voder/PBE
    def ai_move(self, player):
        """Randomly choose between returning the move closest to completing a tile or a random move."""
        tiles = [t for t in self if self.valid_move(player, t)]

        def to_max(t): return t.maxnum - t.num
        tiles.sort(key=to_max)
        return rndchoice( [first(tiles), rndchoice(tiles)] )
Esempio n. 2
0
File: words.py Progetto: Voder/PBE
    def guess(self, i, letter):
        """Reveal all instances of `l` if word[i] == `l` & reveal random letter in one other word."""
        if i in self.hidden and self.word[i] == letter:
            self.reveal(letter)

            L = [w for w in words if w.hidden and w != self]
            if L: rndchoice(L).randreveal()
            return True
Esempio n. 3
0
    def ai_move(self, player):
        """Randomly choose between returning the move closest to completing a tile or a random move."""
        tiles = [t for t in self if self.valid_move(player, t)]

        # tiles.sort(key=to_max)
        to_max = lambda t: t.maxnum - t.num
        loc = rndchoice( [min(tiles, key=to_max), rndchoice(tiles)] )
        if loc == self.current:
            self.hl_visible = False
        return loc
Esempio n. 4
0
def rndmove(**args):
    '''Function to return a random move

    args -- arguments for the functions, if no weights are included, it will default to 33/33/33
    '''

    if "weights" in args.keys():
        return ''.join(
            rndchoice(population=["rock", "paper", "scissors"],
                      weights=args["weights"]))
    else:
        return ''.join(
            rndchoice(population=["rock", "paper", "scissors"],
                      weights=[0.3333, 0.3334, 0.3333]))
Esempio n. 5
0
 async def slap(self, ctx, *, user: discord.Member=None):
     """Slap a user"""
     botid = self.bot.user.id
     if user is None:
         user = ctx.message.author
         await self.bot.say("Dont make me slap you instead " + user.name)
     elif user.id == botid:
         user = ctx.message.author
         botname = self.bot.user.name
         await self.bot.say("-" + botname + " slaps " + user.mention +
                            " multiple times with " +
                            (rndchoice(self.items) + "-"))
     else:
         await self.bot.say("-slaps " + user.name + " with " +
                            (rndchoice(self.items) + "-"))
Esempio n. 6
0
 async def slap(self, ctx, *, user: discord.Member = None):
     """Slap a user"""
     botid = self.bot.user.id
     if user is None:
         user = ctx.message.author
         await self.bot.say("Dont make me slap you instead " + user.name)
     elif user.id == botid:
         user = ctx.message.author
         botname = self.bot.user.name
         await self.bot.say("*" + botname + " slaps " + user.mention +
                            " multiple times with " +
                            (rndchoice(self.items) + "*"))
     else:
         await self.bot.say("*slaps " + user.name + " with " +
                            (rndchoice(self.items) + "*"))
Esempio n. 7
0
 async def feed(self, user: discord.Member = None):
     """Force A food Item Down A Users Throat"""
     if user.id == self.bot.user.id:
         await self.bot.say(":skull: -Dies- :skull:")
         return
     await self.bot.say("-forces {} down {}'s"
                        " throat-".format(rndchoice(self.items), user.name))
Esempio n. 8
0
 async def _sing(self, ctx):
     """Makes Cal Bot sing"""
     if self.downloader["DOWNLOADING"]:
         await self.bot.say("I'm already downloading a track.")
         return
     msg = ctx.message
     if await self.check_voice(msg.author, msg):
         if not self.music_player.is_playing():
                 self.queue = []
                 await self.play_video(rndchoice(self.sing))
         else:
             if await self.is_alone_or_admin(msg):
                 self.queue = []
                 await self.play_video(rndchoice(self.sing))
             else:
                 await self.bot.say("I'm already playing music for someone else at the moment.")
 def getChoiceToDefeatHuman(self, guess):
     """
     Return an option which will defeat what the classifier
     has calculated that the human player will choose.
     Called by self.getBotChoice()
     """
     return rndchoice(self.winningChoices[guess])
Esempio n. 10
0
 async def rotate_avatar(self, m):
     now = datetime.utcnow()
     if not self.last_avatar_change or (now-self.last_avatar_change).total_seconds() >= self.delay*6:
         self.last_avatar_change = now
         self.last_avatar_name = rndchoice([p for p in self.avatars if self.last_avatar_name != p])
         # print(self.avatars[self.last_avatar_name])
         asyncio.ensure_future(self.edit_profile(avatar=self.avatars[self.last_avatar_name]))
Esempio n. 11
0
 async def feed(self, user : discord.Member=None):
     """Force A food Item Down A Users Throat"""
     if user.id == self.bot.user.id:
         await self.bot.say(":skull: -Dies- :skull:")
         return
     await self.bot.say("-forces {} down {}'s"
                        " throat-".format(rndchoice(self.items),
                                          user.name))
Esempio n. 12
0
    def gen_hidden(self, hidden):
        """Hide letters according to `hidden`, e.g. if 0.7, hide 70%."""
        length = len(self.word)
        num_to_hide = round(length * hidden)
        letter_range = range(length)

        while len(self.hidden) < num_to_hide:
            self.hide(rndchoice(letter_range))
Esempio n. 13
0
 def simulation(self, s):
     if self.terminal(s) == 0:
         actions = self.available_move(s)
         a = rndchoice(actions)
         s = self.action_result(s, a)
         return s
     else:
         return self.terminal(s)
Esempio n. 14
0
    def gen_hidden(self, hidden):
        """Hide letters according to `hidden`, e.g. if 0.7, hide 70%."""
        length       = len(self.word)
        num_to_hide  = round(length * hidden)
        letter_range = range(length)

        while len(self.hidden) < num_to_hide:
            self.hide(rndchoice(letter_range))
Esempio n. 15
0
 async def slap(self, ctx, *, user : discord.Member=None):
     """Slap a user"""
     if ctx.invoked_subcommand is None:
         if user.id == self.bot.user.id:
             user = ctx.message.author
             await self.bot.say("Dont make me slap you instead " + user.name)
             return
         await self.bot.say("-slaps " + user.name + " with " +
                            (rndchoice(self.items) + "-"))
Esempio n. 16
0
 def mcts_loop(self):
     node = self.node_selection(self.root)
     self.expand_node(node)
     if node.child:
         selected_node = rndchoice(node.child)
     else:
         selected_node = node
     v = self.simulation(deepcopy(selected_node.state))
     self.backpropagation(selected_node, v)
Esempio n. 17
0
    def random_placement(self, ship):
        """Return list of random locations for `ship` length."""
        while True:
            start = self.random_blank()
            dir   = rndchoice(self.dirlist)
            locs  = [ self.next_validloc(start, dir, n) for n in range(ship) ]
            if all(locs): break

        return locs
Esempio n. 18
0
 def _simulation(self, s):
     # Do random playouts
     if self.is_terminal(s) == 0:
         actions = self.actions_available(s)
         a = rndchoice(actions)
         s = self.action_result(s, a)
         return self._simulation(s)
     else:
         return self.is_terminal(s)
Esempio n. 19
0
def c_hand():
    '''comp randomly selects from the available cards in the side deck'''
    hand = []
    side_deck = [-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6]
    for n in range(4):
        choice = rndchoice(side_deck)
        hand.append(choice)
        side_deck.remove(choice)
    return hand
Esempio n. 20
0
 async def slap(self, ctx, *, user: discord.Member = None):
     """Slap a user"""
     if ctx.invoked_subcommand is None:
         if user.id == self.bot.user.id:
             user = ctx.message.author
             await self.bot.say("Kee te stepem picka? " + user.name)
             return
         await self.bot.say("-slaps " + user.name + " with " +
                            (rndchoice(self.items) + "-"))
Esempio n. 21
0
 async def poke(self, ctx, *, user : discord.Member=None):
     """poke a user"""
     if ctx.invoked_subcommand is None:
         if user.id == self.bot.user.id:
             user = ctx.message.author
             await self.bot.say("Dont make me poke you instead " + user.mention)
             return
         await self.bot.say("-pokes " + user.mention + " with " +
                            (rndchoice(self.items) + "-"))
Esempio n. 22
0
    def random_placement(self, ship):
        """Return list of random locations for `ship` length."""
        while True:
            start = self.random_blank()
            dir   = rndchoice(self.dirlist)
            locs  = [ self.next_validloc(start, dir, n) for n in range(ship) ]
            if all(locs): break

        return locs
Esempio n. 23
0
 def random_from_entity(self, entity, count):
     rnd_records = []
     entity_count = entity.all(keys_only=True).count()
     if entity_count < count: count = entity_count
     rnd_numbers = [i for i in range(entity_count)]
     while (len(rnd_records) < count):
         rnd_number = rndchoice(rnd_numbers)
         del rnd_numbers[rnd_numbers.index(rnd_number)]
         rnd_records.append(entity.all().fetch(1, rnd_number)[0])
     return rnd_records
Esempio n. 24
0
 async def poke(self, ctx, *, user: discord.Member = None):
     """poke a user"""
     if ctx.invoked_subcommand is None:
         if user.id == self.bot.user.id:
             user = ctx.message.author
             await self.bot.say("Dont make me poke you instead " +
                                user.mention)
             return
         await self.bot.say("-pokes " + user.mention + " with " +
                            (rndchoice(self.items) + "-"))
Esempio n. 25
0
 def random_status(self, msg):
     current = str(msg.server.me.game)
     new = str(msg.server.me.game)
     if len(self.statuses) > 1:
         while current == new:
             new = rndchoice(self.statuses)
     elif len(self.statuses) == 1:
         new = self.statuses[0]
     else:
         new = None
     return new
Esempio n. 26
0
 def random_status(self, guild, statuses):
     try:
         current = str(guild.me.activity.name)
     except AttributeError:
         current = None
     new_statuses = [s for s in statuses if s != current]
     if len(new_statuses) > 1:
         return rndchoice(new_statuses)
     elif len(new_statuses) == 1:
         return new_statuses[0]
     return current
Esempio n. 27
0
 def random_status(self, msg):
     current = str(msg.server.me.game)
     new = str(msg.server.me.game)
     if len(self.statuses) > 1:
         while current == new:
             new = rndchoice(self.statuses)
     elif len(self.statuses) == 1:
         new = self.statuses[0]
     else:
         new = None
     return new
Esempio n. 28
0
 async def whale(self, ctx, *, user: discord.Member = None):
     """Whale a user"""
     if ctx.invoked_subcommand is None:
         if user.id == self.bot.user.id:
             user = ctx.message.author
             await self.bot.say("I'm not a whale! I'm a Moo! **Chomp** " +
                                user.name)
             return
         await self.bot.say("-The Filthy Whale " + user.name +
                            " is spotted in their natural habitat " +
                            (rndchoice(self.items) + "-"))
Esempio n. 29
0
    def generate(self):
        if not len(self.accepted_char_edit.toPlainText()):
            return

        self.output_edit.setText("")
        for i in xrange(self.pass_count.value()):
            password = ""
            for j in xrange(self.pass_length.value()):
                password += rndchoice(self.accepted_char_edit.toPlainText())

            self.output_edit.setText(self.output_edit.toPlainText() + password + ("\n" * 2))
Esempio n. 30
0
 async def slap(self, ctx, *, user : discord.Member=None):
     """Slap a user"""
     try:
         if ctx.invoked_subcommand is None:
             if user.id == self.bot.user.id:
                 user = ctx.message.author
                 await self.bot.say("Dont make me slap you instead " + user.name)
                 return
             await self.bot.say(ctx.message.author.mention + " slaps " + user.mention + " with " +
                             (rndchoice(self.items)))
     except:
         self.bot.say("Example Usage: `-slap @User")
Esempio n. 31
0
File: words.py Progetto: Voder/PBE
    def __init__(self, wordlist):
        self.random_reveals = random_reveals
        self.words          = set()

        while len(self.words) < num_words:
            word = Word( rndchoice(wordlist).rstrip() )
            if (limit9 and len(word)>9) or len(word) < 3:
                continue
            self.words.add(word)

        self.words   = list(self.words)
        self.guesses = sum(len(w) for w in self.words) // guesses_divby
Esempio n. 32
0
    def _mcts_loop(self):
        # One loop of MCTS
        # MCTS LOOP : selection -> expansion -> simulation -> backpropagation
        node = self._selection(self.root)
        self._expansion(node)

        if node.child:
            selected_node = rndchoice(node.child)
        else:
            selected_node = node

        v = self._simulation(deepcopy(selected_node.state))
        self._backpropagation(selected_node, v)
Esempio n. 33
0
File: slap.py Progetto: d3fin3d/hnd
 async def slap(self, ctx, *, user: discord.Member = None):
     """Slap a user"""
     try:
         if ctx.invoked_subcommand is None:
             if user.id == self.bot.user.id:
                 user = ctx.message.author
                 await self.bot.say("Dont make me slap you instead " +
                                    user.name)
                 return
             await self.bot.say(ctx.message.author.mention + " slaps " +
                                user.mention + " with " +
                                (rndchoice(self.items)))
     except:
         self.bot.say("Example Usage: `-slap @User")
Esempio n. 34
0
    def run(self):
        moves          = board.get_valid_moves
        player         = rndchoice(players)
        player         = first(players)
        self.textinput = TextInput(board=board)

        while True:
            board.draw()
            move = player.get_random_move() if player.ai else self.get_move(player)
            player.make_move(move)

            # give next turn to enemy OR end game if no turns left, FALLTHRU: current player keeps the turn
            if moves(player.enemy()) : player = player.enemy()
            elif not moves(player)   : versi.game_end()
Esempio n. 35
0
    def __init__(self, wordlist):
        self.random_reveals = random_reveals
        self.words = set()

        while len(self.words) < num_words:
            word = Word(rndchoice(wordlist).rstrip())
            if (limit9 and len(word) > 9) or len(word) < 3:
                continue
            self.words.add(word)

        self.words = list(self.words)
        self.guesses = sum(len(w) for w in self.words) // guesses_divby
        self.current = 0, 0
        self.hl_visible = False
Esempio n. 36
0
 def random_status(self, msg, statuses):
     try:
         current = str(msg.guild.me.activity.name)
     except AttributeError:
         current = None
     try:
         new = str(msg.guild.me.activity.name)
     except AttributeError:
         new = None
     if len(statuses) > 1:
         while current == new:
             new = rndchoice(statuses)
     elif len(statuses) == 1:
         new = statuses[0]
     else:
         new = None
     return new
Esempio n. 37
0
 def random_status(self, msg, statuses):
     try:
         current = str(msg.guild.me.activity.name)
     except AttributeError:
         current = None
     try:
         new = str(msg.guild.me.activity.name)
     except AttributeError:
         new = None
     if len(statuses) > 1:
         while current == new:
             new = rndchoice(statuses)
     elif len(statuses) == 1:
         new = statuses[0]
     else:
         new = None
     return new
Esempio n. 38
0
 async def set_status(self):
     await self.bot.wait_until_ready()
     while True:
         pnbr = len([
             p for p in self.bot.lavalink.players._players.values()
             if p.is_playing
         ])
         if pnbr > 1:
             npstatus = "music in {} servers.."
         elif pnbr == 0:
             npstatus = "No servers playing music at this time.."
         else:
             npstatus = "music in {} server.."
         statuses = [
             npstatus, "k.help | k.invite", "k.help | k.support",
             "{} guilds..", "{} members.."
         ]
         new = rndchoice(statuses)
         if new == "{} guilds..":
             await self.bot.change_presence(
                 status=discord.Status.online,
                 activity=discord.Activity(
                     type=discord.ActivityType.watching,
                     name=new.format(len(self.bot.guilds))))
         elif new == "{} members..":
             await self.bot.change_presence(
                 status=discord.Status.online,
                 activity=discord.Activity(
                     type=discord.ActivityType.watching,
                     name=new.format(
                         len([e.name
                              for e in self.bot.get_all_members()]))))
         elif new == "music in {} server..":
             await self.bot.change_presence(activity=discord.Streaming(
                 name=new.format(pnbr), url="https://www.twitch.tv/snpmv"))
         elif new == "music in {} servers..":
             await self.bot.change_presence(activity=discord.Streaming(
                 name=new.format(pnbr), url="https://www.twitch.tv/snpmv"))
         else:
             await self.bot.change_presence(status=discord.Status.online,
                                            activity=discord.Game(name=new))
         await asyncio.sleep(25)
Esempio n. 39
0
 async def add_xp(self, m):
     a = m.author
     if len(m.content) >= 10 and not a.bot and getattr(m, 'guild', None):
         if not self.is_command.match(m.content):
             u = await self.helpers.get_record('user', m.author.id)
             now = datetime.utcnow().timestamp()
             last_xp = u['timers'].get('last_xp', None)
             if not last_xp or now - last_xp >= 25:
                 xp = self.xp_unit + rndchoice(
                     [1, 2, 2, 2, 2, 2, 3, 3, 4, 3, 2, 2, 4, 15])
                 g = await self.helpers.get_record('server', m.guild.id)
                 u['timers']['last_xp'] = now
                 u['xp']['amount'] = u['xp'].get('amount', 0) + xp
                 await self.helpers.sql_update_record('user', u)
                 if not g.get('users'):
                     g['users'] = []
                 if not [x for x in g['users'] if x['id'] == m.author.id]:
                     g['users'].append({'id': m.author.id, 'xp': 0})
                 u = [x for x in g['users'] if x['id'] == m.author.id][0]
                 u['xp'] = u['xp'] + xp
                 await self.helpers.sql_update_record('server', g)
Esempio n. 40
0
 def random_blank(self):
     return rndchoice(self.locations("blank"))
Esempio n. 41
0
 def create_program(self):
     return [rndchoice(fullcmds)] * randint(1, 6)
Esempio n. 42
0
 def random_blank(self):
     return rndchoice( [loc for loc in self if self[loc]==blank] )
Esempio n. 43
0
 def random_blank(self):
     return rndchoice(self.locations("blank"))
Esempio n. 44
0
        while True:
            cmd = self.textinput.getinput()
            if sudoku.valid_move(*cmd):
                return cmd
            else:
                print(self.textinput.invalid_move)

    def get_move(self):
        while True:
            cmd = self.term.getch()
            try:
                if cmd.isdigit():
                    val = commands.move(int(cmd))
                else:
                    val = commands[cmd]()
                if val:
                    return val
            except KeyError:
                print("invalid command:", cmd)


if __name__ == "__main__":
    board    = SudokuBoard(size, Blank, rndchoice(puzzles))
    sudoku   = Sudoku()
    commands = Commands()

    try:
        BasicInterface().run()
    except KeyboardInterrupt:
        sys.exit()
Esempio n. 45
0
    def random_empty(self)             : return rndchoice(self.tiles_not("mine"))

    def reveal(self, tile):
Esempio n. 46
0
      "/set server %s\n" % (srv) +\
      "/wr\n/reconnect\n/beep\n")
    exit(0)
  except:
    exit(1)

if __name__ == '__main__':

  # generate all the IPs
  for o4 in xrange(2,100):
    servers.append("91.214.237."+str(o4))

  alive = {}
  # test servers
  while len(servers) > 0:

    # pick a random server
    server = rndchoice(servers)
    servers.remove(server)

    result = testserver(server)
    if result > 0:
      alive[server] = result
      if result <= 0.05:
        print server
        useserver(server)

  tmpsrv = sorted(alive.iteritems(), key=lambda srv: srv[1])
  alive = [item[0] for item in tmpsrv]
  useserver(rndchoice(alive))
Esempio n. 47
0
 def randreveal(self):
     self.reveal( self.word[rndchoice(self.hidden)] )
Esempio n. 48
0
 def randreveal(self):
     if self.random_reveals:
         rndchoice( [w for w in self if w.hidden] ).randreveal()
         self.random_reveals -= 1
Esempio n. 49
0
 def create_program(self):
     return [rndchoice(fullcmds)] * randint(1, 6)
Esempio n. 50
0
 def random(self):
     method = getattr(self, rndchoice(fullcmds))
     method()
Esempio n. 51
0
 def random_blank(self) : return rndchoice(self.tiles("blank"))
 def random_unhit(self) : return rndchoice(self.tiles_not("is_hit"))
Esempio n. 52
0
 def random_unhit(self):
     return rndchoice(self.tiles_not("is_hit"))
Esempio n. 53
0
    def random_unhit(self) : return rndchoice(self.tiles_not("is_hit"))

    def next_validloc(self, start, dir, n):
Esempio n. 54
0
def random_line(self):
	return rndchoice(self.lines)
Esempio n. 55
0
 def random_hidden(self)            : return rndchoice(self.locations("hidden"))
 def random_empty(self)             : return rndchoice(self.tiles_not("mine"))
Esempio n. 56
0
 def random(self):
     method = getattr(self, rndchoice(fullcmds))
     method()
Esempio n. 57
0
 def rand_blank(self):
     return rndchoice(self.tiles("blank"))