Add blackjack plugin.

This commit is contained in:
oddluck 2019-12-06 10:22:40 +00:00
parent ecd39b4d15
commit dfca8a08fc
4 changed files with 377 additions and 401 deletions

View File

@ -1,22 +1,3 @@
Ordinary BlackJack game. Forked from https://github.com/kg-bot/SupyBot/tree/master/plugins/BlackJack
Player can play only one instance of the game in same time. This plugin is pretty basic to start, but I plan on improving it.
Player must have enough chips to backup his stake.
When the player places bet and starts a game chips are taken away from him, if he wins
initial stake and bonus are added back to his account.
Each dealer and player are dealt two cards in the begining.
We make a check for blackjack after first two cards are dealt.
If nobody has blackjack we must wait for the player to hit/double or stand.
Player can decide what to do until he stands or he's busted.
When the player stands we start to deal cards to dealer until he reaches 17 or higher.
If the dealer is busted then player winns the game and we calculate the prize.
If the dealer is not busted and he's reached 17 we compare player and dealer score and calculate winner.

View File

@ -41,14 +41,16 @@ import supybot.world as world
__version__ = "" __version__ = ""
# XXX Replace this with an appropriate author or supybot.Author instance. # XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.authors.unknown __author__ = supybot.Author('KgBot', 'KgBot', '')
__maintainer__ = getattr(supybot.authors, 'oddluck',
supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net'))
# This is a dictionary mapping supybot.Author instances to lists of # This is a dictionary mapping supybot.Author instances to lists of
# contributions. # contributions.
__contributors__ = {} __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/BlackJack/download' __url__ = 'https://github.com/oddluck/limnoria-plugins/'
from . import config from . import config
from . import plugin from . import plugin

View File

@ -1,11 +1,2 @@
{ {
"donvitocorleone": { }
"chips": 577
},
"kg-bot": {
"chips": 560
},
"crazy_hospy": {
"chips": 936
}
}

View File

@ -1,367 +1,369 @@
### ###
# Copyright (c) 2014, KgBot # Copyright (c) 2014, KgBot
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
# #
# * Redistributions of source code must retain the above copyright notice, # * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer. # this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, # * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the # this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution. # documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of # * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products # contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent. # derived from this software without specific prior written consent.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
### ###
import supybot.schedule as schedule import supybot.schedule as schedule
import json import json
import random import random
import time import time
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
import supybot.plugins as plugins import supybot.plugins as plugins
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
try: try:
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('BlackJack') _ = PluginInternationalization('BlackJack')
except: except:
# Placeholder that allows to run the plugin on a bot # Placeholder that allows to run the plugin on a bot
# without the i18n module # without the i18n module
_ = lambda x:x _ = lambda x:x
class BlackJack(callbacks.Plugin): class BlackJack(callbacks.Plugin):
"""Add the help for "@plugin help BlackJack" here """Add the help for "@plugin help BlackJack" here
This should describe *how* to use this plugin.""" This should describe *how* to use this plugin."""
threaded = True threaded = True
def __init__(self, irc): def __init__(self, irc):
self.__parent = super(BlackJack, self) self.__parent = super(BlackJack, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
# Dictionary of players, holds important things about each player. # Dictionary of players, holds important things about each player.
self.players = {} self.players = {}
# List of scheduled games # List of scheduled games
self.events = [] self.events = []
self.minStake = 10 self.minStake = 10
self.maxStake = 50 self.maxStake = 50
def _isScheduled(self, name): def _isScheduled(self, name):
""" Checks to see if player is already playing game.""" """ Checks to see if player is already playing game."""
if name in self.events: if name in self.events:
return True return True
else: else:
return False return False
def _waitingPlayerAction(self, player): def _waitingPlayerAction(self, player):
""" Checks to see if player has got his first 2 cards and now we're waiting for him to hit/stand or double.""" """ Checks to see if player has got his first 2 cards and now we're waiting for him to hit/stand or double."""
if player in self.players.keys() and self.players[player]["waitingAction"] == True: if player in self.players.keys() and self.players[player]["waitingAction"] == True:
return True return True
else: else:
return False return False
def _deal(self, who, player): def _deal(self, who, player):
_allowed_whos = ["player", "bank"] _allowed_whos = ["player", "bank"]
if who in _allowed_whos: if who in _allowed_whos:
cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"] cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"]
card = random.choice(cards) card = random.choice(cards)
# Because we J/Q/K are not numbers we must convert them to 10's, but this is not nice, and we must implement # Because we J/Q/K are not numbers we must convert them to 10's, but this is not nice, and we must implement
# 2 types of cards here, one that will be answered to player and one that will be added to score # 2 types of cards here, one that will be answered to player and one that will be added to score
if card == "J" or card == "Q" or card == "K": if card == "J" or card == "Q" or card == "K":
card = 10 card = 10
if who == "player": if who == "player":
if card == 1: if card == 1:
# If 11 + score is bigger then 21 1 will be 1 # If 11 + score is bigger then 21 1 will be 1
if self.players[player]["score"] + 11 > 21: if self.players[player]["score"] + 11 > 21:
card = 1 card = 1
# If 1 + score is less then 21 1 will be 11 # If 1 + score is less then 21 1 will be 11
else: else:
card = 11 card = 11
self.players[player]["score"] = self.players[player]["score"] + card self.players[player]["score"] = self.players[player]["score"] + card
# Returns card because we might want to tell the player which card he's got. # Returns card because we might want to tell the player which card he's got.
return card return card
else: else:
if card == 1: if card == 1:
if self.players[player]["bankScore"] + 11 > 21: if self.players[player]["bankScore"] + 11 > 21:
card = 1 card = 1
else: else:
card = 11 card = 11
self.players[player]["bankScore"] = self.players[player]["bankScore"] + card self.players[player]["bankScore"] = self.players[player]["bankScore"] + card
return card return card
def _finishGame(self, irc, player): def _finishGame(self, irc, player):
self.players[player]["waitingAction"] = False self.players[player]["waitingAction"] = False
playerScore = self.players[player]["score"] playerScore = self.players[player]["score"]
bankScore = self.players[player]["bankScore"] bankScore = self.players[player]["bankScore"]
if playerScore == 21 and bankScore != 21: if playerScore == 21 and bankScore != 21:
self._playerWins(irc, player) self._playerWins(irc, player)
elif playerScore == 21 and bankScore == 21: elif playerScore == 21 and bankScore == 21:
irc.reply("This is push, nobody wins.") irc.reply("This is push, nobody wins.")
self._push(player) self._push(player)
elif bankScore == 21 and playerScore != 21: elif bankScore == 21 and playerScore != 21:
self._bankWins(irc, player) self._bankWins(irc, player)
elif playerScore < 21 and playerScore > bankScore: elif playerScore < 21 and playerScore > bankScore:
self._playerWins(irc, player) self._playerWins(irc, player)
elif bankScore < 21 and bankScore > playerScore: elif bankScore < 21 and bankScore > playerScore:
self._bankWins(irc, player) self._bankWins(irc, player)
elif playerScore == bankScore: elif playerScore == bankScore:
irc.reply("This is push, nobody wins.") irc.reply("This is push, nobody wins.")
self._push(player) self._push(player)
elif playerScore > 21 and bankScore < 21: elif playerScore > 21 and bankScore < 21:
self._bankWins(irc, player) self._bankWins(irc, player)
else: else:
self._playerWins(irc, player) self._playerWins(irc, player)
def _removeScheduledGame(self, name): def _removeScheduledGame(self, name):
try: try:
schedule.removeEvent(name) schedule.removeEvent(name)
self.events.remove(name) self.events.remove(name)
except: except:
try: try:
self.events.remove(name) self.events.remove(name)
except: except:
pass pass
def _push(self, player): def _push(self, player):
stake = self.players[player]["stake"] stake = self.players[player]["stake"]
chips = Chips() chips = Chips()
chips._addChips(player, stake) chips._addChips(player, stake)
game_name = "game_%s" % player game_name = "game_%s" % player
self._removeScheduledGame(game_name) self._removeScheduledGame(game_name)
def _playerWins(self, irc, player, blackjack=False): def _playerWins(self, irc, player, blackjack=False):
game_name = "game_%s" % player game_name = "game_%s" % player
if blackjack: if blackjack:
amount = self._blackjackPrize(self.players[player]["stake"]) amount = self._blackjackPrize(self.players[player]["stake"])
else: else:
amount = self.players[player]["stake"] * 2 amount = self.players[player]["stake"] * 2
chips = Chips() chips = Chips()
chips._addChips(player, amount) chips._addChips(player, amount)
irc.reply("Congrats, you have won and you got %s chips." % amount) irc.reply("Congrats, you have won and you got %s chips." % amount)
self._removeScheduledGame(game_name) self._removeScheduledGame(game_name)
def _bankWins(self, irc, player): def _bankWins(self, irc, player):
game_name = "game_%s" % player game_name = "game_%s" % player
irc.reply("Sorry but you've lost this time.") irc.reply("Sorry but you've lost this time.")
self._removeScheduledGame(game_name) self._removeScheduledGame(game_name)
def _playerChips(self, player): def _playerChips(self, player):
""" Return number of chips that player has.""" """ Return number of chips that player has."""
chipsClass = Chips() chipsClass = Chips()
chips = chipsClass._getChips(player) chips = chipsClass._getChips(player)
return chips return chips
def _finishBank(self, irc, player): def _finishBank(self, irc, player):
if player in self.players.keys(): if player in self.players.keys():
while(self.players[player]["bankScore"] < 17): while(self.players[player]["bankScore"] < 17):
card = self._deal("bank", player) card = self._deal("bank", player)
irc.reply("Dealer has got \x02%s\x02, and his score is \x02%s\x02." % (card, self.players[player]["bankScore"])) irc.reply("Dealer has got \x02%s\x02, and his score is \x02%s\x02." % (card, self.players[player]["bankScore"]))
self._finishGame(irc, player) self._finishGame(irc, player)
def _addNewPlayer(self, player, stake): def _addNewPlayer(self, player, stake):
""" Adds new player and needed things to self.players dictionary.""" """ Adds new player and needed things to self.players dictionary."""
self.players[player] = {} self.players[player] = {}
# This is set because this is the best way to check if player is playing when he wants to hit/double/stand # This is set because this is the best way to check if player is playing when he wants to hit/double/stand
self.players[player]["waitingAction"] = False self.players[player]["waitingAction"] = False
# We must keep track of players score after each card is dealt # We must keep track of players score after each card is dealt
self.players[player]["score"] = 0 self.players[player]["score"] = 0
# Also we must keep track of bank score # Also we must keep track of bank score
self.players[player]["bankScore"] = 0 self.players[player]["bankScore"] = 0
# And we need to know how much the player wants to stake # And we need to know how much the player wants to stake
self.players[player]["stake"] = stake self.players[player]["stake"] = stake
# We must also remove initial stake from player, just like he put it on table # We must also remove initial stake from player, just like he put it on table
chips = Chips() chips = Chips()
chips._removeChips(player, stake) chips._removeChips(player, stake)
def _scheduleNewGame(self, command, when, name, player, irc): def _scheduleNewGame(self, command, when, name, player, irc):
# Here we're adding game name to the list of games, from where we check who's playing and who's not # Here we're adding game name to the list of games, from where we check who's playing and who's not
self.events.append(name) self.events.append(name)
# Here we schedule the command to run after 10s and to finish game # Here we schedule the command to run after 10s and to finish game
schedule.addEvent(command, time.time() + when, name, args=(irc, player)) schedule.addEvent(command, time.time() + when, name, args=(irc, player))
def _checkBlackjack(self, irc, player): def _checkBlackjack(self, irc, player):
""" Checking to see if enyone has blackjack after first two cards are dealt.""" """ Checking to see if enyone has blackjack after first two cards are dealt."""
if player in self.players.keys(): if player in self.players.keys():
if self.players[player]["score"] == 21 and self.players[player]["bankScore"] != 21: if self.players[player]["score"] == 21 and self.players[player]["bankScore"] != 21:
self._playerWins(irc, player, True) self._playerWins(irc, player, True)
elif self.players[player]["bankScore"] == 21 and self.players[player]["score"] != 21: self.players[player]["waitingAction"] = False
self._bankWins(irc, player) elif self.players[player]["bankScore"] == 21 and self.players[player]["score"] != 21:
else: self._bankWins(irc, player)
return else:
return
def _blackjackPrize(self, stake):
# BlackJack prize is not same as regular prize. It is 3:1 so we must calculate it def _blackjackPrize(self, stake):
halfStake = stake / 2 # BlackJack prize is not same as regular prize. It is 3:1 so we must calculate it
newStake = (stake * 2) + halfStake halfStake = stake / 2
return newStake newStake = (stake * 2) + halfStake
return newStake
def blackjack(self, irc, msg, args, stake):
"""<stake> - amount of stake, between 10 and 50 def blackjack(self, irc, msg, args, stake):
"""<stake> - amount of stake, between 10 and 50
Starts a new game."""
# Because nicks are case-insensitive we must turn nick to lower version. Starts a new game."""
player = str(msg.nick).lower() # Because nicks are case-insensitive we must turn nick to lower version.
# Nicks are uniqe and we will use nick for scheduling game. player = str(msg.nick).lower()
game_name = "game_%s" % player # Nicks are uniqe and we will use nick for scheduling game.
# Checks if player has any chips. game_name = "game_%s" % player
chips = self._playerChips(player) # Checks if player has any chips.
# If this is True player is already playing blackjack and only one game is allowed per player. chips = self._playerChips(player)
if self._isScheduled(game_name): # If this is True player is already playing blackjack and only one game is allowed per player.
irc.reply("You can play only one instance of the game in same time.") if self._isScheduled(game_name):
# If player does not have chips he can't play, logical. irc.reply("You can play only one instance of the game in same time.")
elif chips == "NoChipsFile" or chips == False or chips == None: # If player does not have chips he can't play, logical.
irc.reply("You can't play blackjack because you don't have enough chips. If you think this is some mistake notify admins.") if chips == "NoChipsFile" or chips == False or chips == None:
else: chipsClass = Chips()
# If player has enough chips to backup his stake we can start a game. chipsClass._addChips(player, stake)
if stake >= self.minStake and stake <= self.maxStake and stake <= chips: chips = stake
# Now is good time to add new player and actually start a game. if stake >= self.minStake and stake <= self.maxStake and stake <= chips:
self._addNewPlayer(player, stake) # Now is good time to add new player and actually start a game.
self._startNewGame(irc, player) self._addNewPlayer(player, stake)
else: self._startNewGame(irc, player)
irc.reply("Something is wrong with your stake, maybe it's too high or too low, or maybe you don't have enough chips.") else:
blackjack = wrap(blackjack, ["int"]) irc.reply("Something is wrong with your stake, maybe it's too high or too low, or maybe you don't have enough chips.")
blackjack = wrap(blackjack, ["int"])
def _startNewGame(self, irc, player):
# We deal first card to the player def _startNewGame(self, irc, player):
playerFirstCard = self._deal('player', player) # We deal first card to the player
# And we must tell the player which card he got playerFirstCard = self._deal('player', player)
irc.reply("Your first card is %s" % playerFirstCard) # And we must tell the player which card he got
# We must also deal first card to the bank irc.reply("Your first card is %s" % playerFirstCard)
bankFirstCard = self._deal('bank', player) # We must also deal first card to the bank
# And player shouldn't know which is the dealers first card bankFirstCard = self._deal('bank', player)
irc.reply("Dealer has got his first card, face down.") # And player shouldn't know which is the dealers first card
# Now we deal second card to the player irc.reply("Dealer has got his first card, face down.")
playerSecondCard = self._deal('player', player) # Now we deal second card to the player
# And we have to tell the player what's his second card, and also what's his score playerSecondCard = self._deal('player', player)
irc.reply("Your second card is %s, and you're score is %s" % (playerSecondCard, self.players[player]["score"])) # And we have to tell the player what's his second card, and also what's his score
# Bank just got it's second card irc.reply("Your second card is %s, and you're score is %s" % (playerSecondCard, self.players[player]["score"]))
bankSecondCard = self._deal('bank', player) # Bank just got it's second card
# Player needs to know which is dealer's second card bankSecondCard = self._deal('bank', player)
irc.reply("Dealer has got his second card %s, his score is now \x02%s\02.What are you gonna do, stand, hit or double. You have 20 seconds to decide." % (bankSecondCard, self.players[player]["bankScore"])) # Player needs to know which is dealer's second card
# Now we wait for user to hit/double/stand and our bot must know that he's waiting for player action irc.reply("Dealer has got his second card %s, his score is now \x02%s\02.What are you gonna do, stand, hit or double. You have 20 seconds to decide." % (bankSecondCard, self.players[player]["bankScore"]))
self.players[player]["waitingAction"] = True # Now we wait for user to hit/double/stand and our bot must know that he's waiting for player action
# Each game will wait 10s for user input and then it'll end the game if nothing happens, and we must schedule it self.players[player]["waitingAction"] = True
self._scheduleNewGame(self._finishBank, 20, "game_%s" % player, player, irc) # Each game will wait 10s for user input and then it'll end the game if nothing happens, and we must schedule it
# We must check if somebody has got blackjack after first 2 cards self._scheduleNewGame(self._finishBank, 20, "game_%s" % player, player, irc)
self._checkBlackjack(irc, player) # We must check if somebody has got blackjack after first 2 cards
self._checkBlackjack(irc, player)
def hit(self, irc, msg, args):
"""Takes no arguments def hit(self, irc, msg, args):
"""Takes no arguments
Hit!!!"""
player = str(msg.nick).lower() Hit!!!"""
if self._waitingPlayerAction(player) == True: player = str(msg.nick).lower()
game_name = "game_%s" % player if self._waitingPlayerAction(player) == True:
self._removeScheduledGame(game_name) game_name = "game_%s" % player
card = self._deal('player', player) self._removeScheduledGame(game_name)
irc.reply("You've got %s, and your score is %s." % (card, self.players[player]["score"])) card = self._deal('player', player)
if self.players[player]["score"] > 21: irc.reply("You've got %s, and your score is %s." % (card, self.players[player]["score"]))
irc.reply("You're busted.") if self.players[player]["score"] > 21:
self._bankWins(irc, player) irc.reply("You're busted.")
else: self._bankWins(irc, player)
self._scheduleNewGame(self._finishBank, 20, game_name, player, irc) else:
else: self._scheduleNewGame(self._finishBank, 20, game_name, player, irc)
irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50") else:
hit = wrap(hit) irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50")
hit = wrap(hit)
def double(self, irc, msg, args):
"""Takes no arguments def double(self, irc, msg, args):
"""Takes no arguments
Double!!!!"""
player = str(msg.nick).lower() Double!!!!"""
if self._waitingPlayerAction(player) == True: player = str(msg.nick).lower()
stake = self.players[player]["stake"] if self._waitingPlayerAction(player) == True:
chips = self._playerChips(player) stake = self.players[player]["stake"]
if chips != False and chips != None and chips != "NoChipsFile" and chips >= stake: chips = self._playerChips(player)
game_name = "game_%s" % player if chips != False and chips != None and chips != "NoChipsFile" and chips >= stake:
self._removeScheduledGame(game_name) game_name = "game_%s" % player
chipsClass = Chips() self._removeScheduledGame(game_name)
chipsClass._removeChips(player, stake) chipsClass = Chips()
self.players[player]["stake"] = stake * 2 chipsClass._removeChips(player, stake)
irc.reply("Your stake was %s, and now it is %s." % (stake, self.players[player]["stake"])) self.players[player]["stake"] = stake * 2
card = self._deal('player', player) irc.reply("Your stake was %s, and now it is %s." % (stake, self.players[player]["stake"]))
irc.reply("You've got %s, and your score is %s" % (card, self.players[player]["score"])) card = self._deal('player', player)
if self.players[player]["score"] > 21: irc.reply("You've got %s, and your score is %s" % (card, self.players[player]["score"]))
irc.reply("You're busted.") if self.players[player]["score"] > 21:
self._bankWins(irc, player) irc.reply("You're busted.")
else: self._bankWins(irc, player)
self._finishBank(irc, player) else:
else: self._finishBank(irc, player)
irc.reply("You don't have enough chips for double stake.") else:
else: irc.reply("You don't have enough chips for double stake.")
irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50") else:
double = wrap(double) irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50")
double = wrap(double)
def stand(self, irc, msg, args):
"""Takes no arguments. def stand(self, irc, msg, args):
"""Takes no arguments.
Stand!!!"""
player = str(msg.nick).lower() Stand!!!"""
if self._waitingPlayerAction(player) == True: player = str(msg.nick).lower()
self._finishBank(irc, player) if self._waitingPlayerAction(player) == True:
else: self._finishBank(irc, player)
irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50") else:
stand = wrap(stand) irc.reply("You're not playing blackjack at this moment. Start a new game with +blackjack 50")
stand = wrap(stand)
class Chips():
def __init__(self): class Chips():
try: def __init__(self):
with open("G:\\supybot\\plugins\\BlackJack\\local\\chips.json", "r") as chipsFile: try:
self.players = json.load(chipsFile) with open("G:\\supybot\\plugins\\BlackJack\\local\\chips.json", "r") as chipsFile:
except: self.players = json.load(chipsFile)
self.players = False except:
self.players = False
def _getChips(self, player):
if self.players: def _getChips(self, player):
if player in self.players.keys(): if self.players:
try: if player in self.players.keys():
return self.players[player]["chips"] try:
except: return self.players[player]["chips"]
return False except:
else: return False
return None else:
else: return None
return "NoChipsFile" else:
return "NoChipsFile"
def _addChips(self, player, amount):
if self.players: def _addChips(self, player, amount):
if player in self.players.keys(): if self.players:
self.players[player]["chips"] = self.players[player]["chips"] + amount if player in self.players.keys():
self._saveChips() self.players[player]["chips"] = self.players[player]["chips"] + amount
else: self._saveChips()
self.players[player] = {} else:
self.players[player]["chips"] = amount self.players[player] = {}
self._saveChips() self.players[player]["chips"] = amount
else: self._saveChips()
return "NoChipsFile" else:
return "NoChipsFile"
def _removeChips(self, player, amount):
if self.players: def _removeChips(self, player, amount):
if player in self.players.keys(): if self.players:
self.players[player]["chips"] = self.players[player]["chips"] - amount if player in self.players.keys():
self._saveChips() self.players[player]["chips"] = self.players[player]["chips"] - amount
self._saveChips()
def _saveChips(self):
with open("G:\\supybot\\plugins\\BlackJack\\local\\chips.json", "w") as chips: def _saveChips(self):
json.dump(self.players, chips, indent=4) with open("G:\\supybot\\plugins\\BlackJack\\local\\chips.json", "w") as chips:
json.dump(self.players, chips, indent=4)
Class = BlackJack
Class = BlackJack
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: