def test_app_inventor_scoreboard_ordering(): scores = {'a': 12, 'b': 35, 'c': 19, 'd': 85, 'e': 5} scoreboard_list = scoreboard.format_scoreboard_for_app_inventor(scores) expected = [[85, 'd'], [35, 'b'], [19, 'c'], [12, 'a'], [5, 'e']] assert scoreboard_list == expected
def end_turn_command(instance, player, arguments): """ End the current turn and start a new one. Args: instance: The GameInstance database model for this operation. player: The player submitting the card. Must be the current leader. arguments: A two item list consisting of the round number to end and the selected winning card. If the command is for the wrong round, a four item list with an error string as its first element will be returned. The remaining elements are the player's hand, the current round and the current characteristic card to respond to. No other action will be taken. Ends the current turn and adds 1 point to the score of the player who submitted the winning card. If that player has reached the winning score, an 'ata_game_over' message will be sent to all players. The game over message content will be a three item list as its contents. The list contains the final round number, the winning card and the final scoreboard. Otherwise, sends an 'ata_new_round' message to all players. The new round message contents will be a five item list with the round number, the new characteristic card, the previous round winner, the winning card and the current scoreboard. Returns: If the command was for the correct round, returns the content of whichever message was sent to all players as described above. Raises: ValueError if player is not the leader. KeyError if no player has submitted the winning card. """ if int(arguments[0]) != instance.ata_round: hand = card_game.get_player_hand(instance, player) return ['You tried to end a turn that has already ended. ' + 'Please try again.', hand, instance.ata_round, instance.ata_char_card] missing_player = check_players(instance) if missing_player: return missing_player instance.check_leader(player) card = arguments[1] winner = None for player, submitted_card in get_submissions_dict(instance).items(): if card == submitted_card: winner = player break if winner == None: raise KeyError('No player has submitted the card %s.' % card) board = scoreboard.add_to_score(instance, winner, 1) # Check to see if anyone has won instance.leader = winner if board[winner] == winning_score: return end_game(instance, card) setup_new_round(instance) return_scoreboard = scoreboard.format_scoreboard_for_app_inventor(board) content = [instance.ata_char_card, return_scoreboard, instance.ata_round, winner, card] instance.create_message(instance.leader, 'ata_new_round', '', content).put() return content
def test_app_inventor_scoreboard_ordering(): scores = {'a' : 12, 'b' : 35, 'c' : 19, 'd' : 85, 'e' : 5} scoreboard_list = scoreboard.format_scoreboard_for_app_inventor(scores) expected = [[85, 'd'], [35, 'b'], [19, 'c'], [12, 'a'], [5, 'e']] assert scoreboard_list == expected