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
cfada799
Unverified
Commit
cfada799
authored
Apr 26, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Extract Value/Color, encoders
parent
ac8ad5b5
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
92 additions
and
37 deletions
+92
-37
encoding.py
server/encoding.py
+30
-0
lobby.py
server/game/lobby.py
+2
-2
card.py
server/model/card.py
+9
-23
deck.py
server/model/deck.py
+3
-1
game.py
server/model/game.py
+7
-5
hand.py
server/model/hand.py
+10
-1
hands.py
server/model/hands.py
+3
-1
known.py
server/model/known.py
+2
-1
value.py
server/model/value.py
+21
-0
requirements.txt
server/requirements.txt
+1
-1
test_data.py
server/test/test_data.py
+3
-1
test_lobby.py
server/test/test_lobby.py
+1
-1
No files found.
server/encoding.py
0 → 100644
View file @
cfada799
from
server.model.color
import
Color
from
server.model.value
import
Value
def
encode_value
(
v
:
Value
):
return
{
"Two"
:
"Deux"
,
"Three"
:
"Trois"
,
"Four"
:
"Quatre"
,
"Five"
:
"Cinq"
,
"Six"
:
"Six"
,
"Seven"
:
"Sept"
,
"Eight"
:
"Huit"
,
"Nine"
:
"Neuf"
,
"Ten"
:
"Dix"
,
"Jack"
:
"Valet"
,
"Queen"
:
"Dame"
,
"King"
:
"Roi"
,
"Ace"
:
"As"
}[
v
.
name
]
def
encode_color
(
c
:
Color
):
return
{
"Hearts"
:
"Coeur"
,
"Spades"
:
"Pique"
,
"Clubs"
:
"Trèfle"
,
"Diamonds"
:
"Carreau"
}[
c
.
name
]
\ No newline at end of file
server/game/lobby.py
View file @
cfada799
...
...
@@ -103,7 +103,7 @@ class LobbyManager(ClientManager):
data
[
"extra"
]
=
extras
print
(
f
"MSGOUT|{sid} ({to.name}), {data}"
)
await
self
.
sio
.
emit
(
'messageChannel'
,
json
.
dumps
(
data
),
room
=
sid
)
await
self
.
sio
.
emit
(
'messageChannel'
,
json
.
dumps
(
data
,
ensure_ascii
=
False
)
.
encode
(
"utf8"
),
room
=
sid
)
async
def
handle_message
(
self
,
sid
,
data
):
message
=
None
...
...
@@ -169,6 +169,6 @@ class LobbyManager(ClientManager):
async
def
send_waiting_for
(
self
,
player
:
Player
):
game
=
self
.
game_with
(
player
)
await
self
.
send
(
player
,
MessageToPlayer
.
YourTurn
,
extras
=
{
"bet"
:
game
.
current_bet
})
await
self
.
send
(
player
,
MessageToPlayer
.
YourTurn
,
extras
=
{
"bet"
:
game
.
current_bet
.
json
()
})
for
p
in
[
p
for
p
in
game
.
players
if
p
!=
player
]:
await
self
.
send
(
p
,
MessageToPlayer
.
Waiting
,
extras
=
{
"waitingFor"
:
p
.
name
})
server/model/card.py
View file @
cfada799
from
enum
import
Enum
from
typing
import
Optional
from
pydantic.main
import
BaseModel
class
Value
(
Enum
):
Two
=
1
Three
=
2
Four
=
3
Five
=
4
Six
=
5
Seven
=
6
Eight
=
7
Nine
=
8
Ten
=
9
Jack
=
10
Queen
=
11
King
=
12
Ace
=
13
class
Color
(
Enum
):
Hearts
=
"♥"
Spades
=
"♠"
Clubs
=
"♣"
Diamonds
=
"♦"
from
server.encoding
import
encode_value
,
encode_color
from
server.model.color
import
Color
from
server.model.value
import
Value
class
Card
(
BaseModel
):
value
:
Value
color
:
Optional
[
Color
]
=
None
class
Config
:
json_encoders
=
{
Value
:
encode_value
,
Color
:
encode_color
,
}
def
__cmp__
(
self
,
other
:
"Card"
):
my
=
self
.
score
()
their
=
other
.
score
()
...
...
server/model/deck.py
View file @
cfada799
from
random
import
randrange
,
shuffle
from
server.model.card
import
Card
,
Value
,
Color
from
server.model.card
import
Card
from
server.model.color
import
Color
from
server.model.value
import
Value
class
Deck
:
...
...
server/model/game.py
View file @
cfada799
...
...
@@ -4,10 +4,11 @@ from typing import List, Dict, Optional
from
server.game.manager
import
ClientManager
from
server.game.message
import
MessageToPlayer
from
server.model.card
import
Card
,
Value
from
server.model.card
import
Card
from
server.model.deck
import
Deck
from
server.model.hand
import
Hand
from
server.model.players
import
Player
,
Announce
from
server.model.value
import
Value
class
Game
:
...
...
@@ -26,9 +27,9 @@ class Game:
self
.
manager
=
manager
async
def
message
(
self
,
message
:
MessageToPlayer
,
*
to
:
Player
,
extra
=
None
)
->
None
:
*
to
:
Player
,
extra
=
None
)
->
None
:
if
self
.
manager
:
if
not
to
:
to
=
self
.
players
...
...
@@ -152,7 +153,8 @@ class Game:
self
.
current_bet
=
announce
.
bet
print
(
f
"{current_player} starts the round: {self.current_bet}"
)
print
(
"Game: Awaiting start announce"
)
await
self
.
message
(
MessageToPlayer
.
Announce
,
extra
=
{
"player"
:
current_player
.
name
,
"announce"
:
announce
.
json
()})
await
self
.
message
(
MessageToPlayer
.
Announce
,
extra
=
{
"player"
:
current_player
.
name
,
"announce"
:
announce
.
json
()})
else
:
print
(
f
"You cannot say Menteur on first round, {current_player}!"
)
...
...
server/model/hand.py
View file @
cfada799
...
...
@@ -3,12 +3,21 @@ from typing import List
from
pydantic.main
import
BaseModel
from
server.model.card
import
Card
,
Value
from
server.encoding
import
encode_color
,
encode_value
from
server.model.card
import
Card
from
server.model.color
import
Color
from
server.model.value
import
Value
class
Hand
(
BaseModel
):
cards
:
List
[
Card
]
=
[]
class
Config
:
json_encoders
=
{
Value
:
encode_value
,
Color
:
encode_color
,
}
def
__contains__
(
self
,
item
:
Card
):
return
item
in
self
.
cards
...
...
server/model/hands.py
View file @
cfada799
from
random
import
choice
from
typing
import
List
from
server.model.card
import
Value
,
Color
,
Card
from
server.model.card
import
Card
from
server.model.color
import
Color
from
server.model.value
import
Value
from
server.model.hand
import
Hand
...
...
server/model/known.py
View file @
cfada799
from
server.model.card
import
Value
,
Color
from
server.model.color
import
Color
from
server.model.value
import
Value
from
server.model.hands
import
pair
,
single
,
double_pair
,
brelan
,
full
,
carre
,
card
ACE_OF_HEARTS
=
card
(
Value
.
Ace
,
Color
.
Hearts
)
...
...
server/model/value.py
0 → 100644
View file @
cfada799
from
enum
import
Enum
class
Value
(
Enum
):
Two
=
1
Three
=
2
Four
=
3
Five
=
4
Six
=
5
Seven
=
6
Eight
=
7
Nine
=
8
Ten
=
9
Jack
=
10
Queen
=
11
King
=
12
Ace
=
13
def
json
(
self
):
return
self
.
value
\ No newline at end of file
server/requirements.txt
View file @
cfada799
fastapi==0.5
3.2
fastapi==0.5
4.1
uvicorn==0.11.3
python-socketio==4.5.1
server/test/test_data.py
View file @
cfada799
from
unittest
import
TestCase
from
server.model.card
import
Value
,
Color
,
Card
,
lowest_value_and_rest
from
server.model.card
import
Card
,
lowest_value_and_rest
from
server.model.color
import
Color
from
server.model.value
import
Value
from
server.model.deck
import
Deck
from
server.model.hand
import
Hand
from
server.model.hands
import
full
,
brelan
,
pair
,
single
,
double_pair
,
carre
...
...
server/test/test_lobby.py
View file @
cfada799
...
...
@@ -3,7 +3,7 @@ from unittest import TestCase
from
server.game.manager
import
ClientManager
from
server.game.message
import
MessageToPlayer
from
server.model.
card
import
Value
from
server.model.
value
import
Value
from
server.model.deck
import
Deck
from
server.model.game
import
Game
from
server.model.hand
import
Hand
...
...
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