FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ThinkRubyBuild/code/PokerHand.py at master · learnbyexample/ThinkRubyBuild · GitHub
learnbyexample
/
ThinkRubyBuild
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
32
Code
Issues
7
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
ThinkRubyBuild
/
code
/
PokerHand.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (39 loc) · 1.22 KB
Breadcrumbs
ThinkRubyBuild
/
code
/
PokerHand.py
Copy path
File metadata and controls
54 lines (39 loc) · 1.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""This module contains a code example related to
Think Python, 2nd Edition
by Allen Downey
http://thinkpython2.com
Copyright 2015 Allen Downey
License: http://creativecommons.org/licenses/by/4.0/
"""
from
__future__
import
print_function
,
division
from
Card
import
Hand
,
Deck
class
PokerHand
(
Hand
):
"""Represents a poker hand."""
def
suit_hist
(
self
):
"""Builds a histogram of the suits that appear in the hand.
Stores the result in attribute suits.
"""
self
.
suits
=
{}
for
card
in
self
.
cards
:
self
.
suits
[
card
.
suit
]
=
self
.
suits
.
get
(
card
.
suit
,
0
)
+
1
def
has_flush
(
self
):
"""Returns True if the hand has a flush, False otherwise.
Note that this works correctly for hands with more than 5 cards.
"""
self
.
suit_hist
()
for
val
in
self
.
suits
.
values
():
if
val
>=
5
:
return
True
return
False
if
__name__
==
'__main__'
:
# make a deck
deck
=
Deck
()
deck
.
shuffle
()
# deal the cards and classify the hands
for
i
in
range
(
7
):
hand
=
PokerHand
()
deck
.
move_cards
(
hand
,
7
)
hand
.
sort
()
print
(
hand
)
print
(
hand
.
has_flush
())
print
(
''
)
Back
|
FazBrowse Home
|
New Git URL