mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-05-01 07:51:10 -05:00
Initial commit.
This commit is contained in:
parent
9f2cb8bef5
commit
0f75093efd
1
CAH/README.md
Normal file
1
CAH/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Cards Against Humanity
|
@ -12,6 +12,7 @@ here. This should describe *what* the plugin does.
|
|||||||
|
|
||||||
import supybot
|
import supybot
|
||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
|
import importlib
|
||||||
|
|
||||||
# Use this for the version of this plugin. You may wish to put a CVS keyword
|
# 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.
|
# 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.
|
# This is a url where the most recent plugin package can be downloaded.
|
||||||
__url__ = '' # 'http://supybot.com/Members/yourname/Cah/download'
|
__url__ = '' # 'http://supybot.com/Members/yourname/Cah/download'
|
||||||
|
|
||||||
import config
|
from . import config
|
||||||
import plugin
|
from . import plugin
|
||||||
reload(plugin) # In case we're being reloaded.
|
importlib.reload(plugin) # In case we're being reloaded.
|
||||||
# Add more reloads here if you add third-party modules and want them to be
|
# 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!
|
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||||
|
|
||||||
if world.testing:
|
if world.testing:
|
||||||
import test
|
from . import test
|
||||||
|
|
||||||
Class = plugin.Class
|
Class = plugin.Class
|
||||||
configure = config.configure
|
configure = config.configure
|
@ -1,7 +1,7 @@
|
|||||||
from random import choice
|
from random import choice
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import test
|
from . import test
|
||||||
|
|
||||||
# Settings you change
|
# Settings you change
|
||||||
card_folder = 'cards'
|
card_folder = 'cards'
|
||||||
@ -70,7 +70,7 @@ class Card(object):
|
|||||||
self.id = id
|
self.id = id
|
||||||
self.type = type
|
self.type = type
|
||||||
self.text = text
|
self.text = text
|
||||||
for key, value in kwargs.iteritems():
|
for key, value in kwargs.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.text
|
return self.text
|
||||||
@ -104,7 +104,7 @@ class Game(object):
|
|||||||
|
|
||||||
def end_round(self, winner_name, cards_played):
|
def end_round(self, winner_name, cards_played):
|
||||||
self.score_keeping(winner_name)
|
self.score_keeping(winner_name)
|
||||||
for player in cards_played.keys():
|
for player in list(cards_played.keys()):
|
||||||
if isinstance(cards_played[player], Card):
|
if isinstance(cards_played[player], Card):
|
||||||
cards_played[player] = [cards_played[player]]
|
cards_played[player] = [cards_played[player]]
|
||||||
for card in cards_played[player]:
|
for card in cards_played[player]:
|
||||||
@ -112,9 +112,9 @@ class Game(object):
|
|||||||
self.players[player].deal_hand(self.deck)
|
self.players[player].deal_hand(self.deck)
|
||||||
|
|
||||||
def score_keeping(self, player_name):
|
def score_keeping(self, player_name):
|
||||||
if not self.players.has_key(player_name):
|
if player_name not in self.players:
|
||||||
raise NameError
|
raise NameError
|
||||||
if self.score.has_key(player_name):
|
if player_name in self.score:
|
||||||
self.score[player_name] += 1
|
self.score[player_name] += 1
|
||||||
else:
|
else:
|
||||||
self.score[player_name] = 1
|
self.score[player_name] = 1
|
||||||
@ -122,10 +122,10 @@ class Game(object):
|
|||||||
def cardSubmit(self):
|
def cardSubmit(self):
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
cardInput = None
|
cardInput = None
|
||||||
cardRange = range(5)
|
cardRange = list(range(5))
|
||||||
while cardInput not in cardRange:
|
while cardInput not in cardRange:
|
||||||
try:
|
try:
|
||||||
cardInput = int(raw_input('%s Pick a Card: ' % player)) - 1
|
cardInput = int(input('%s Pick a Card: ' % player)) - 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -151,25 +151,25 @@ class PlayerHand(object):
|
|||||||
return card_text
|
return card_text
|
||||||
|
|
||||||
def showHand(self):
|
def showHand(self):
|
||||||
print '%s' % self.text_list()
|
print('%s' % self.text_list())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
game = Game(['Bear','Swim', 'Jazz'])
|
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()
|
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()
|
game.players['Swim'].showHand()
|
||||||
|
|
||||||
print "\nJazz's hand in a weird way"
|
print("\nJazz's hand in a weird way")
|
||||||
round['hands']['Jazz'].showHand()
|
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):
|
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)))
|
@ -39,7 +39,7 @@ from random import randint
|
|||||||
|
|
||||||
import operator
|
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 time
|
||||||
import os
|
import os
|
||||||
@ -108,7 +108,7 @@ class Cah(callbacks.Plugin):
|
|||||||
|
|
||||||
def _findHighScore(self, scores):
|
def _findHighScore(self, scores):
|
||||||
highscore = []
|
highscore = []
|
||||||
for nick, score in scores.iteritems():
|
for nick, score in scores.items():
|
||||||
if len(highscore) == 0:
|
if len(highscore) == 0:
|
||||||
highscore.append([nick, score])
|
highscore.append([nick, score])
|
||||||
elif highscore[0][1] < score:
|
elif highscore[0][1] < score:
|
||||||
@ -126,10 +126,10 @@ class Cah(callbacks.Plugin):
|
|||||||
ties = []
|
ties = []
|
||||||
winningCanidate = []
|
winningCanidate = []
|
||||||
canidatesById = []
|
canidatesById = []
|
||||||
for nick in self.cardsPlayed.keys():
|
for nick in list(self.cardsPlayed.keys()):
|
||||||
canidatesById.append(nick)
|
canidatesById.append(nick)
|
||||||
|
|
||||||
for canidateNumber, count in votes.iteritems():
|
for canidateNumber, count in votes.items():
|
||||||
canidate = canidatesById[int(canidateNumber)]
|
canidate = canidatesById[int(canidateNumber)]
|
||||||
count = int(count)
|
count = int(count)
|
||||||
if len(winningCanidate) == 0:
|
if len(winningCanidate) == 0:
|
||||||
@ -203,9 +203,9 @@ class Cah(callbacks.Plugin):
|
|||||||
#scores = []
|
#scores = []
|
||||||
winner = None
|
winner = None
|
||||||
formattedScores = []
|
formattedScores = []
|
||||||
print cah.score
|
print(cah.score)
|
||||||
winner = self._findHighScore(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))
|
formattedScores.append("%s: %d" % (name, score))
|
||||||
self._msg(channel, "Game Over! %s is the Winner! Scores: %s " % (winner[0][0], ", ".join(formattedScores)))
|
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 = self
|
||||||
game.voting = False
|
game.voting = False
|
||||||
winner = self._tallyVotes(game.votes)
|
winner = self._tallyVotes(game.votes)
|
||||||
print winner
|
print(winner)
|
||||||
game.game.end_round(winner[0][0], self.cardsPlayed)
|
game.game.end_round(winner[0][0], self.cardsPlayed)
|
||||||
game.voted = []
|
game.voted = []
|
||||||
game._msg(self.channel, "%s wins the round!" % ircutils.bold(winner[0][0]))
|
game._msg(self.channel, "%s wins the round!" % ircutils.bold(winner[0][0]))
|
@ -1,6 +1,6 @@
|
|||||||
__author__ = 'Bear'
|
__author__ = 'Bear'
|
||||||
|
|
||||||
from cah import *
|
from .cah import *
|
||||||
|
|
||||||
def test_cards_will_be_unique(deck=None, player_list = None):
|
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()
|
deck=Deck()
|
||||||
if player_list is None:
|
if player_list is None:
|
||||||
player_list = {'one': PlayerHand(deck),'two': PlayerHand(deck) }
|
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:
|
for card in value.card_list:
|
||||||
assert card.text not in deck.answerDb
|
assert card.text not in deck.answerDb
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ def test_card_parsing(deck=None):
|
|||||||
def test_game():
|
def test_game():
|
||||||
game = Game(['Bear','Swim', 'Jazz'])
|
game = Game(['Bear','Swim', 'Jazz'])
|
||||||
test_cards_will_be_unique(deck=game.deck, player_list= game.players)
|
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]
|
hand = game.players[player]
|
||||||
test_player_hand(hand)
|
test_player_hand(hand)
|
||||||
test_round_advancement(game)
|
test_round_advancement(game)
|
||||||
@ -42,16 +42,16 @@ def test_round_advancement(game=None):
|
|||||||
while round < game.round_limit:
|
while round < game.round_limit:
|
||||||
bot_gets = game.next_round()
|
bot_gets = game.next_round()
|
||||||
assert isinstance(bot_gets, dict)
|
assert isinstance(bot_gets, dict)
|
||||||
assert bot_gets.has_key('question')
|
assert 'question' in bot_gets
|
||||||
assert game.has_key('question')
|
assert 'question' in game
|
||||||
assert bot_gets.has_key('hands')
|
assert 'hands' in bot_gets
|
||||||
test_end_round(game)
|
test_end_round(game)
|
||||||
|
|
||||||
def build_end_round_data(game):
|
def build_end_round_data(game):
|
||||||
winner = choice(game.players.keys())
|
winner = choice(list(game.players.keys()))
|
||||||
cards_played = {}
|
cards_played = {}
|
||||||
#Get random cards from player's hand to satisfy the question card
|
#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]
|
player_cards = game.players[player].card_list[:game.question.answers]
|
||||||
cards_played[player] = player_cards #player_cards is a deque object -> tuple(list,maxlen)
|
cards_played[player] = player_cards #player_cards is a deque object -> tuple(list,maxlen)
|
||||||
return {'winner': winner, 'cards_played': cards_played}
|
return {'winner': winner, 'cards_played': cards_played}
|
||||||
@ -63,13 +63,13 @@ def test_end_round(game=None):
|
|||||||
game.question.answers = 2
|
game.question.answers = 2
|
||||||
fake_end_round = build_end_round_data(game)
|
fake_end_round = build_end_round_data(game)
|
||||||
game.end_round(fake_end_round['winner'],fake_end_round['cards_played'])
|
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
|
assert len(game.players[player].card_list) == 5
|
||||||
if isinstance(fake_end_round['cards_played'][player], Card):
|
if isinstance(fake_end_round['cards_played'][player], Card):
|
||||||
fake_end_round['cards_played'][player] = list(fake_end_round['cards_played'][player])
|
fake_end_round['cards_played'][player] = list(fake_end_round['cards_played'][player])
|
||||||
for card in 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 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):
|
def test_player_hand(hand=None):
|
@ -1 +0,0 @@
|
|||||||
# Stub so local is a module, used for third-party modules
|
|
Loading…
x
Reference in New Issue
Block a user