diff --git a/CAH/README.md b/CAH/README.md new file mode 100644 index 0000000..203a8bb --- /dev/null +++ b/CAH/README.md @@ -0,0 +1 @@ +Cards Against Humanity diff --git a/__init__.py b/CAH/__init__.py similarity index 88% rename from __init__.py rename to CAH/__init__.py index 96e255f..2ffef00 100644 --- a/__init__.py +++ b/CAH/__init__.py @@ -12,6 +12,7 @@ here. This should describe *what* the plugin does. import supybot import supybot.world as world +import importlib # Use this for the version of this plugin. You may wish to put a CVS keyword # in here if you're keeping the plugin in CVS or some similar system. @@ -27,14 +28,14 @@ __contributors__ = {} # This is a url where the most recent plugin package can be downloaded. __url__ = '' # 'http://supybot.com/Members/yourname/Cah/download' -import config -import plugin -reload(plugin) # In case we're being reloaded. +from . import config +from . import plugin +importlib.reload(plugin) # In case we're being reloaded. # Add more reloads here if you add third-party modules and want them to be # reloaded when this plugin is reloaded. Don't forget to import them as well! if world.testing: - import test + from . import test Class = plugin.Class configure = config.configure diff --git a/cah.py b/CAH/cah.py similarity index 86% rename from cah.py rename to CAH/cah.py index 6405110..6733550 100644 --- a/cah.py +++ b/CAH/cah.py @@ -1,7 +1,7 @@ from random import choice import os import json -import test +from . import test # Settings you change card_folder = 'cards' @@ -70,7 +70,7 @@ class Card(object): self.id = id self.type = type self.text = text - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): setattr(self, key, value) def __str__(self): return self.text @@ -104,7 +104,7 @@ class Game(object): def end_round(self, winner_name, cards_played): self.score_keeping(winner_name) - for player in cards_played.keys(): + for player in list(cards_played.keys()): if isinstance(cards_played[player], Card): cards_played[player] = [cards_played[player]] for card in cards_played[player]: @@ -112,9 +112,9 @@ class Game(object): self.players[player].deal_hand(self.deck) def score_keeping(self, player_name): - if not self.players.has_key(player_name): + if player_name not in self.players: raise NameError - if self.score.has_key(player_name): + if player_name in self.score: self.score[player_name] += 1 else: self.score[player_name] = 1 @@ -122,10 +122,10 @@ class Game(object): def cardSubmit(self): for player in self.players: cardInput = None - cardRange = range(5) + cardRange = list(range(5)) while cardInput not in cardRange: try: - cardInput = int(raw_input('%s Pick a Card: ' % player)) - 1 + cardInput = int(input('%s Pick a Card: ' % player)) - 1 except ValueError: pass @@ -151,25 +151,25 @@ class PlayerHand(object): return card_text def showHand(self): - print '%s' % self.text_list() + print('%s' % self.text_list()) if __name__=="__main__": game = Game(['Bear','Swim', 'Jazz']) - print "\nGame started with the following players: %s \n" % game.players.keys() + print("\nGame started with the following players: %s \n" % list(game.players.keys())) round = game.next_round() - print "The first question is: %s \n" % game.question.text + print("The first question is: %s \n" % game.question.text) - print "Swim's hand the easy way:" + print("Swim's hand the easy way:") game.players['Swim'].showHand() - print "\nJazz's hand in a weird way" + print("\nJazz's hand in a weird way") round['hands']['Jazz'].showHand() - print "\nBear's hand the hard way:" + print("\nBear's hand the hard way:") for index, card in enumerate(game.players['Bear'].card_list): - print '%s: %s' % (index + 1, card.text) + print('%s: %s' % (index + 1, card.text)) - print "\nEnd the round by picking a random cards amd winner: %s" % str(test.build_end_round_data(game)) + print("\nEnd the round by picking a random cards amd winner: %s" % str(test.build_end_round_data(game))) diff --git a/cards/__init__.py b/CAH/cards/__init__.py similarity index 100% rename from cards/__init__.py rename to CAH/cards/__init__.py diff --git a/cards/answer_cards b/CAH/cards/answer_cards similarity index 100% rename from cards/answer_cards rename to CAH/cards/answer_cards diff --git a/cards/question_cards b/CAH/cards/question_cards similarity index 100% rename from cards/question_cards rename to CAH/cards/question_cards diff --git a/cards/question_cards1 b/CAH/cards/question_cards1 similarity index 100% rename from cards/question_cards1 rename to CAH/cards/question_cards1 diff --git a/cards/question_cards2 b/CAH/cards/question_cards2 similarity index 100% rename from cards/question_cards2 rename to CAH/cards/question_cards2 diff --git a/config.py b/CAH/config.py similarity index 100% rename from config.py rename to CAH/config.py diff --git a/plugin.py b/CAH/plugin.py similarity index 97% rename from plugin.py rename to CAH/plugin.py index 6802f35..b4b542f 100644 --- a/plugin.py +++ b/CAH/plugin.py @@ -39,7 +39,7 @@ from random import randint import operator -from cah import Game, base_directory, card_folder, blank_format +from .cah import Game, base_directory, card_folder, blank_format import time import os @@ -108,7 +108,7 @@ class Cah(callbacks.Plugin): def _findHighScore(self, scores): highscore = [] - for nick, score in scores.iteritems(): + for nick, score in scores.items(): if len(highscore) == 0: highscore.append([nick, score]) elif highscore[0][1] < score: @@ -126,10 +126,10 @@ class Cah(callbacks.Plugin): ties = [] winningCanidate = [] canidatesById = [] - for nick in self.cardsPlayed.keys(): + for nick in list(self.cardsPlayed.keys()): canidatesById.append(nick) - for canidateNumber, count in votes.iteritems(): + for canidateNumber, count in votes.items(): canidate = canidatesById[int(canidateNumber)] count = int(count) if len(winningCanidate) == 0: @@ -203,9 +203,9 @@ class Cah(callbacks.Plugin): #scores = [] winner = None formattedScores = [] - print cah.score + print(cah.score) winner = self._findHighScore(cah.score) - for name, score in cah.score.iteritems(): + for name, score in cah.score.items(): formattedScores.append("%s: %d" % (name, score)) self._msg(channel, "Game Over! %s is the Winner! Scores: %s " % (winner[0][0], ", ".join(formattedScores))) @@ -249,7 +249,7 @@ class Cah(callbacks.Plugin): game = self game.voting = False winner = self._tallyVotes(game.votes) - print winner + print(winner) game.game.end_round(winner[0][0], self.cardsPlayed) game.voted = [] game._msg(self.channel, "%s wins the round!" % ircutils.bold(winner[0][0])) diff --git a/test.py b/CAH/test.py similarity index 85% rename from test.py rename to CAH/test.py index 9b58d0d..3f25f52 100644 --- a/test.py +++ b/CAH/test.py @@ -1,6 +1,6 @@ __author__ = 'Bear' -from cah import * +from .cah import * def test_cards_will_be_unique(deck=None, player_list = None): """ @@ -10,7 +10,7 @@ def test_cards_will_be_unique(deck=None, player_list = None): deck=Deck() if player_list is None: player_list = {'one': PlayerHand(deck),'two': PlayerHand(deck) } - for value in player_list.values(): + for value in list(player_list.values()): for card in value.card_list: assert card.text not in deck.answerDb @@ -27,7 +27,7 @@ def test_card_parsing(deck=None): def test_game(): game = Game(['Bear','Swim', 'Jazz']) test_cards_will_be_unique(deck=game.deck, player_list= game.players) - for player in game.players.keys(): + for player in list(game.players.keys()): hand = game.players[player] test_player_hand(hand) test_round_advancement(game) @@ -42,16 +42,16 @@ def test_round_advancement(game=None): while round < game.round_limit: bot_gets = game.next_round() assert isinstance(bot_gets, dict) - assert bot_gets.has_key('question') - assert game.has_key('question') - assert bot_gets.has_key('hands') + assert 'question' in bot_gets + assert 'question' in game + assert 'hands' in bot_gets test_end_round(game) def build_end_round_data(game): - winner = choice(game.players.keys()) + winner = choice(list(game.players.keys())) cards_played = {} #Get random cards from player's hand to satisfy the question card - for player in game.players.keys(): + for player in list(game.players.keys()): player_cards = game.players[player].card_list[:game.question.answers] cards_played[player] = player_cards #player_cards is a deque object -> tuple(list,maxlen) return {'winner': winner, 'cards_played': cards_played} @@ -63,13 +63,13 @@ def test_end_round(game=None): game.question.answers = 2 fake_end_round = build_end_round_data(game) game.end_round(fake_end_round['winner'],fake_end_round['cards_played']) - for player in game.players.keys(): + for player in list(game.players.keys()): assert len(game.players[player].card_list) == 5 if isinstance(fake_end_round['cards_played'][player], Card): fake_end_round['cards_played'][player] = list(fake_end_round['cards_played'][player]) for card in fake_end_round['cards_played'][player]: assert card not in game.players[player].card_list - assert game.score.has_key(fake_end_round['winner']) + assert fake_end_round['winner'] in game.score def test_player_hand(hand=None): diff --git a/README.md b/README.md deleted file mode 100644 index 63b0f35..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -supybot-cah -=========== \ No newline at end of file diff --git a/local/__init__.py b/local/__init__.py deleted file mode 100644 index e86e97b..0000000 --- a/local/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Stub so local is a module, used for third-party modules