3333 User ,
3434 UserAlreadyInGameError ,
3535)
36+ from ttt .entities .elo .rating import GamesPlayed
3637from ttt .entities .math .matrix import Matrix
3738from ttt .entities .math .random import Random , choice
3839from ttt .entities .math .vector import Vector
@@ -152,34 +153,30 @@ def is_completed(self) -> bool:
152153 def cancel (
153154 self ,
154155 user_id : int ,
155- user1_last_game_id : UUID ,
156- user2_last_game_id : UUID ,
157156 tracking : Tracking ,
158157 ) -> None :
159158 """
160159 :raises ttt.entities.core.game.game.AlreadyCompletedGameError:
161160 :raises ttt.entities.core.game.game.NotPlayerError:
162- :raises ttt.entities.core.user.user.UserAlreadyLeftGameError:
163161 """
164162
165163 none (self .result , else_ = AlreadyCompletedGameError )
166164 canceler = not_none (self .user (user_id ), else_ = NotPlayerError )
167165
168166 if isinstance (self .player1 , User ):
169- self .player1 .leave_game (user1_last_game_id , self . id , tracking )
167+ self .player1 .leave_game (tracking )
170168 if isinstance (self .player2 , User ):
171- self .player2 .leave_game (user2_last_game_id , self . id , tracking )
169+ self .player2 .leave_game (tracking )
172170
173171 self .result = CancelledGameResult (canceler .id )
174172 self .state = GameState .completed
175173 tracking .register_mutated (self )
176174
177- def make_user_move ( # noqa: C901, PLR0913, PLR0917
175+ def make_user_move ( # noqa: C901
178176 self ,
179177 user_id : int ,
180178 cell_number_int : int ,
181- current_user_last_game_id : UUID ,
182- not_current_user_last_game_id : UUID ,
179+ games_played_by_player_id : dict [int , GamesPlayed ],
183180 player_win_random : Random ,
184181 tracking : Tracking ,
185182 ) -> UserMove :
@@ -230,21 +227,17 @@ def make_user_move( # noqa: C901, PLR0913, PLR0917
230227 case User ():
231228 win = current_player .win_against_user (
232229 not_current_player .rating ,
230+ games_played_by_player_id [current_player .id ],
233231 player_win_random ,
234- current_user_last_game_id ,
235- self .id ,
236232 tracking ,
237233 )
238234 loss = not_current_player .lose_to_user (
239235 current_player .rating ,
240- not_current_user_last_game_id ,
241- self .id ,
236+ games_played_by_player_id [not_current_player .id ],
242237 tracking ,
243238 )
244239 case Ai ():
245- win = current_player .win_against_ai (
246- current_user_last_game_id , self .id , tracking ,
247- )
240+ win = current_player .win_against_ai (tracking )
248241 loss = not_current_player .lose ()
249242
250243 self ._complete_as_decided (win , loss , tracking )
@@ -257,20 +250,16 @@ def make_user_move( # noqa: C901, PLR0913, PLR0917
257250 case User ():
258251 draw1 = current_player .be_draw_against_user (
259252 not_current_player .rating ,
260- current_user_last_game_id ,
261- self .id ,
253+ games_played_by_player_id [current_player .id ],
262254 tracking ,
263255 )
264256 draw2 = not_current_player .be_draw_against_user (
265257 not_current_player .rating ,
266- not_current_user_last_game_id ,
267- self .id ,
258+ games_played_by_player_id [not_current_player .id ],
268259 tracking ,
269260 )
270261 case Ai ():
271- draw1 = current_player .be_draw_against_ai (
272- current_user_last_game_id , self .id , tracking ,
273- )
262+ draw1 = current_player .be_draw_against_ai (tracking )
274263 draw2 = not_current_player .be_draw ()
275264
276265 self ._complete_as_draw (draw1 , draw2 , tracking )
@@ -292,7 +281,6 @@ def make_ai_move(
292281 self ,
293282 ai_id : UUID ,
294283 cell_number_int : int | None ,
295- not_current_user_last_game_id : UUID ,
296284 free_cell_random : Random ,
297285 tracking : Tracking ,
298286 ) -> AiMove :
@@ -316,7 +304,6 @@ def make_ai_move(
316304 return self ._make_random_ai_move (
317305 current_player ,
318306 not_current_player ,
319- not_current_user_last_game_id ,
320307 free_cell_random ,
321308 tracking ,
322309 )
@@ -327,7 +314,6 @@ def make_ai_move(
327314 return self ._make_random_ai_move (
328315 current_player ,
329316 not_current_player ,
330- not_current_user_last_game_id ,
331317 free_cell_random ,
332318 tracking ,
333319 )
@@ -340,7 +326,6 @@ def make_ai_move(
340326 return self ._make_random_ai_move (
341327 current_player ,
342328 not_current_player ,
343- not_current_user_last_game_id ,
344329 free_cell_random ,
345330 tracking ,
346331 )
@@ -351,7 +336,6 @@ def make_ai_move(
351336 return self ._make_random_ai_move (
352337 current_player ,
353338 not_current_player ,
354- not_current_user_last_game_id ,
355339 free_cell_random ,
356340 tracking ,
357341 )
@@ -361,16 +345,12 @@ def make_ai_move(
361345
362346 if self ._is_player_winner (current_player , cell_position ):
363347 win = current_player .win ()
364- loss = not_current_player .lose_to_ai (
365- not_current_user_last_game_id , self .id , tracking ,
366- )
348+ loss = not_current_player .lose_to_ai (tracking )
367349 self ._complete_as_decided (win , loss , tracking )
368350
369351 elif not self ._can_continue ():
370352 draw1 = current_player .be_draw ()
371- draw2 = not_current_player .be_draw_against_ai (
372- not_current_user_last_game_id , self .id , tracking ,
373- )
353+ draw2 = not_current_player .be_draw_against_ai (tracking )
374354 self ._complete_as_draw (draw1 , draw2 , tracking )
375355
376356 else :
@@ -411,7 +391,6 @@ def _make_random_ai_move(
411391 self ,
412392 current_player : Ai ,
413393 not_current_player : User ,
414- not_current_user_last_game_id : UUID ,
415394 free_cell_random : Random ,
416395 tracking : Tracking ,
417396 ) -> AiMove :
@@ -422,16 +401,12 @@ def _make_random_ai_move(
422401
423402 if self ._is_player_winner (current_player , cell .board_position ):
424403 win = current_player .win ()
425- loss = not_current_player .lose_to_ai (
426- not_current_user_last_game_id , self .id , tracking ,
427- )
404+ loss = not_current_player .lose_to_ai (tracking )
428405 self ._complete_as_decided (win , loss , tracking )
429406
430407 elif not self ._can_continue ():
431408 draw1 = current_player .be_draw ()
432- draw2 = not_current_player .be_draw_against_ai (
433- not_current_user_last_game_id , self .id , tracking ,
434- )
409+ draw2 = not_current_player .be_draw_against_ai (tracking )
435410 self ._complete_as_draw (draw1 , draw2 , tracking )
436411
437412 else :
0 commit comments