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
c7c10c0b
Unverified
Commit
c7c10c0b
authored
May 03, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(Game): Unfreshen announce, better extras, reset ready when done playing
parent
6e8d3d76
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
11 deletions
+27
-11
lobby.py
server/game/lobby.py
+15
-7
message.py
server/game/message.py
+1
-0
game.py
server/model/game.py
+8
-3
ws.py
server/ws.py
+3
-1
No files found.
server/game/lobby.py
View file @
c7c10c0b
import
asyncio
import
json
import
sys
from
sys
import
stderr
from
typing
import
List
,
Dict
,
Optional
...
...
@@ -91,13 +92,14 @@ class LobbyManager(ClientManager):
game
=
Game
(
players
,
manager
=
self
)
self
.
games
.
append
(
game
)
print
(
f
"Game started : {' vs '.join([p.name for p in players])}"
)
winner
=
await
game
.
new_game
()
print
(
f
"Game ended : winner is {winner.name}! {len(players)} players back waiting in lobby."
)
for
p
in
players
:
self
.
metadata
[
p
.
name
]
.
ready
=
False
print
(
f
"Game started : {' vs '.join([p.name for p in players])}"
)
await
game
.
new_game
()
async
def
reset
(
self
):
async
def
reset
(
self
)
->
str
:
players
=
len
(
self
.
players
)
games
=
len
(
self
.
games
)
msg
=
f
"Resetting! sorry for the {players} players / {games} games..."
...
...
@@ -110,12 +112,18 @@ class LobbyManager(ClientManager):
self
.
players
.
clear
()
self
.
metadata
.
clear
()
self
.
games
.
clear
()
print
(
f
"Reset done, {players} players, {games} games."
)
return
msg
async
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extras
=
None
):
async
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extras
=
None
)
->
None
:
sid
:
str
=
"?"
try
:
sid
=
self
.
metadata
[
to
.
name
]
.
sid
game
=
self
.
game_with
(
to
)
except
KeyError
as
e
:
print
(
f
"Error: Cannot send message to player {to.name}"
,
file
=
stderr
)
return
# TODO: Warn other players and kill game
game
:
Game
=
self
.
game_with
(
to
)
data
=
to
.
hand
.
json
()
# Start with "cards": []
data
=
json
.
loads
(
data
)
# JSONEncode and decode, starting with dict would miss `json()` encoders
...
...
server/game/message.py
View file @
c7c10c0b
...
...
@@ -9,6 +9,7 @@ class MessageToPlayer(Enum):
GiveHand
=
"GIVE_HAND"
WaitTurn
=
"WAITING_TURN"
YourTurn
=
"YOUR_TURN"
WrongAnnounce
=
"WRONG_ANNOUNCE"
Announce
=
"ANNOUNCE"
LoseRound
=
"LOSE_ROUND"
Win
=
"WINNER"
...
...
server/model/game.py
View file @
c7c10c0b
import
itertools
from
collections
import
defaultdict
from
time
import
sleep
from
typing
import
List
,
Dict
,
Optional
from
server.game.manager
import
ClientManager
...
...
@@ -57,8 +58,9 @@ class Game:
winner
=
self
.
players
[
0
]
await
self
.
message
(
MessageToPlayer
.
Win
,
winner
)
await
self
.
message
(
MessageToPlayer
.
WinnerIs
,
extras
=
winner
)
await
self
.
message
(
MessageToPlayer
.
WinnerIs
,
extras
=
{
"winner"
:
winner
.
name
}
)
print
(
f
"Game over - {winner.name} wins with {len(winner.hand)} cards!"
)
return
winner
async
def
new_turn
(
self
)
->
Player
:
"""
...
...
@@ -149,7 +151,8 @@ class Game:
if
not
self
.
current_bet
:
# First player, has to bet something
print
(
"Game: First awaiting current bet"
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extras
=
self
.
current_bet
)
message
=
MessageToPlayer
.
YourTurn
await
self
.
message
(
message
,
current_player
,
extras
=
self
.
current_bet
)
while
not
self
.
current_bet
:
# Ask a valid bet
print
(
"Game: While no bet, awaiting"
)
announce
=
await
current_player
.
announce
(
self
.
current_bet
)
...
...
@@ -161,6 +164,8 @@ class Game:
extras
=
{
"player"
:
current_player
.
name
,
"announce"
:
announce
.
json
()})
else
:
print
(
f
"You cannot say Menteur on first round, {current_player}!"
)
message
=
MessageToPlayer
.
WrongAnnounce
sleep
(
5
)
else
:
# Next player, announce or menteur
...
...
@@ -170,7 +175,7 @@ class Game:
announce
=
Announce
()
# MENTEUR obligatoire
else
:
print
(
"Game: Awaiting bet"
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extras
=
self
.
current_bet
)
await
self
.
message
(
message
,
current_player
,
extras
=
self
.
current_bet
)
announce
=
await
current_player
.
announce
(
self
.
current_bet
)
if
announce
.
bet
:
...
...
server/ws.py
View file @
c7c10c0b
...
...
@@ -32,7 +32,9 @@ class ClientPlayer(Player):
sleep
(
5
)
print
(
f
"Client announced: {metadata.last_announce.bet}!"
)
return
metadata
.
last_announce
got_announce
=
metadata
.
last_announce
metadata
.
fresh_announce
=
False
return
got_announce
@sio.event
...
...
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