Skip to content

Commit

Permalink
Merge pull request #116 from paulosgf/blackjack
Browse files Browse the repository at this point in the history
Fix #3
- blackjack plugin lint
  • Loading branch information
paulosgf committed Jun 25, 2022
2 parents 9265f0b + 06d65d4 commit 10131ac
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 66 deletions.
1 change: 0 additions & 1 deletion src/honeybot/plugins/downloaded/blackjack/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

NAME = 'blackjack.py'
ORIGINAL_AUTHORS = [
'Angelo Giacco'
Expand Down
53 changes: 24 additions & 29 deletions src/honeybot/plugins/downloaded/blackjack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
move on to next player
"""

import random, sys, os

sys.path.append("plugins/poker_assets")
import deck
import card
import hand
import player
import poker_assets.deck
import poker_assets.card
import poker_assets.hand
import poker_assets.player


class Plugin:

bj_created = False
round_started = False
turn = 0
Expand Down Expand Up @@ -80,10 +77,10 @@ def initPlayer(methods, info):
name = info["prefix"].split("!")[0]
if len(Plugin.player_lst) <= 5: # limit game to 6 players
if not (
name in [player.get_name() for player in Plugin.player_lst]
name in [player.get_name() for player in Plugin.player_lst]
):
Plugin.player_lst.append(
player.Player(
poker_assets.player.Player(
len(Plugin.player_lst), Plugin.starting_chips, name
)
)
Expand All @@ -108,17 +105,14 @@ def checkHand(methods, info, player):
name = player.get_name()
total = player.show_player_hand().hand_total()
cards = " ".join(
[card.show_card() for card in player.show_player_hand().show_hand_obj()]
[poker_assets.card.show_card() for card in
player.show_player_hand().show_hand_obj()]
)
if total > 21:
methods["send"](
info["address"],
name
+ "'s hand "
+ cards
+ " has a value of "
+ str(total)
+ " so you have been kicked out",
name + "'s hand " + cards + " has a value of " + str(total) +
" so you have been kicked out",
)
for p in Plugin.player_lst:
if p.get_name() == name:
Expand Down Expand Up @@ -155,11 +149,11 @@ def initGame(methods, info):
Plugin.bj_created = True
Plugin.round_started = False
Plugin.initPlayer(methods, info)
Plugin.DECK = deck.Deck()
Plugin.DECK = poker_assets.deck.Deck()
methods["send"](
info["address"],
name
+ " has started a game of blackjack! Use .blackjack join to join in!",
name + " has started a game of blackjack! "
"Use .blackjack join to join in!",
)
else:
methods["send"](info["address"], "A game already exists!")
Expand All @@ -170,18 +164,19 @@ def start(methods, info):
Plugin.round_started = True
Plugin.bj_created = True
for player in Plugin.player_lst:
player.add_hand(hand.Hand(Plugin.DECK.make_hand()))
player.add_hand(poker_assets.hand.Hand(Plugin.DECK.make_hand()))
total = player.show_player_hand().hand_total()
cards = " ".join(
[card.show_card() for card in player.show_player_hand().show_hand_obj()]
[poker_assets.card.show_card() for card
in player.show_player_hand().show_hand_obj()]
)
Plugin.checkHand(methods, info, player)

def hit(methods, info):
""" give player a new card """

name = info["prefix"].split("!")[0]
if Plugin.winner == None:
if Plugin.winner is None:
if Plugin.player_lst[Plugin.turn].get_name() == name:
Plugin.player_lst[Plugin.turn].add_card_to_hand(
Plugin.DECK.draw_random_card()
Expand All @@ -198,13 +193,13 @@ def hit(methods, info):
def stand(methods, info):
""" player chooses not to get a new car """
name = info["prefix"].split("!")[0]
if Plugin.winner == None:
if Plugin.winner is None:
if Plugin.turn < len(Plugin.player_lst):
if Plugin.player_lst[Plugin.turn].get_name() == name:
methods["send"](
info["address"],
info["prefix"].split("!")[0]
+ " has chosen not to pick another card!",
info["prefix"].split("!")[0] +
" has chosen not to pick another card!",
)
Plugin.next_turn(methods, info)
else:
Expand All @@ -223,13 +218,13 @@ def stand(methods, info):
RUNNING PLUGIN
"""

def run(self, incoming, methods, info, bot_info):
def run(self, methods, info):
try:
msgs = info["args"][1:][0].split()
if (
info["command"] == "PRIVMSG"
and (msgs[0] == ".bj" or msgs[0] == ".21" or msgs[0] == ".blackjack")
and len(msgs) == 2
info["command"] == "PRIVMSG" and
(msgs[0] == ".bj" or msgs[0] == ".21" or msgs[0] == ".blackjack") and
len(msgs) == 2
):
if msgs[1] == "create":
Plugin.initGame(methods, info)
Expand Down
15 changes: 10 additions & 5 deletions src/honeybot/plugins/downloaded/blackjack/poker_assets/best5.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def straight(ranks):


def kind(n, ranks):
""" return the first rank that this hand has exactly n-of-a-kind of. Return None if there is no
n-of-a-kind in the hand """
"""
return the first rank that this hand has exactly n-of-a-kind of.
Return None if there is no n-of-a-kind in the hand
"""

for r in ranks:

Expand All @@ -102,9 +104,12 @@ def test_best_hand(playerhand):
# D = Diamond
# C = Club
# H = Heart
# assert (sorted(best_hand('6C 7C 8C 9C TC 5C JS'.split())) == ['6C', '7C', '8C', '9C', 'TC'])
# assert (sorted(best_hand('TD TC TH 7C 7D 8C 8S'.split())) == ['8C', '8S', 'TC', 'TD', 'TH'])
# assert (sorted(best_hand('JD TC TH 7C 7D 7S 7H'.split())) == ['7C', '7D', '7H', '7S', 'JD'])
# assert (sorted(best_hand('6C 7C 8C 9C TC 5C JS'.split())) ==
# ['6C', '7C', '8C', '9C', 'TC'])
# assert (sorted(best_hand('TD TC TH 7C 7D 8C 8S'.split())) ==
# ['8C', '8S', 'TC', 'TD', 'TH'])
# assert (sorted(best_hand('JD TC TH 7C 7D 7S 7H'.split())) ==
# ['7C', '7D', '7H', '7S', 'JD'])
# return 'test_best_hand passes'
# return sorted(best_hand('2D 2C 2H 7C 7D KC KS'.split()))
return sorted(best_hand(playerhand.split()))
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" board class """

# pylint: disable=E1601


class Board(object):
""" board class """

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def __init__(self, card):
1,
2,
3,
] # 0 is for a low: 2 3 4, 1 for a medium 4 5 6 7, 2 for a high 8 9 10, 3 for a suit J Q K A
] # 0 is for a low: 2 3 4,
# 1 for a medium 4 5 6 7,
# 2 for a high 8 9 10,
# 3 for a suit J Q K A

self.__figure = card[0]
self.__color = card[1].upper()
Expand Down
27 changes: 13 additions & 14 deletions src/honeybot/plugins/downloaded/blackjack/poker_assets/game_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# pylint: disable=E1601, W0612

import card
import deck
import board
import hand
Expand Down Expand Up @@ -41,9 +40,9 @@ def init_game(players, round):
players = init_players(6, 100)
game = init_game(players, 9)

deck = game[0]
board = game[1]
pot = game[2]
# deck = game[0]
# board = game[1]
# pot = game[2]
players = game[3]
for card in board.get_board():

Expand All @@ -53,19 +52,19 @@ def init_game(players, round):

players[0].show_player_hand().best_five(board)

for player in players:
for play in players:

print(player.general_name())
print(play.general_name())

print(
player.general_name(),
player.show_player_hand().show_hand()[0].show_card(),
player.show_player_hand().show_hand()[1].show_card(),
player.chips(),
player.position_nr(),
player.position_name(),
player.show_player_hand().hand_strength(board),
str(player.show_player_hand().best_five(board)),
play.general_name(),
play.show_player_hand().show_hand()[0].show_card(),
play.show_player_hand().show_hand()[1].show_card(),
play.chips(),
play.position_nr(),
play.position_name(),
play.show_player_hand().hand_strength(board),
str(play.show_player_hand().best_five(board)),
)

print(len(deck.show_deck()))
22 changes: 14 additions & 8 deletions src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# import deuces
# import best5
# import board
import card
# import card


class Hand(object):
Expand Down Expand Up @@ -41,8 +41,9 @@ def best_five(self, b):
print(b.turn())
print(b.river())
print(" ".join([c.show_card() for c in self.show_hand()]))
hand_and_board = self.show_hand()[0].show_card() + ' ' + self.show_hand()[1].show_card() +\
' ' + b.flop1() + ' ' + b.flop2() + ' ' + b.flop3() + ' ' + b.turn() + ' ' + b.river()
hand_and_board = self.show_hand()[0].show_card() + ' ' +\
self.show_hand()[1].show_card() + ' ' + b.flop1() + ' ' +\
b.flop2() + ' ' + b.flop3() + ' ' + b.turn() + ' ' + b.river()
return(" ".join([c for c in best5.test_best_hand(hand_and_board)]))
except Exception:
Expand All @@ -53,11 +54,16 @@ def hand_strength(self, board):
evaluator = deuces.Evaluator()
b5 = self.best_five(board)
h1 = b5[:2].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
h2 = b5[3:5].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
b1 = b5[6:8].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
b2 = b5[9:11].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
b3 = b5[12:14].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
h1 = b5[:2].replace('S', 's').replace('H', 'h').replace('D', 'd')\
.replace('C', 'c')
h2 = b5[3:5].replace('S', 's').replace('H', 'h').replace('D', 'd')\
.replace('C', 'c')
b1 = b5[6:8].replace('S', 's').replace('H', 'h').replace('D', 'd')\
.replace('C', 'c')
b2 = b5[9:11].replace('S', 's').replace('H', 'h').replace('D', 'd')\
.replace('C', 'c')
b3 = b5[12:14].replace('S', 's').replace('H', 'h').replace('D', 'd')\
.replace('C', 'c')
hl = [deuces.Card.new(h1), deuces.Card.new(h2)]
bl = [deuces.Card.new(b1), deuces.Card.new(b2), deuces.Card.new(b3)]
strength = evaluator.evaluate(bl, hl)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
""" player class """
# pylint: disable=E1601

import game_init


class Player(object):
""" player class """

Expand Down
17 changes: 9 additions & 8 deletions src/honeybot/plugins/downloaded/blackjack/poker_assets/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hand
import player
import pot
import game_init

# import game_init

Expand Down Expand Up @@ -109,15 +110,15 @@

print(len(game_init.game[0]) + len(game_init.game[1]) + len(game_init.game[3]) * 2)

for player in game_init.game[3]:
for play in game_init.game[3]:
print(
player.general_name(),
player.show_player_hand().show_hand(),
player.chips(),
player.position_nr(),
player.position_name(),
player.show_player_hand().hand_strength(board),
player.show_player_hand().best_five(board),
play.general_name(),
play.show_player_hand().show_hand(),
play.chips(),
play.position_nr(),
play.position_name(),
play.show_player_hand().hand_strength(board),
play.show_player_hand().best_five(board),
)

game_init.game[0].show_deck()
Expand Down

0 comments on commit 10131ac

Please sign in to comment.