Exemplo n.º 1
0
def play_result_string(play_result, current_player_name, last_player_name=None):

	string = str(current_player_name) + ' '

	if play_result.action == uno.ACTION_PLAY:
		string += 'played '

		string += card_string(play_result.card)

		if play_result.new_color:
			string += ' with new color ' + card_color_string(play_result.new_color)
		
		string += '.'

		if play_result.uno:
			string += ' UNO!'

	elif play_result.action == uno.ACTION_DRAW:
		string += 'drew ' + str(play_result.num_draw) + ' ' + plural(play_result.num_draw, 'card', 'cards') + '.'
	elif play_result.action == uno.ACTION_PASS:
		string += 'passed.'

	elif play_result.action == uno.ACTION_CALL_BLUFF:
		string += 'called ' + str(last_player_name) + '\'s bluff... '

		if play_result.bluffed:
			string += 'and it was a bluff. ' + str(last_player_name) + ' received ' + str(play_result.num_draw) + ' ' + plural(play_result.num_draw, 'card', 'cards') + '.'
		else:
			string += 'and it was not a bluff. ' + str(current_player_name) + ' received ' + str(play_result.num_draw) + ' ' + plural(play_result.num_draw, 'card', 'cards') + '.'

	return string
Exemplo n.º 2
0
def status():

    text = ''

    if game.direction == 1:
        player_numbers = range(game.num_players)
    else:
        player_numbers = range(game.num_players - 1, -1, -1)

    for for_player_number in player_numbers:

        num_cards = len(game.player_cards[for_player_number])
        text += str(for_player_number) + ': ' + str(num_cards) + ' ' + plural(
            num_cards, 'card', 'cards')

        if game.winner == None:
            if game.current_player == for_player_number:
                text += ' <- Current'
            elif game.get_next_player() == for_player_number:
                text += ' <- Next'
        elif game.winner == for_player_number:
            text += ' <- Winner'

        text += '\n'

    text += 'Current card: ' + unoparser.card_string(game.current_card) + '\n'
    if game.current_color != game.current_card.color:
        text += 'Chosen color: ' + unoparser.card_color_string(
            game.current_color) + '\n'

    player_number = game.current_player

    text += 'Your cards: '

    if len(game.player_cards[player_number]) != 0:
        text += unoparser.play_intent_list_string(
            game.get_play_intents_cards(player_number))
    else:
        text += 'None!'

    text += '\n'

    print(text)

    return text
Exemplo n.º 3
0
 def _plural(word):
     return plural(word, custom=quantify_custom_plurals)
Exemplo n.º 4
0
             'man': 'men',
             'mailman': 'mailmen',
             'knife': 'knives',
             'wife': 'wives',
             'tableau': 'tableaux',
             'elf': 'elves',
             'shelf': 'shelves',
             'sheep': 'sheep',
             'deer': 'deer',
             'fish': 'fish',
             'moose': 'moose',
             'aircraft': 'aircraft',
             'series': 'series',
             'haiku': 'haiku',
             'delf': 'delfs',
             'pelf': 'pelfs',
             'human': 'humans',
             'roman': 'romans',
             'lowlife': 'lowlifes',
		  }

for noun, pluralnoun in KnownValues.nouns.items():
    func = lambda self, noun=noun, pluralnoun=pluralnoun: \
           KnownValues.failUnlessEqual(self, plural(noun), pluralnoun)
    func.__doc__ = "%s --> %s" % (noun, pluralnoun)
    instanceMethod = new.instancemethod(func, None, KnownValues)
    setattr(KnownValues, "test_%s" % noun, instanceMethod)

if __name__ == "__main__":
    unittest.main()
Exemplo n.º 5
0
	def __str__(self):
		days 						= '%d %s ' % (self.d, plural   (self.d, 'day'))   if self.d else ''
		months 						= '%d %s ' % (self.m, plural   (self.m, 'month')) if self.m else ''
		years  						= '%d %s ' % (self.y, plural   (self.y, 'year'))  if self.y else ''
		return ('%s%s%s' % (years, months, days)).strip()
Exemplo n.º 6
0
def get_status_text(room_id,
                    user_id,
                    show_room_info=True,
                    show_your_turn=False):

    text = ''

    if room_id:
        users = server.select_users_info_in_room(room_id)
        game = server.select_game(room_id)

        configs = server.get_room_configs(room_id)
        apply_room_configs(configs, game)

        if show_room_info:
            num_users = len(users)
            text += ('You are currently in room number ' + str(room_id) +
                     ', which has ' + str(num_users) + ' ' +
                     plural(num_users, 'user', 'users') + '.\n')

        if show_your_turn:
            text += 'It is your turn.\n'

        if game:
            if game.direction == -1:
                users.reverse()

        for for_player_number, for_user_id in users:

            for_user_name = get_user_name(for_user_id)

            if game:
                num_cards = len(game.player_cards[for_player_number])
                text += (str(for_player_number) + ': ' + for_user_name + ' (' +
                         str(num_cards) + ' ' +
                         plural(num_cards, 'card', 'cards') + ')')

                if game.winner == None:
                    if game.current_player == for_player_number:
                        text += ' &lt;- Current'
                    elif game.get_next_player() == for_player_number:
                        text += ' &lt;- Next'
                elif game.winner == for_player_number:
                    text += ' &lt;- Winner'

            else:
                text += '- ' + for_user_name

            text += '\n'

        if game:

            text += 'Current card: ' + unoparser.card_string(
                game.current_card) + '\n'
            if game.current_color != game.current_card.color:
                text += 'Chosen color: ' + unoparser.card_color_string(
                    game.current_color) + '\n'

            player_number = next((for_player_number
                                  for for_player_number, for_user_id in users
                                  if for_user_id == user_id))

            text += 'Your cards: '

            if len(game.player_cards[player_number]) != 0:
                text += unoparser.play_intent_list_string(
                    game.get_play_intents_cards(player_number))
            else:
                text += 'None!'

            text += '\n'

    else:
        text += 'You are currently not joined in any room.\n'

    return text
Exemplo n.º 7
0
 def _plural(word):
     return plural(word, custom=quantify_custom_plurals)
Exemplo n.º 8
0
        'mailman': 'mailmen',
        'knife': 'knives',
        'wife': 'wives',
        'tableau': 'tableaux',
        'elf': 'elves',
        'shelf': 'shelves',
        'sheep': 'sheep',
        'deer': 'deer',
        'fish': 'fish',
        'moose': 'moose',
        'aircraft': 'aircraft',
        'series': 'series',
        'haiku': 'haiku',
        'delf': 'delfs',
        'pelf': 'pelfs',
        'human': 'humans',
        'roman': 'romans',
        'lowlife': 'lowlifes',
    }


for noun, pluralnoun in list(KnownValues.nouns.items()):
    func = lambda self, noun=noun, pluralnoun=pluralnoun: \
           KnownValues.failUnlessEqual(self, plural(noun), pluralnoun)
    func.__doc__ = "%s --> %s" % (noun, pluralnoun)
    instanceMethod = new.instancemethod(func, None, KnownValues)
    setattr(KnownValues, "test_%s" % noun, instanceMethod)

if __name__ == "__main__":
    unittest.main()
Exemplo n.º 9
0
now = maya.now().datetime()

days_in = (now - the_past).days
days_left = (the_future - now).days
total_days = (the_future - the_past).days

messages = [
    ##    u"Only {} days of Zelenskiy left!".format(
    ##        humanize.intcomma(days_left),
    ##    ),
    ##    u"Loading new president…\n{}\n{:0.1f}% complete".format(
    ##        progress_bar(float(days_in) / total_days, 30),
    ##        (float(days_in) / total_days) * 100.0,
    ##    ),
    u"Зеленському {} {} {}!".format(
        plural(days_left, u'лишився', u'лишилось', u'лишилось'),
        humanize.intcomma(days_left),
        plural(days_left, u'день', u'дні', u'днів')),
    u"Завантаження нового Президента…\n{}\n{:0.1f}% виконано".format(
        progress_bar(float(days_in) / total_days, 31),
        (float(days_in) / total_days) * 100.0,
    )
]

message = random.choice(messages)

if dry_run:
    logging.info(
        "In dry run mode. Would have tweeted (in reply to %s):\n\n%s\n",
        previous_tweet_id, message)
else: