示例#1
0
    def stateToAscii(self, state):
        rows = []
        table = BeautifulTable()
        for row in state:
            for cell in row:
                rows.append(str(cell))
            table.append_row(rows)
            rows.clear()

        return table.__str__()
    def __repr__(self):
        if not self.has_tournament_started:
            raise Warning(
                'Trying to print tournament results while tournament has not even started'
            )
        if not self.is_tournament_over:
            raise Warning(
                'Trying to print tournament results while tournament is not over'
            )
        table = BeautifulTable()
        table.column_headers = [
            'Contestant name', 'Matches won', 'Matches played', 'Time played'
        ]

        sort_by_wins = lambda x: x[1].wins
        sorted_contestants = sorted(list(self.contestant_statistics.items()),
                                    key=sort_by_wins,
                                    reverse=True)
        for contestant, statistics in sorted_contestants:
            table.append_row([
                contestant.ai_name, statistics.wins, statistics.played_matches,
                statistics.played_time
            ])
        return table.__str__()