bettermint commited on
Commit
1b00295
·
verified ·
1 Parent(s): 81ff85d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -1
main.py CHANGED
@@ -13,6 +13,7 @@ user_playing = {
13
  'total': 0,
14
  'stockfish': 0,
15
  'rodent': 0,
 
16
  'maia': 0
17
  }
18
 
@@ -170,6 +171,36 @@ async def websocket_endpoint(websocket: WebSocket, personality: str):
170
  user_playing['rodent'] -= 1
171
 
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  @app.get("/")
174
  async def root(request: Request):
175
  html_content = """
@@ -238,9 +269,13 @@ async def root(request: Request):
238
  <span id="stockfish-users">""" + str(user_playing['stockfish']) + """</span>
239
  </div>
240
  <div class="stat">
241
- <label>RodentIII Users:</label>
242
  <span id="rodent3-users">""" + str(user_playing['rodent']) + """</span>
243
  </div>
 
 
 
 
244
  <div class="stat">
245
  <label>Maia Users:</label>
246
  <span id="maia-users">""" + str(user_playing['maia']) + """</span>
 
13
  'total': 0,
14
  'stockfish': 0,
15
  'rodent': 0,
16
+ 'patricia': 0,
17
  'maia': 0
18
  }
19
 
 
171
  user_playing['rodent'] -= 1
172
 
173
 
174
+ @app.websocket("/patricia")
175
+ async def websocket_endpoint(websocket: WebSocket):
176
+ await websocket.accept()
177
+
178
+ user_playing['total'] += 1
179
+ user_playing['patricia'] += 1
180
+
181
+ stockfish = EngineChess([f"./engines/Patricia/patricia"])
182
+
183
+ async def read_from_socket(websocket: WebSocket):
184
+ async for data in websocket.iter_text():
185
+ print(f"Patricia Client: {data}")
186
+ stockfish.put(data)
187
+
188
+ asyncio.create_task(read_from_socket(websocket))
189
+
190
+ try:
191
+ while True:
192
+ while True:
193
+ res = stockfish.read_line()
194
+ if res:
195
+ await websocket.send_text(f"{res}")
196
+ else:
197
+ break
198
+ await asyncio.sleep(0.1)
199
+ finally:
200
+ user_playing['total'] -= 1
201
+ user_playing['patricia'] -= 1
202
+
203
+
204
  @app.get("/")
205
  async def root(request: Request):
206
  html_content = """
 
269
  <span id="stockfish-users">""" + str(user_playing['stockfish']) + """</span>
270
  </div>
271
  <div class="stat">
272
+ <label>Rodent-III Users:</label>
273
  <span id="rodent3-users">""" + str(user_playing['rodent']) + """</span>
274
  </div>
275
+ <div class="stat">
276
+ <label>Patricia Users:</label>
277
+ <span id="patricia-users">""" + str(user_playing['patricia']) + """</span>
278
+ </div>
279
  <div class="stat">
280
  <label>Maia Users:</label>
281
  <span id="maia-users">""" + str(user_playing['maia']) + """</span>