bettermint commited on
Commit
fc818cf
·
verified ·
1 Parent(s): 0317947

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +40 -1
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
  'maia': 0
16
  }
17
 
@@ -135,6 +136,40 @@ async def websocket_endpoint(websocket: WebSocket, elo: str):
135
  user_playing['maia'] -= 1
136
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  @app.get("/")
139
  async def root(request: Request):
140
  html_content = """
@@ -193,7 +228,7 @@ async def root(request: Request):
193
  </head>
194
  <body>
195
  <div class="container">
196
- <h1>Users playing now</h1>
197
  <div class="stat">
198
  <label>Total Users:</label>
199
  <span id="total-users">""" + str(user_playing['total']) + """</span>
@@ -202,6 +237,10 @@ async def root(request: Request):
202
  <label>Stockfish Users:</label>
203
  <span id="stockfish-users">""" + str(user_playing['stockfish']) + """</span>
204
  </div>
 
 
 
 
205
  <div class="stat">
206
  <label>Maia Users:</label>
207
  <span id="maia-users">""" + str(user_playing['maia']) + """</span>
 
12
  user_playing = {
13
  'total': 0,
14
  'stockfish': 0,
15
+ 'rodent': 0,
16
  'maia': 0
17
  }
18
 
 
136
  user_playing['maia'] -= 1
137
 
138
 
139
+ @app.websocket("/rodent3-{personality}")
140
+ async def websocket_endpoint(websocket: WebSocket, personality: str):
141
+ await websocket.accept()
142
+
143
+ user_playing['total'] += 1
144
+ user_playing['rodent'] += 1
145
+
146
+ stockfish = EngineChess([f"./engines/RodentIII/rodentIII-debug"])
147
+
148
+ await asyncio.sleep(1)
149
+
150
+ stockfish.put(f"setoption name PersonalityFile value {personality}.txt")
151
+
152
+ async def read_from_socket(websocket: WebSocket):
153
+ async for data in websocket.iter_text():
154
+ print(f"Rodent Client: {data}")
155
+ stockfish.put(data)
156
+
157
+ asyncio.create_task(read_from_socket(websocket))
158
+
159
+ try:
160
+ while True:
161
+ while True:
162
+ res = stockfish.read_line()
163
+ if res:
164
+ await websocket.send_text(f"{res}")
165
+ else:
166
+ break
167
+ await asyncio.sleep(0.1)
168
+ finally:
169
+ user_playing['total'] -= 1
170
+ user_playing['rodent'] -= 1
171
+
172
+
173
  @app.get("/")
174
  async def root(request: Request):
175
  html_content = """
 
228
  </head>
229
  <body>
230
  <div class="container">
231
+ <h1>Currently playing users</h1>
232
  <div class="stat">
233
  <label>Total Users:</label>
234
  <span id="total-users">""" + str(user_playing['total']) + """</span>
 
237
  <label>Stockfish Users:</label>
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>