Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Menteur
Commits
f759fb4b
Unverified
Commit
f759fb4b
authored
Apr 04, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Score Pair vs single
parent
f62a31a3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
12 deletions
+116
-12
data.py
model/data.py
+88
-12
test_data.py
test/test_data.py
+28
-0
No files found.
model/data.py
View file @
f759fb4b
...
...
@@ -35,17 +35,34 @@ class Card:
value
:
Value
color
:
Color
def
__cmp__
(
self
,
other
:
"Card"
):
my
=
self
.
score
()
their
=
other
.
score
()
return
(
my
>
their
)
-
(
my
<
their
)
def
__lt__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
<
other
.
score
())
def
__gt__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
>
other
.
score
())
def
__eq__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
==
other
.
score
())
def
__str__
(
self
)
->
str
:
return
f
"{self.color.value} {self.value.name} {self.color.value}"
def
score
(
self
)
->
int
:
return
int
(
self
.
value
.
value
)
class
Hand
:
def
__init__
(
self
,
cards
=
None
):
def
__init__
(
self
,
cards
:
List
[
Card
]
=
None
):
if
cards
is
None
:
cards
=
[]
self
.
cards
:
List
[
Card
]
=
cards
def
__len__
(
self
):
def
__len__
(
self
)
->
int
:
return
len
(
self
.
cards
)
def
__getitem__
(
self
,
item
):
...
...
@@ -55,16 +72,75 @@ class Hand:
self
.
cards
.
append
(
other
)
def
value
(
self
):
print
(
f
"Looking at value of {len(self.cards)} cards"
)
counter
=
Counter
(
self
.
cards
)
print
(
counter
)
if
len
(
self
.
cards
)
==
1
:
# Simple, v=x
return
int
(
self
.
cards
[
0
]
.
value
.
value
)
# elif len(self.cards) == 2: # Paire, v=20*x
# elif len(self.cards) == 3: # Brelan ou paire, v=20*x
# elif len(self.cards) == 2: # Paire, v=20*x
# elif len(self.cards) == 2: # Paire, v=20*x
counter
=
Counter
([
c
.
value
for
c
in
self
.
cards
])
has_pair
=
False
has_double_pair
=
False
has_brelan
=
False
has_full
=
False
has_carre
=
False
highest_card
=
None
pair
=
None
double_pair
=
None
brelan
=
None
full_des
=
None
full_par
=
None
carre
=
None
for
element
,
count
in
counter
.
items
():
element_cards
=
[
c
for
c
in
self
.
cards
if
c
.
value
==
element
]
card
=
element_cards
[
0
]
# Note we take a random color
highest_card
=
max
(
highest_card
,
card
)
if
highest_card
else
card
if
count
==
2
:
if
has_pair
:
has_double_pair
=
True
double_pair
=
max
(
pair
,
card
)
pair
=
min
(
pair
,
card
)
else
:
has_pair
=
True
pair
=
max
(
pair
,
card
)
if
pair
else
card
if
count
==
3
:
has_brelan
=
True
brelan
=
max
(
brelan
,
card
)
if
brelan
else
card
if
has_brelan
and
has_pair
:
has_full
=
True
full_des
=
max
(
brelan
,
card
)
if
brelan
else
card
full_par
=
max
(
pair
,
card
)
if
pair
else
card
if
count
==
4
:
has_carre
=
True
carre
=
max
(
carre
,
card
)
if
carre
else
card
print
(
""
.
join
([
f
"End of analysis: "
,
f
"Carre[{carre}]"
if
has_carre
else
"no carre | "
,
f
"Full[{full_des}|{full_par}]"
if
has_full
else
"no full | "
,
f
"Brelan[{brelan}]"
if
has_brelan
else
"no carre | "
,
f
"Double paire[{double_pair}|{pair}]"
if
has_double_pair
else
"no Dpaire | "
,
f
"Paire[{pair}]"
if
has_pair
else
"no paire | "
,
f
"Card[{highest_card}]"
]),
end
=
" "
)
# Finished counting, let's return scores
if
has_carre
:
print
(
"LE CARRE, LE CARRE!"
)
score
=
(
20
^
5
)
*
carre
.
score
()
elif
has_full
:
print
(
"Fouloulou"
)
score
=
(
20
^
4
)
*
full_des
.
score
()
+
full_par
elif
has_brelan
:
print
(
"BRELAN!"
)
score
=
(
20
^
3
)
*
brelan
.
score
()
elif
has_double_pair
:
print
(
"Double Paire!"
)
score
=
(
20
^
2
)
*
double_pair
.
score
()
+
pair
.
score
()
elif
has_pair
:
print
(
"Paire!"
)
score
=
(
20
^
2
)
*
pair
.
score
()
else
:
score
=
highest_card
.
score
()
print
(
"-> score="
,
score
)
return
score
class
Deck
:
...
...
test/test_data.py
View file @
f759fb4b
...
...
@@ -67,3 +67,31 @@ class TestHand(TestCase):
lowHand
=
Hand
([
Card
(
lowValue
,
Color
.
Hearts
)])
self
.
assertGreater
(
highHand
.
value
(),
lowHand
.
value
())
def
testPair
(
self
):
lowValue
:
Value
=
Value
.
Two
for
value
in
[
Value
.
Three
,
Value
.
Four
,
Value
.
Five
,
Value
.
Six
,
Value
.
Seven
,
Value
.
Eight
,
Value
.
Nine
,
Value
.
Ten
,
Value
.
Jack
,
Value
.
Queen
,
Value
.
King
,
Value
.
Ace
,
]:
highHand
:
Hand
=
Hand
([
Card
(
value
,
Color
.
Hearts
),
Card
(
value
,
Color
.
Clubs
)])
singleHand
:
Hand
=
Hand
([
ACE_OF_HEARTS
])
lowHand
:
Hand
=
Hand
([
Card
(
lowValue
,
Color
.
Hearts
),
Card
(
lowValue
,
Color
.
Clubs
)])
highScore
=
highHand
.
value
()
singleScore
=
singleHand
.
value
()
lowScore
=
lowHand
.
value
()
self
.
assertGreater
(
highScore
,
singleScore
,
f
"Pair[{highHand.cards}] > Ace"
)
self
.
assertGreater
(
highScore
,
lowScore
,
f
"Pair[{highHand.cards}] > Pair[{lowHand.cards}]]"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment