From c08c35ca342da77e7754fb24bdeda9dd16d2affd Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Tue, 3 Dec 2019 03:30:24 -0500 Subject: [PATCH] wild draw 4 fixes --- Uno/plugin.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Uno/plugin.py b/Uno/plugin.py index d3a95ed..ed1f92b 100644 --- a/Uno/plugin.py +++ b/Uno/plugin.py @@ -12,7 +12,6 @@ import re import random - import supybot.conf as conf import supybot.utils as utils from supybot.commands import * @@ -233,7 +232,7 @@ class Uno(callbacks.Plugin): else: pass - def _uno_is_valid_play(self, table, card, discard, wildcolor): + def _uno_is_valid_play(self, table, card, discard): if card=='Wild': # Wild is always a valid play for now return True @@ -242,7 +241,7 @@ class Uno(callbacks.Plugin): if 'Wild' not in discard: discardcolor=discard.split(' ',1)[0] else: - discardcolor=wildcolor + discardcolor=self.game[table].get('wildcolor') for c in self.game[table]['players'][turnplayer]['hand']: if discardcolor in c: return False @@ -547,17 +546,16 @@ class Uno(callbacks.Plugin): nick=list(self.game[table]['players'].keys())[self.game[table]['turn']] discard=self.game[table]['discard'][-1] - wildcolor = self.game[table].get('wildcolor') novalid=True for c in self.game[table]['players'][nick]['hand']: - if self._uno_is_valid_play(table, c, discard, wildcolor)==True: + if self._uno_is_valid_play(table, c, discard)==True: novalid=False if novalid==True: # draw a card card=self._uno_draw_card(table, nick) self.game[table]['players'][nick]['hasdrawn']=True - if self._uno_is_valid_play(table, card, discard, wildcolor)==True: + if self._uno_is_valid_play(table, card, discard)==True: # always play the card if possible ncards=len(self.game[table]['players'][nick]['hand']) irc.reply("%s draws a card, and plays it; It's a %s (%s cards left in hand)." % (nick, card, ncards), to=channel) @@ -570,7 +568,7 @@ class Uno(callbacks.Plugin): card='' else: # pick a random card - playablecards=[c for c in self.game[table]['players'][nick]['hand'] if self._uno_is_valid_play(table, c, discard, wildcolor)==True or 'Wild' in c] + playablecards=[c for c in self.game[table]['players'][nick]['hand'] if self._uno_is_valid_play(table, c, discard)==True or 'Wild' in c] card=random.choice(playablecards) if card=='Wild' or card=='Wild Draw 4': # Just do dumb blind color choice @@ -669,11 +667,10 @@ class Uno(callbacks.Plugin): text=text.strip() discard=self.game[table]['discard'][-1] - wildcolor=self.game[table].get('wildcolor') novalid=True for c in self.game[table]['players'][nick]['hand']: - if self._uno_is_valid_play(table, c, discard, wildcolor)==True: + if self._uno_is_valid_play(table, c, discard)==True: novalid=False if text.lower()=='draw': @@ -687,7 +684,7 @@ class Uno(callbacks.Plugin): # Draw a card c=self.game[table]['deck'].pop(random.randint(0,len(self.game[table]['deck'])-1)) self.game[table]['players'][nick]['hand'].append(c) - if self._uno_is_valid_play(table, c, discard, wildcolor)==True: + if self._uno_is_valid_play(table, c, discard)==True: self.reply(irc, 'You draw a %s from the draw pile. You can choose not to play this card using "%suno play done"' % (c, self.prefixChar), to=nick, notice=True, private=True) self.game[table]['players'][nick]['hasdrawn']=True return @@ -753,7 +750,7 @@ class Uno(callbacks.Plugin): return # check for illegal move - if self._uno_is_valid_play(table, card, discard, wildcolor)==False: + if self._uno_is_valid_play(table, card, discard)==False: irc.reply("You can't play that card.") return