-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrainstorm.txt
184 lines (157 loc) · 3.67 KB
/
brainstorm.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Session tokens:
- need to update lobby fields on socket change
- do we need the addresses in lobby?
- can have them in lobby manager? lobby sends lobby manager message, which sends to both players
- bottleneck at lobby manager
- updating the existing fields:
- if a client connection is closed, client connection manager still has state of the old connection
- we can call stop on the connection actor
- actor will be stopped, but can still be accessed in client connection manager
- need to garbage collect maybe?
- on new socket connection, client connection manager updates new connection fields as needed from old one
- eg. lobby address
- client connection manager sends message to lobby (update user connection)
ClientConnectionManager:
- map session tokens <> client connection address
ClientConnection:
- addr: lobby
Lobby:
- addr: user1 connection
- addr: user2 connection
Messages:
ClientMessage: used by ClientConnection to model messages received from client
ServerMessage: used by ClientConnection to model messages to be sent from server
Lobby
API:
POST ws::/connect
- optional session_token
- sends session_token back on connection
Websocket server messages
- Move made
- probably should include side
- Game started
- Game ended (result)
- Rematch?
Websocket client messages
- Create lobby
- Choosing sides?
- Time control?
- Join lobby
- Start lobby
- Make move
- should include side?
- Forfeit
- Rematch
*Everything except initial connection will be via websocket
- will need some infrastructure around keeping socket alive (probably FE task?)
ClientConnection: Websocket implementation for client connection
ClientConnectionManager: actor for controlling to websocket events
LobbyManager: actor for controlling lobby events
Actor Model:
- LobbyManager
- lobby ids map
- ClientConnection
- Session token -> connection map
- session token -> lobby id map
Client socket receives user message
-> send to lobby manager actor
-> perform lobby action
-> send message to client socket actor
-> send message to client
Objects:
Lobby
field: user1_connection
field: user2_connection
field: is_user1_black
field: game
field: lobby_status
- handles Users joining/creating game
- handles Game creation
- handles websockets
- create:
assign user1
- join:
assign user2
start game
- start:
init board
start game
- forfeit:
end game
- make move:
place piece on board
update moves sequence
check win condition
Game
field: id
field: user1
field: user2
field: board
field: moves sequence
field: result
- init:
blank fields
enum Move:
Position {x, y}
Forfeit
GameResultEnum:
WIN_BLACK
WIN_WHITE
DRAW
IN_PROGRESS
Board
field: id
field: grid of pieces
- init: blank board
- place piece: update grid cell
- private check win:
use last move
calc max conn in vert, hor, diag
update result if winner
User
field: id
field: username
field: password (if present)
APIs:
- create game (username)
create player w/ username
create game
send invite link
websocket connection
- join game (username)
create player w/ username
join game
websocket connection
Flows:
- game creation
select username (or choose default)
select side
create game (username)
- game join
navigate to invite link
select username
join game
- make move
click board
send move via websocket
server pushes next move to both players (move, win, draw, etc.)
Lobby:
- Create lobby
- Join lobby
- Assign sides
- Start game
- Start rematch
Features:
- 2-player (link sharing)
- 2-player (same computer)
- 1-player (vs AI)
- 1-player (analysis board)
- timed games
- display move order toggle
- input modes (confirm move, instant move)
- premoves
- ghost mode (to inspect lines)
- share a game
- evaluation bar
- user accounts
- ELO system