Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -12,6 +12,7 @@ os.environ['LD_LIBRARY_PATH'] = '/engines/maia/lib:' + os.environ.get('LD_LIBRAR
|
|
| 12 |
user_playing = {
|
| 13 |
'total': 0,
|
| 14 |
'stockfish': 0,
|
|
|
|
| 15 |
'rodent': 0,
|
| 16 |
'patricia': 0,
|
| 17 |
'maia': 0
|
|
@@ -205,6 +206,36 @@ async def websocket_endpoint(websocket: WebSocket, elo: str):
|
|
| 205 |
user_playing['patricia'] -= 1
|
| 206 |
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
@app.get("/")
|
| 209 |
async def root(request: Request):
|
| 210 |
html_content = """
|
|
@@ -272,6 +303,10 @@ async def root(request: Request):
|
|
| 272 |
<label>Stockfish Users:</label>
|
| 273 |
<span id="stockfish-users">""" + str(user_playing['stockfish']) + """</span>
|
| 274 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
<div class="stat">
|
| 276 |
<label>Rodent-III Users:</label>
|
| 277 |
<span id="rodent3-users">""" + str(user_playing['rodent']) + """</span>
|
|
|
|
| 12 |
user_playing = {
|
| 13 |
'total': 0,
|
| 14 |
'stockfish': 0,
|
| 15 |
+
'trollfish': 0,
|
| 16 |
'rodent': 0,
|
| 17 |
'patricia': 0,
|
| 18 |
'maia': 0
|
|
|
|
| 206 |
user_playing['patricia'] -= 1
|
| 207 |
|
| 208 |
|
| 209 |
+
@app.websocket("/trollfish}")
|
| 210 |
+
async def websocket_endpoint(websocket: WebSocket, elo: str):
|
| 211 |
+
await websocket.accept()
|
| 212 |
+
|
| 213 |
+
user_playing['total'] += 1
|
| 214 |
+
user_playing['trollfish'] += 1
|
| 215 |
+
|
| 216 |
+
stockfish = EngineChess([f"./engines/trollfish/trollfish"])
|
| 217 |
+
|
| 218 |
+
async def read_from_socket(websocket: WebSocket):
|
| 219 |
+
async for data in websocket.iter_text():
|
| 220 |
+
print(f"Trollfish Client: {data}")
|
| 221 |
+
stockfish.put(data)
|
| 222 |
+
|
| 223 |
+
asyncio.create_task(read_from_socket(websocket))
|
| 224 |
+
|
| 225 |
+
try:
|
| 226 |
+
while True:
|
| 227 |
+
while True:
|
| 228 |
+
res = stockfish.read_line()
|
| 229 |
+
if res:
|
| 230 |
+
await websocket.send_text(f"{res}")
|
| 231 |
+
else:
|
| 232 |
+
break
|
| 233 |
+
await asyncio.sleep(0.1)
|
| 234 |
+
finally:
|
| 235 |
+
user_playing['total'] -= 1
|
| 236 |
+
user_playing['trollfish'] -= 1
|
| 237 |
+
|
| 238 |
+
|
| 239 |
@app.get("/")
|
| 240 |
async def root(request: Request):
|
| 241 |
html_content = """
|
|
|
|
| 303 |
<label>Stockfish Users:</label>
|
| 304 |
<span id="stockfish-users">""" + str(user_playing['stockfish']) + """</span>
|
| 305 |
</div>
|
| 306 |
+
<div class="stat">
|
| 307 |
+
<label>Trollfish Users:</label>
|
| 308 |
+
<span id="trollfish-users">""" + str(user_playing['trollfish']) + """</span>
|
| 309 |
+
</div>
|
| 310 |
<div class="stat">
|
| 311 |
<label>Rodent-III Users:</label>
|
| 312 |
<span id="rodent3-users">""" + str(user_playing['rodent']) + """</span>
|