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
f62a31a3
Unverified
Commit
f62a31a3
authored
Apr 04, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Hand): base + score simple
parent
1b879a99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
23 deletions
+75
-23
data.py
model/data.py
+45
-21
test_data.py
test/test_data.py
+30
-2
No files found.
model/data.py
View file @
f62a31a3
from
collections
import
defaultdict
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
...
@@ -8,19 +8,19 @@ from model.animals import random_animal_name
...
@@ -8,19 +8,19 @@ from model.animals import random_animal_name
class
Value
(
Enum
):
class
Value
(
Enum
):
Ace
=
1
Two
=
1
T
wo
=
2
T
hree
=
2
Three
=
3
Four
=
3
F
our
=
4
F
ive
=
4
Five
=
5
Six
=
5
S
ix
=
6
S
even
=
6
Seven
=
7
Eight
=
7
Eight
=
8
Nine
=
8
Nine
=
9
Ten
=
9
Ten
=
10
Jack
=
10
Jack
=
11
Queen
=
11
Queen
=
12
King
=
12
King
=
13
Ace
=
13
class
Color
(
Enum
):
class
Color
(
Enum
):
...
@@ -39,6 +39,34 @@ class Card:
...
@@ -39,6 +39,34 @@ class Card:
return
f
"{self.color.value} {self.value.name} {self.color.value}"
return
f
"{self.color.value} {self.value.name} {self.color.value}"
class
Hand
:
def
__init__
(
self
,
cards
=
None
):
if
cards
is
None
:
cards
=
[]
self
.
cards
:
List
[
Card
]
=
cards
def
__len__
(
self
):
return
len
(
self
.
cards
)
def
__getitem__
(
self
,
item
):
return
self
.
cards
[
item
]
def
give
(
self
,
other
:
Card
):
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
class
Deck
:
class
Deck
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
cards
=
[
Card
(
v
,
c
)
for
v
in
Value
for
c
in
Color
]
self
.
cards
=
[
Card
(
v
,
c
)
for
v
in
Value
for
c
in
Color
]
...
@@ -63,10 +91,10 @@ class Deck:
...
@@ -63,10 +91,10 @@ class Deck:
class
Player
:
class
Player
:
name
:
str
=
random_animal_name
()
name
:
str
=
random_animal_name
()
hand
:
List
[
Card
]
=
[]
hand
:
Hand
=
Hand
()
def
give
(
self
,
card
:
Card
):
def
give
(
self
,
card
:
Card
):
self
.
hand
.
append
(
card
)
self
.
hand
.
give
(
card
)
class
Game
:
class
Game
:
...
@@ -96,7 +124,4 @@ class Game:
...
@@ -96,7 +124,4 @@ class Game:
for
p
in
self
.
players
:
for
p
in
self
.
players
:
announce
=
p
.
announce
(
current_bet
)
announce
=
p
.
announce
(
current_bet
)
# TODO: Put next first player first of list
# TODO: Put next first player first of list
\ No newline at end of file
test/test_data.py
View file @
f62a31a3
from
unittest
import
TestCase
from
unittest
import
TestCase
from
model.data
import
Deck
,
Player
,
Card
,
Value
,
Color
from
model.data
import
Deck
,
Player
,
Card
,
Value
,
Color
,
Hand
ACE_OF_HEARTS
=
Card
(
Value
.
Ace
,
Color
.
Hearts
)
class
TestDeck
(
TestCase
):
class
TestDeck
(
TestCase
):
...
@@ -31,7 +33,7 @@ class TestPlayer(TestCase):
...
@@ -31,7 +33,7 @@ class TestPlayer(TestCase):
self
.
assertEqual
(
0
,
len
(
self
.
player
.
hand
),
"Begin no cards"
)
self
.
assertEqual
(
0
,
len
(
self
.
player
.
hand
),
"Begin no cards"
)
self
.
assertTrue
(
len
(
self
.
player
.
name
),
"Has a name"
)
self
.
assertTrue
(
len
(
self
.
player
.
name
),
"Has a name"
)
self
.
player
.
give
(
Card
(
Value
.
Ace
,
Color
.
Hearts
)
)
self
.
player
.
give
(
ACE_OF_HEARTS
)
self
.
assertEqual
(
1
,
len
(
self
.
player
.
hand
),
"Gave one card"
)
self
.
assertEqual
(
1
,
len
(
self
.
player
.
hand
),
"Gave one card"
)
self
.
assertEqual
(
Value
.
Ace
,
self
.
player
.
hand
[
0
]
.
value
,
"Is Ace"
)
self
.
assertEqual
(
Value
.
Ace
,
self
.
player
.
hand
[
0
]
.
value
,
"Is Ace"
)
...
@@ -39,3 +41,29 @@ class TestPlayer(TestCase):
...
@@ -39,3 +41,29 @@ class TestPlayer(TestCase):
def
testDefeats
(
self
):
def
testDefeats
(
self
):
pass
pass
class
TestHand
(
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
hand
=
Hand
()
def
testSimple
(
self
):
lowValue
=
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
([
Card
(
value
,
Color
.
Hearts
)])
lowHand
=
Hand
([
Card
(
lowValue
,
Color
.
Hearts
)])
self
.
assertGreater
(
highHand
.
value
(),
lowHand
.
value
())
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