Skip to content

Commit 06d65d4

Browse files
committed
Fix #3
- blackjack plugin lint
1 parent 9265f0b commit 06d65d4

File tree

9 files changed

+80
-66
lines changed

9 files changed

+80
-66
lines changed

src/honeybot/plugins/downloaded/blackjack/info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
NAME = 'blackjack.py'
32
ORIGINAL_AUTHORS = [
43
'Angelo Giacco'

src/honeybot/plugins/downloaded/blackjack/main.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@
2323
move on to next player
2424
"""
2525

26-
import random, sys, os
2726

28-
sys.path.append("plugins/poker_assets")
29-
import deck
30-
import card
31-
import hand
32-
import player
27+
import poker_assets.deck
28+
import poker_assets.card
29+
import poker_assets.hand
30+
import poker_assets.player
3331

3432

3533
class Plugin:
36-
3734
bj_created = False
3835
round_started = False
3936
turn = 0
@@ -80,10 +77,10 @@ def initPlayer(methods, info):
8077
name = info["prefix"].split("!")[0]
8178
if len(Plugin.player_lst) <= 5: # limit game to 6 players
8279
if not (
83-
name in [player.get_name() for player in Plugin.player_lst]
80+
name in [player.get_name() for player in Plugin.player_lst]
8481
):
8582
Plugin.player_lst.append(
86-
player.Player(
83+
poker_assets.player.Player(
8784
len(Plugin.player_lst), Plugin.starting_chips, name
8885
)
8986
)
@@ -108,17 +105,14 @@ def checkHand(methods, info, player):
108105
name = player.get_name()
109106
total = player.show_player_hand().hand_total()
110107
cards = " ".join(
111-
[card.show_card() for card in player.show_player_hand().show_hand_obj()]
108+
[poker_assets.card.show_card() for card in
109+
player.show_player_hand().show_hand_obj()]
112110
)
113111
if total > 21:
114112
methods["send"](
115113
info["address"],
116-
name
117-
+ "'s hand "
118-
+ cards
119-
+ " has a value of "
120-
+ str(total)
121-
+ " so you have been kicked out",
114+
name + "'s hand " + cards + " has a value of " + str(total) +
115+
" so you have been kicked out",
122116
)
123117
for p in Plugin.player_lst:
124118
if p.get_name() == name:
@@ -155,11 +149,11 @@ def initGame(methods, info):
155149
Plugin.bj_created = True
156150
Plugin.round_started = False
157151
Plugin.initPlayer(methods, info)
158-
Plugin.DECK = deck.Deck()
152+
Plugin.DECK = poker_assets.deck.Deck()
159153
methods["send"](
160154
info["address"],
161-
name
162-
+ " has started a game of blackjack! Use .blackjack join to join in!",
155+
name + " has started a game of blackjack! "
156+
"Use .blackjack join to join in!",
163157
)
164158
else:
165159
methods["send"](info["address"], "A game already exists!")
@@ -170,18 +164,19 @@ def start(methods, info):
170164
Plugin.round_started = True
171165
Plugin.bj_created = True
172166
for player in Plugin.player_lst:
173-
player.add_hand(hand.Hand(Plugin.DECK.make_hand()))
167+
player.add_hand(poker_assets.hand.Hand(Plugin.DECK.make_hand()))
174168
total = player.show_player_hand().hand_total()
175169
cards = " ".join(
176-
[card.show_card() for card in player.show_player_hand().show_hand_obj()]
170+
[poker_assets.card.show_card() for card
171+
in player.show_player_hand().show_hand_obj()]
177172
)
178173
Plugin.checkHand(methods, info, player)
179174

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

183178
name = info["prefix"].split("!")[0]
184-
if Plugin.winner == None:
179+
if Plugin.winner is None:
185180
if Plugin.player_lst[Plugin.turn].get_name() == name:
186181
Plugin.player_lst[Plugin.turn].add_card_to_hand(
187182
Plugin.DECK.draw_random_card()
@@ -198,13 +193,13 @@ def hit(methods, info):
198193
def stand(methods, info):
199194
""" player chooses not to get a new car """
200195
name = info["prefix"].split("!")[0]
201-
if Plugin.winner == None:
196+
if Plugin.winner is None:
202197
if Plugin.turn < len(Plugin.player_lst):
203198
if Plugin.player_lst[Plugin.turn].get_name() == name:
204199
methods["send"](
205200
info["address"],
206-
info["prefix"].split("!")[0]
207-
+ " has chosen not to pick another card!",
201+
info["prefix"].split("!")[0] +
202+
" has chosen not to pick another card!",
208203
)
209204
Plugin.next_turn(methods, info)
210205
else:
@@ -223,13 +218,13 @@ def stand(methods, info):
223218
RUNNING PLUGIN
224219
"""
225220

226-
def run(self, incoming, methods, info, bot_info):
221+
def run(self, methods, info):
227222
try:
228223
msgs = info["args"][1:][0].split()
229224
if (
230-
info["command"] == "PRIVMSG"
231-
and (msgs[0] == ".bj" or msgs[0] == ".21" or msgs[0] == ".blackjack")
232-
and len(msgs) == 2
225+
info["command"] == "PRIVMSG" and
226+
(msgs[0] == ".bj" or msgs[0] == ".21" or msgs[0] == ".blackjack") and
227+
len(msgs) == 2
233228
):
234229
if msgs[1] == "create":
235230
Plugin.initGame(methods, info)

src/honeybot/plugins/downloaded/blackjack/poker_assets/best5.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def straight(ranks):
7474

7575

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

8082
for r in ranks:
8183

@@ -102,9 +104,12 @@ def test_best_hand(playerhand):
102104
# D = Diamond
103105
# C = Club
104106
# H = Heart
105-
# assert (sorted(best_hand('6C 7C 8C 9C TC 5C JS'.split())) == ['6C', '7C', '8C', '9C', 'TC'])
106-
# assert (sorted(best_hand('TD TC TH 7C 7D 8C 8S'.split())) == ['8C', '8S', 'TC', 'TD', 'TH'])
107-
# assert (sorted(best_hand('JD TC TH 7C 7D 7S 7H'.split())) == ['7C', '7D', '7H', '7S', 'JD'])
107+
# assert (sorted(best_hand('6C 7C 8C 9C TC 5C JS'.split())) ==
108+
# ['6C', '7C', '8C', '9C', 'TC'])
109+
# assert (sorted(best_hand('TD TC TH 7C 7D 8C 8S'.split())) ==
110+
# ['8C', '8S', 'TC', 'TD', 'TH'])
111+
# assert (sorted(best_hand('JD TC TH 7C 7D 7S 7H'.split())) ==
112+
# ['7C', '7D', '7H', '7S', 'JD'])
108113
# return 'test_best_hand passes'
109114
# return sorted(best_hand('2D 2C 2H 7C 7D KC KS'.split()))
110115
return sorted(best_hand(playerhand.split()))

src/honeybot/plugins/downloaded/blackjack/poker_assets/board.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" board class """
22

33
# pylint: disable=E1601
4+
5+
46
class Board(object):
57
""" board class """
68

src/honeybot/plugins/downloaded/blackjack/poker_assets/card.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def __init__(self, card):
1313
1,
1414
2,
1515
3,
16-
] # 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
16+
] # 0 is for a low: 2 3 4,
17+
# 1 for a medium 4 5 6 7,
18+
# 2 for a high 8 9 10,
19+
# 3 for a suit J Q K A
1720

1821
self.__figure = card[0]
1922
self.__color = card[1].upper()

src/honeybot/plugins/downloaded/blackjack/poker_assets/game_init.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# pylint: disable=E1601, W0612
44

5-
import card
65
import deck
76
import board
87
import hand
@@ -41,9 +40,9 @@ def init_game(players, round):
4140
players = init_players(6, 100)
4241
game = init_game(players, 9)
4342

44-
deck = game[0]
45-
board = game[1]
46-
pot = game[2]
43+
# deck = game[0]
44+
# board = game[1]
45+
# pot = game[2]
4746
players = game[3]
4847
for card in board.get_board():
4948

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

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

56-
for player in players:
55+
for play in players:
5756

58-
print(player.general_name())
57+
print(play.general_name())
5958

6059
print(
61-
player.general_name(),
62-
player.show_player_hand().show_hand()[0].show_card(),
63-
player.show_player_hand().show_hand()[1].show_card(),
64-
player.chips(),
65-
player.position_nr(),
66-
player.position_name(),
67-
player.show_player_hand().hand_strength(board),
68-
str(player.show_player_hand().best_five(board)),
60+
play.general_name(),
61+
play.show_player_hand().show_hand()[0].show_card(),
62+
play.show_player_hand().show_hand()[1].show_card(),
63+
play.chips(),
64+
play.position_nr(),
65+
play.position_name(),
66+
play.show_player_hand().hand_strength(board),
67+
str(play.show_player_hand().best_five(board)),
6968
)
7069

7170
print(len(deck.show_deck()))

src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# import deuces
88
# import best5
99
# import board
10-
import card
10+
# import card
1111

1212

1313
class Hand(object):
@@ -41,8 +41,9 @@ def best_five(self, b):
4141
print(b.turn())
4242
print(b.river())
4343
print(" ".join([c.show_card() for c in self.show_hand()]))
44-
hand_and_board = self.show_hand()[0].show_card() + ' ' + self.show_hand()[1].show_card() +\
45-
' ' + b.flop1() + ' ' + b.flop2() + ' ' + b.flop3() + ' ' + b.turn() + ' ' + b.river()
44+
hand_and_board = self.show_hand()[0].show_card() + ' ' +\
45+
self.show_hand()[1].show_card() + ' ' + b.flop1() + ' ' +\
46+
b.flop2() + ' ' + b.flop3() + ' ' + b.turn() + ' ' + b.river()
4647
4748
return(" ".join([c for c in best5.test_best_hand(hand_and_board)]))
4849
except Exception:
@@ -53,11 +54,16 @@ def hand_strength(self, board):
5354
5455
evaluator = deuces.Evaluator()
5556
b5 = self.best_five(board)
56-
h1 = b5[:2].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
57-
h2 = b5[3:5].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
58-
b1 = b5[6:8].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
59-
b2 = b5[9:11].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
60-
b3 = b5[12:14].replace('S', 's').replace('H', 'h').replace('D', 'd').replace('C', 'c')
57+
h1 = b5[:2].replace('S', 's').replace('H', 'h').replace('D', 'd')\
58+
.replace('C', 'c')
59+
h2 = b5[3:5].replace('S', 's').replace('H', 'h').replace('D', 'd')\
60+
.replace('C', 'c')
61+
b1 = b5[6:8].replace('S', 's').replace('H', 'h').replace('D', 'd')\
62+
.replace('C', 'c')
63+
b2 = b5[9:11].replace('S', 's').replace('H', 'h').replace('D', 'd')\
64+
.replace('C', 'c')
65+
b3 = b5[12:14].replace('S', 's').replace('H', 'h').replace('D', 'd')\
66+
.replace('C', 'c')
6167
hl = [deuces.Card.new(h1), deuces.Card.new(h2)]
6268
bl = [deuces.Card.new(b1), deuces.Card.new(b2), deuces.Card.new(b3)]
6369
strength = evaluator.evaluate(bl, hl)

src/honeybot/plugins/downloaded/blackjack/poker_assets/player.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
""" player class """
22
# pylint: disable=E1601
3+
4+
import game_init
5+
6+
37
class Player(object):
48
""" player class """
59

src/honeybot/plugins/downloaded/blackjack/poker_assets/test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import hand
66
import player
77
import pot
8+
import game_init
89

910
# import game_init
1011

@@ -109,15 +110,15 @@
109110

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

112-
for player in game_init.game[3]:
113+
for play in game_init.game[3]:
113114
print(
114-
player.general_name(),
115-
player.show_player_hand().show_hand(),
116-
player.chips(),
117-
player.position_nr(),
118-
player.position_name(),
119-
player.show_player_hand().hand_strength(board),
120-
player.show_player_hand().best_five(board),
115+
play.general_name(),
116+
play.show_player_hand().show_hand(),
117+
play.chips(),
118+
play.position_nr(),
119+
play.position_name(),
120+
play.show_player_hand().hand_strength(board),
121+
play.show_player_hand().best_five(board),
121122
)
122123

123124
game_init.game[0].show_deck()

0 commit comments

Comments
 (0)