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
b62cff4c
Unverified
Commit
b62cff4c
authored
Apr 04, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(score): Test all hands
parent
8cff0217
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
20 deletions
+107
-20
data.py
model/data.py
+8
-12
hands.py
model/hands.py
+12
-2
test_data.py
test/test_data.py
+87
-6
No files found.
model/data.py
View file @
b62cff4c
...
@@ -2,7 +2,7 @@ from collections import defaultdict, Counter
...
@@ -2,7 +2,7 @@ from collections import defaultdict, Counter
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
enum
import
Enum
from
enum
import
Enum
from
random
import
shuffle
,
randrange
from
random
import
shuffle
,
randrange
from
typing
import
List
,
Dict
from
typing
import
List
,
Dict
,
Optional
from
model.animals
import
random_animal_name
from
model.animals
import
random_animal_name
...
@@ -33,7 +33,7 @@ class Color(Enum):
...
@@ -33,7 +33,7 @@ class Color(Enum):
@dataclass
(
frozen
=
True
)
@dataclass
(
frozen
=
True
)
class
Card
:
class
Card
:
value
:
Value
value
:
Value
color
:
Color
color
:
Optional
[
Color
]
=
None
def
__cmp__
(
self
,
other
:
"Card"
):
def
__cmp__
(
self
,
other
:
"Card"
):
my
=
self
.
score
()
my
=
self
.
score
()
...
@@ -41,16 +41,16 @@ class Card:
...
@@ -41,16 +41,16 @@ class Card:
return
(
my
>
their
)
-
(
my
<
their
)
return
(
my
>
their
)
-
(
my
<
their
)
def
__lt__
(
self
,
other
:
"Card"
):
def
__lt__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
<
other
.
score
()
)
return
self
.
score
()
<
other
.
score
(
)
def
__gt__
(
self
,
other
:
"Card"
):
def
__gt__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
>
other
.
score
()
)
return
self
.
score
()
>
other
.
score
(
)
def
__eq__
(
self
,
other
:
"Card"
):
def
__eq__
(
self
,
other
:
"Card"
):
return
(
self
.
score
()
==
other
.
score
()
)
return
self
.
score
()
==
other
.
score
(
)
def
__str__
(
self
)
->
str
:
def
__str__
(
self
)
->
str
:
return
f
"{self.value.
value} {self.color.value
}"
return
f
"{self.value.
name} of {self.color.value if self.color else '?'
}"
def
score
(
self
)
->
int
:
def
score
(
self
)
->
int
:
return
int
(
self
.
value
.
value
)
return
int
(
self
.
value
.
value
)
...
@@ -88,8 +88,6 @@ class Hand:
...
@@ -88,8 +88,6 @@ class Hand:
pair
=
None
pair
=
None
double_pair
=
None
double_pair
=
None
brelan
=
None
brelan
=
None
full_des
=
None
full_par
=
None
carre
=
None
carre
=
None
for
element
,
count
in
counter
.
items
():
for
element
,
count
in
counter
.
items
():
...
@@ -110,8 +108,6 @@ class Hand:
...
@@ -110,8 +108,6 @@ class Hand:
brelan
=
max
(
brelan
,
card
)
if
brelan
else
card
brelan
=
max
(
brelan
,
card
)
if
brelan
else
card
if
has_brelan
and
has_pair
:
if
has_brelan
and
has_pair
:
has_full
=
True
has_full
=
True
full_des
=
max
(
brelan
,
card
)
if
brelan
else
card
full_par
=
max
(
pair
,
card
)
if
pair
else
card
if
count
==
4
:
if
count
==
4
:
has_carre
=
True
has_carre
=
True
carre
=
max
(
carre
,
card
)
if
carre
else
card
carre
=
max
(
carre
,
card
)
if
carre
else
card
...
@@ -119,7 +115,7 @@ class Hand:
...
@@ -119,7 +115,7 @@ class Hand:
print
(
" | "
.
join
([
print
(
" | "
.
join
([
f
"ANALYSIS"
,
f
"ANALYSIS"
,
f
"Carre[{carre}]"
if
has_carre
else
"no carre"
,
f
"Carre[{carre}]"
if
has_carre
else
"no carre"
,
f
"Full[{
full_des}|{full_pa
r}]"
if
has_full
else
"no full"
,
f
"Full[{
brelan}|{pai
r}]"
if
has_full
else
"no full"
,
f
"Brelan[{brelan}]"
if
has_brelan
else
"no carre"
,
f
"Brelan[{brelan}]"
if
has_brelan
else
"no carre"
,
f
"Double paire[{double_pair}|{pair}]"
if
has_double_pair
else
"no Dpaire"
,
f
"Double paire[{double_pair}|{pair}]"
if
has_double_pair
else
"no Dpaire"
,
f
"Paire[{pair}]"
if
has_pair
else
"no paire"
,
f
"Paire[{pair}]"
if
has_pair
else
"no paire"
,
...
@@ -129,7 +125,7 @@ class Hand:
...
@@ -129,7 +125,7 @@ class Hand:
if
has_carre
:
if
has_carre
:
score
=
(
20
**
5
)
*
carre
.
score
()
score
=
(
20
**
5
)
*
carre
.
score
()
elif
has_full
:
elif
has_full
:
score
=
(
20
**
4
)
*
full_des
.
score
()
+
full_pa
r
.
score
()
score
=
(
20
**
4
)
*
brelan
.
score
()
+
20
*
pai
r
.
score
()
elif
has_brelan
:
elif
has_brelan
:
score
=
(
20
**
3
)
*
brelan
.
score
()
score
=
(
20
**
3
)
*
brelan
.
score
()
elif
has_double_pair
:
elif
has_double_pair
:
...
...
model/hands.py
View file @
b62cff4c
...
@@ -10,6 +10,17 @@ def carre(value) -> Hand:
...
@@ -10,6 +10,17 @@ def carre(value) -> Hand:
])
])
def
full
(
value_aux
:
Value
,
value_par
:
Value
)
->
Hand
:
return
Hand
([
Card
(
value_aux
,
Color
.
Hearts
),
Card
(
value_aux
,
Color
.
Clubs
),
Card
(
value_aux
,
Color
.
Spades
),
Card
(
value_par
,
Color
.
Hearts
),
Card
(
value_par
,
Color
.
Clubs
)
])
def
brelan
(
value
)
->
Hand
:
def
brelan
(
value
)
->
Hand
:
return
Hand
([
return
Hand
([
Card
(
value
,
Color
.
Hearts
),
Card
(
value
,
Color
.
Hearts
),
...
@@ -44,4 +55,4 @@ def double_pair(value: Value, other: Value = None):
...
@@ -44,4 +55,4 @@ def double_pair(value: Value, other: Value = None):
# And pair of twos or threes
# And pair of twos or threes
Card
(
other
,
Color
.
Hearts
),
Card
(
other
,
Color
.
Hearts
),
Card
(
other
,
Color
.
Clubs
)
Card
(
other
,
Color
.
Clubs
)
])
])
\ No newline at end of file
test/test_data.py
View file @
b62cff4c
from
unittest
import
TestCase
from
unittest
import
TestCase
from
model.data
import
Deck
,
Player
,
Card
,
Value
,
Color
,
Hand
from
model.data
import
Deck
,
Player
,
Card
,
Value
,
Color
,
Hand
from
model.hands
import
brelan
,
pair
,
single
,
double_pair
from
model.hands
import
full
,
brelan
,
pair
,
single
,
double_pair
,
carre
ACE_OF_HEARTS
=
Card
(
Value
.
Ace
,
Color
.
Hearts
)
ACE_OF_HEARTS
=
Card
(
Value
.
Ace
,
Color
.
Hearts
)
ACE_OF_SPADES
=
Card
(
Value
.
Ace
,
Color
.
Spades
)
ACE_OF_SPADES
=
Card
(
Value
.
Ace
,
Color
.
Spades
)
...
@@ -11,6 +11,8 @@ ACE_OF_CLUBS = Card(Value.Ace, Color.Clubs)
...
@@ -11,6 +11,8 @@ ACE_OF_CLUBS = Card(Value.Ace, Color.Clubs)
PAIR_ACE
=
pair
(
Value
.
Ace
)
PAIR_ACE
=
pair
(
Value
.
Ace
)
SINGLE_ACE
=
single
(
Value
.
Ace
)
SINGLE_ACE
=
single
(
Value
.
Ace
)
DOUBLE_PAIR_ACE
=
double_pair
(
Value
.
Ace
)
DOUBLE_PAIR_ACE
=
double_pair
(
Value
.
Ace
)
BRELAN_ACE
=
brelan
(
Value
.
Ace
)
FULL_ACE
=
full
(
Value
.
Ace
,
Value
.
King
)
class
TestDeck
(
TestCase
):
class
TestDeck
(
TestCase
):
...
@@ -51,7 +53,7 @@ class TestPlayer(TestCase):
...
@@ -51,7 +53,7 @@ class TestPlayer(TestCase):
pass
pass
def
lowest_
card
_and_rest
():
def
lowest_
value
_and_rest
():
lowValue
:
Value
=
Value
.
Two
lowValue
:
Value
=
Value
.
Two
otherValues
=
list
(
Value
)
otherValues
=
list
(
Value
)
otherValues
.
remove
(
lowValue
)
otherValues
.
remove
(
lowValue
)
...
@@ -64,7 +66,7 @@ class TestHand(TestCase):
...
@@ -64,7 +66,7 @@ class TestHand(TestCase):
self
.
hand
=
Hand
()
self
.
hand
=
Hand
()
def
testSimple
(
self
):
def
testSimple
(
self
):
low_value
,
other_values
=
lowest_
card
_and_rest
()
low_value
,
other_values
=
lowest_
value
_and_rest
()
for
value
in
other_values
:
for
value
in
other_values
:
high_hand
=
single
(
value
)
high_hand
=
single
(
value
)
...
@@ -73,7 +75,7 @@ class TestHand(TestCase):
...
@@ -73,7 +75,7 @@ class TestHand(TestCase):
self
.
assertGreater
(
high_hand
.
value
(),
low_hand
.
value
())
self
.
assertGreater
(
high_hand
.
value
(),
low_hand
.
value
())
def
testPair
(
self
):
def
testPair
(
self
):
low_value
,
other_values
=
lowest_
card
_and_rest
()
low_value
,
other_values
=
lowest_
value
_and_rest
()
for
value
in
other_values
:
for
value
in
other_values
:
high_hand
:
Hand
=
pair
(
value
)
high_hand
:
Hand
=
pair
(
value
)
...
@@ -88,7 +90,7 @@ class TestHand(TestCase):
...
@@ -88,7 +90,7 @@ class TestHand(TestCase):
self
.
assertGreater
(
high_score
,
single_score
,
f
"Pair[{high_hand}] > Ace"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"Pair[{high_hand}] > Ace"
)
def
testDoublePair
(
self
):
def
testDoublePair
(
self
):
low_value
,
other_values
=
lowest_
card
_and_rest
()
low_value
,
other_values
=
lowest_
value
_and_rest
()
for
value
in
other_values
:
for
value
in
other_values
:
high_hand
:
Hand
=
double_pair
(
value
)
high_hand
:
Hand
=
double_pair
(
value
)
...
@@ -111,7 +113,7 @@ class TestHand(TestCase):
...
@@ -111,7 +113,7 @@ class TestHand(TestCase):
self
.
assertGreater
(
high_score
,
single_score
,
f
"DoublePair[{high_hand}] > Ace"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"DoublePair[{high_hand}] > Ace"
)
def
testBrelan
(
self
):
def
testBrelan
(
self
):
low_value
,
other_values
=
lowest_
card
_and_rest
()
low_value
,
other_values
=
lowest_
value
_and_rest
()
for
value
in
other_values
:
for
value
in
other_values
:
high_hand
:
Hand
=
brelan
(
value
)
high_hand
:
Hand
=
brelan
(
value
)
...
@@ -130,3 +132,82 @@ class TestHand(TestCase):
...
@@ -130,3 +132,82 @@ class TestHand(TestCase):
self
.
assertGreater
(
high_score
,
double_pair_score
,
f
"Brelan[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
double_pair_score
,
f
"Brelan[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
pair_score
,
f
"Brelan[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
pair_score
,
f
"Brelan[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"Brelan[{high_hand}] > Ace"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"Brelan[{high_hand}] > Ace"
)
def
testFulls
(
self
):
# AssertionError: 24060 not greater than 24060 :
# Full[Three of ♥|Three of ♣|Three of ♠|Four of ♥|Four of ♣]
# > Full[Two of ♥|Two of ♣|Two of ♠|Four of ♥|Four of ♣]]
full1
=
Hand
([
Card
(
v
)
for
v
in
[
Value
.
Three
,
Value
.
Three
,
Value
.
Three
,
Value
.
Four
,
Value
.
Four
,
]])
full2
=
Hand
([
Card
(
v
)
for
v
in
[
Value
.
Two
,
Value
.
Two
,
Value
.
Two
,
Value
.
Four
,
Value
.
Four
,
]])
self
.
assertGreater
(
full1
.
value
(),
full2
.
value
(),
"Full1 > full2 (threes >> twos)"
)
def
testFull
(
self
):
low_value
,
other_values
=
lowest_value_and_rest
()
for
full_aux
in
other_values
:
# Full_aux: brelan
full_options
=
other_values
.
copy
()
full_options
.
remove
(
full_aux
)
full_options
.
append
(
low_value
)
for
full_par
in
full_options
:
# Full_des: paire
high_hand
:
Hand
=
full
(
full_aux
,
full_par
)
low_hand
:
Hand
=
full
(
low_value
,
full_par
)
brelan_hand
:
Hand
=
BRELAN_ACE
double_pair_hand
:
Hand
=
DOUBLE_PAIR_ACE
pair_hand
:
Hand
=
PAIR_ACE
single_hand
:
Hand
=
SINGLE_ACE
high_score
=
high_hand
.
value
()
low_score
=
low_hand
.
value
()
brelan_score
=
brelan_hand
.
value
()
double_pair_score
=
double_pair_hand
.
value
()
pair_score
=
pair_hand
.
value
()
single_score
=
single_hand
.
value
()
self
.
assertGreater
(
high_score
,
low_score
,
f
"Full[{high_hand}] > Full[{low_hand}]]"
)
self
.
assertGreater
(
high_score
,
brelan_score
,
f
"Full[{high_hand}] > Brelan[Ace]"
)
self
.
assertGreater
(
high_score
,
double_pair_score
,
f
"Full[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
pair_score
,
f
"Full[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"Full[{high_hand}] > Ace"
)
def
testCarre
(
self
):
low_value
,
other_values
=
lowest_value_and_rest
()
for
value
in
other_values
:
high_hand
:
Hand
=
carre
(
value
)
low_hand
:
Hand
=
carre
(
low_value
)
full_hand
:
Hand
=
FULL_ACE
brelan_hand
:
Hand
=
BRELAN_ACE
double_pair_hand
:
Hand
=
DOUBLE_PAIR_ACE
pair_hand
:
Hand
=
PAIR_ACE
single_hand
:
Hand
=
SINGLE_ACE
high_score
=
high_hand
.
value
()
low_score
=
low_hand
.
value
()
full_score
=
full_hand
.
value
()
brelan_score
=
brelan_hand
.
value
()
double_pair_score
=
double_pair_hand
.
value
()
pair_score
=
pair_hand
.
value
()
single_score
=
single_hand
.
value
()
self
.
assertGreater
(
high_score
,
low_score
,
f
"Carre[{high_hand}] > Carre[{low_hand}]]"
)
self
.
assertGreater
(
high_score
,
full_score
,
f
"Carre[{high_hand}] > Full[Ace]]"
)
self
.
assertGreater
(
high_score
,
brelan_score
,
f
"Carre[{high_hand}] > Brelan[Ace]"
)
self
.
assertGreater
(
high_score
,
double_pair_score
,
f
"Carre[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
pair_score
,
f
"Carre[{high_hand}] > Pair[Ace]"
)
self
.
assertGreater
(
high_score
,
single_score
,
f
"Carre[{high_hand}] > Ace"
)
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