Initial commit.

This commit is contained in:
oddluck 2019-12-07 08:54:25 +00:00
parent 9f2cb8bef5
commit 0f75093efd
13 changed files with 38 additions and 39 deletions

1
CAH/README.md Normal file
View File

@ -0,0 +1 @@
Cards Against Humanity

View File

@ -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

View File

@ -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)))

View File

@ -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]))

View File

@ -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):

View File

@ -1,2 +0,0 @@
supybot-cah
===========

View File

@ -1 +0,0 @@
# Stub so local is a module, used for third-party modules