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
a1c60615
Unverified
Commit
a1c60615
authored
Apr 04, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Player): str, test_full_game()
parent
11dc9ff8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
data.py
model/data.py
+11
-8
test_game.py
test/test_game.py
+8
-2
No files found.
model/data.py
View file @
a1c60615
...
@@ -25,6 +25,9 @@ class Player:
...
@@ -25,6 +25,9 @@ class Player:
self
.
name
:
str
=
name
self
.
name
:
str
=
name
self
.
hand
:
Hand
=
Hand
()
self
.
hand
:
Hand
=
Hand
()
def
__str__
(
self
):
return
f
"Player {self.name}"
def
give
(
self
,
card
:
Card
):
def
give
(
self
,
card
:
Card
):
self
.
hand
.
give
(
card
)
self
.
hand
.
give
(
card
)
...
@@ -57,13 +60,13 @@ class Game:
...
@@ -57,13 +60,13 @@ class Game:
loser
=
self
.
new_turn
()
loser
=
self
.
new_turn
()
if
self
.
defeats
[
loser
]
==
5
:
if
self
.
defeats
[
loser
]
==
5
:
print
(
f
"
Player
{loser} is eliminated!"
)
print
(
f
"{loser} is eliminated!"
)
self
.
players
.
remove
(
loser
)
self
.
players
.
remove
(
loser
)
else
:
else
:
print
(
f
"
Player
{loser} lost the round, now playing with {self.defeats[loser] + 1} cards!"
)
print
(
f
"{loser} lost the round, now playing with {self.defeats[loser] + 1} cards!"
)
winner
=
self
.
players
[
0
]
winner
=
self
.
players
[
0
]
print
(
f
"Game over -
Player
{winner.name} wins with {len(winner.hand)} cards!"
)
print
(
f
"Game over - {winner.name} wins with {len(winner.hand)} cards!"
)
def
new_turn
(
self
)
->
Player
:
def
new_turn
(
self
)
->
Player
:
"""
"""
...
@@ -80,13 +83,13 @@ class Game:
...
@@ -80,13 +83,13 @@ class Game:
current_bet
:
Optional
[
Hand
]
=
None
current_bet
:
Optional
[
Hand
]
=
None
last_player
=
None
last_player
=
None
for
current_player
in
itertools
.
cycle
(
self
.
players
):
for
current_player
in
itertools
.
cycle
(
self
.
players
):
print
(
f
"|
Player {current_player.name
}'s turn >"
)
print
(
f
"|
{current_player
}'s turn >"
)
if
not
current_bet
:
# First player, has to bet something
if
not
current_bet
:
# First player, has to bet something
while
not
current_bet
:
while
not
current_bet
:
announce
=
current_player
.
announce
(
current_bet
)
announce
=
current_player
.
announce
(
current_bet
)
if
announce
.
bet
:
if
announce
.
bet
:
current_bet
=
announce
.
bet
current_bet
=
announce
.
bet
print
(
f
"
Player {current_player.name
} starts the round: {current_bet}"
)
print
(
f
"
{current_player
} starts the round: {current_bet}"
)
else
:
# Next player, announce or menteur
else
:
# Next player, announce or menteur
announce
=
current_player
.
announce
(
current_bet
)
announce
=
current_player
.
announce
(
current_bet
)
if
announce
.
bet
:
if
announce
.
bet
:
...
@@ -94,12 +97,12 @@ class Game:
...
@@ -94,12 +97,12 @@ class Game:
print
(
f
"Invalid bet, {announce.bet} < {current_bet}!"
)
print
(
f
"Invalid bet, {announce.bet} < {current_bet}!"
)
announce
=
current_player
.
announce
(
current_bet
)
announce
=
current_player
.
announce
(
current_bet
)
current_bet
=
announce
.
bet
current_bet
=
announce
.
bet
print
(
f
"
Player {current_player.name
} bets {current_bet}."
)
print
(
f
"
{current_player
} bets {current_bet}."
)
else
:
# Menteur! Who lost the round?
else
:
# Menteur! Who lost the round?
menteur
=
self
.
is_menteur
(
current_bet
)
menteur
=
self
.
is_menteur
(
current_bet
)
print
(
f
"
Player {current_player.name
} says Menteur... {'Bravo!' if menteur else 'FAIL!'}"
)
print
(
f
"
{current_player
} says Menteur... {'Bravo!' if menteur else 'FAIL!'}"
)
loser
=
last_player
if
menteur
else
current_player
loser
=
last_player
if
menteur
else
current_player
print
(
f
"
Player {loser.name
} lost the round!"
)
print
(
f
"
{loser
} lost the round!"
)
self
.
count_defeat
(
loser
)
self
.
count_defeat
(
loser
)
return
loser
return
loser
last_player
=
current_player
last_player
=
current_player
...
...
test/test_game.py
View file @
a1c60615
...
@@ -6,8 +6,8 @@ from model.data import Game, Player
...
@@ -6,8 +6,8 @@ from model.data import Game, Player
class
TestGame
(
TestCase
):
class
TestGame
(
TestCase
):
def
setUp
(
self
)
->
None
:
def
setUp
(
self
)
->
None
:
super
()
.
setUp
()
super
()
.
setUp
()
self
.
player1
=
Player
(
name
=
"
"
)
self
.
player1
=
Player
(
"PLN
"
)
self
.
player2
=
Player
()
self
.
player2
=
Player
(
"Nassim"
)
self
.
game
=
Game
([
self
.
player1
,
self
.
player2
])
self
.
game
=
Game
([
self
.
player1
,
self
.
player2
])
def
test_global_hand
(
self
)
->
None
:
def
test_global_hand
(
self
)
->
None
:
...
@@ -28,3 +28,9 @@ class TestGame(TestCase):
...
@@ -28,3 +28,9 @@ class TestGame(TestCase):
self
.
assertEqual
(
1
,
len
(
self
.
game
.
defeats
.
values
()),
"There should have been one defeat."
)
self
.
assertEqual
(
1
,
len
(
self
.
game
.
defeats
.
values
()),
"There should have been one defeat."
)
self
.
assertTrue
(
1
in
self
.
game
.
defeats
.
values
(),
"A player should have one defeat."
)
self
.
assertTrue
(
1
in
self
.
game
.
defeats
.
values
(),
"A player should have one defeat."
)
def
test_full_game
(
self
):
self
.
game
.
new_game
()
self
.
assertGreater
(
len
(
self
.
game
.
defeats
.
values
()),
0
,
"There should be at least one player with defeats."
)
self
.
assertTrue
(
5
in
self
.
game
.
defeats
.
values
(),
"A player should have lost five times."
)
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