示例#1
0
    def addai(self, gender, allowedwords):
        if len(self.players) >= self.settings.playercount:
            raise gamecore.GameConnectionError()
        if not self.iswaiting():
            raise gamecore.GameConnectionError()

        ainame = None
        attempt = 0
        while not ainame or self.hasplayer(ainame):
            if attempt > 100:
                raise gamecore.GameConnectionError()
            attempt += 1
            ainame, cls = ai.generate_name_ai(gender)
        aiplayer = cls(allowedwords)
        attemptlst = []
        for roundcards in self.cards:
            word = aiplayer.roundattempt(roundcards)
            attemptlst.append(word)
        self.aiattempts[ainame] = attemptlst
        self.addplayer(ainame, human=False)
示例#2
0
    def creategame(self, player, minplayercount=2, aicount=0):
        if not isinstance(player, (str, unicode)):
            player = player.playername

        if aicount > minplayercount:
            raise ValueError, "AIs count exceeds players limit o_O"
        self._maintain()
        self.leavegame(player)

        game = Game()
        game.settings.playercount = minplayercount
        game.addplayer(player, creator=True)

        game.cards =  []
        curdeck = self.deckfactory()
        for roundcards in curdeck:
            game.cards.append([])
            l = game.cards[-1]
            for card in roundcards:
                l.append(GameCard(letter=card.letter, score=card.score))

        for __ in xrange(aicount):
            ainame = None
            while not ainame or game.hasplayer(ainame):
                gender = random.choice(('male', 'female', 'vasserman'))
                ainame, cls = ai.generate_name_ai(gender)
            aiplayer = cls(self.allowedwords)
            attemptlst = []
            for roundcards in curdeck:
                word = aiplayer.roundattempt(roundcards)
                attemptlst.append(word)
            game.aiattempts[ainame] = attemptlst
            game.addplayer(ainame, human=False)

        game.save()
        logging.info(
            u"[gameconnect] player '{0}' created a game".format(
                player).encode('utf-8'))
        return game.getstate(player)