debugging

This commit is contained in:
CHIBOUB Chakib
2024-09-11 19:02:01 +02:00
parent 730431736a
commit 18147ff10b
4 changed files with 29 additions and 8 deletions

View File

@@ -9,6 +9,9 @@ from asgiref.sync import sync_to_async
from .models import Tournoi
class Game:
# Global variable to handle the using of the database
USING_DB = False
def __init__(self, game_id, player1, player2, localgame):
self.game_id = game_id
self.player1 = player1
@@ -243,6 +246,9 @@ class Game:
if not self.botgame:
if not self.localgame:
await self.player2.send(end_message)
while (Game.USING_DB):
await asyncio.sleep(1)
Game.USING_DB = True
if hasattr(self, 'tournament'):
print(f"*** Game #{self.game_id} from tournament: {self.tournament.tournoi_reg.name} ENDED ***")
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
@@ -253,3 +259,4 @@ class Game:
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
self.game_state['player1_score'], self.game_state['player2_score'],
self.bt1, self.bt2, duration, False, None)
Game.USING_DB = False

View File

@@ -82,13 +82,13 @@ class TournamentMatchMaker:
# Tournament start method
async def start_tournament(self):
if len(self.waiting_players) < 2:
if len(self.waiting_players) < 3:
return False
if len(self.waiting_players) % 2 == 0:
await self.add_player(None)
self.tournament_state = "in_progress"
random.shuffle(self.waiting_players)
'''if (len(self.waiting_players) % 2) != 0:
print("Adding a BYE to the tournament..")
await self.add_player(None)'''
self.tournament_state = "in_progress"
self.current_round = 0
len_tournament = await sync_to_async(getlen)()
self.final_name = self.name + " #" + str(len_tournament + 1)
@@ -97,7 +97,7 @@ class TournamentMatchMaker:
return True
async def advance_tournament(self):
players = self.waiting_players
players = self.waiting_players
while len(players) > 1:
self.current_round += 1
print(f"Starting round {self.current_round} with {len(players)} players")
@@ -180,6 +180,14 @@ class TournamentMatchMaker:
match.game_state['player1_score'] = 3
match.game_state['player2_score'] = 0
await match.end_game()
await self.send_game_text(match.player1, "You lucky bastard! You got an auto-win!")
async def send_game_text(self, player, text):
message = json.dumps({
'type': 'game_text_update',
'game_text': text
})
await player.send(message)
def get_round_winners(self):
winners = []