add detection when player left the tournament to not start any game, add action 7 to tournaments
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/19 18:29:36 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/20 15:36:33 by tomoron ### ########.fr #
|
||||
# Updated: 2024/10/22 01:19:12 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -6,13 +6,14 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/08 07:33:29 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/11 10:47:53 by edbernar ### ########.fr #
|
||||
# Updated: 2024/10/22 01:19:10 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
class DummySocket:
|
||||
def __init__(self, game):
|
||||
self.id = 0
|
||||
self.online = True
|
||||
self.username = "bot"
|
||||
self.game = game
|
||||
self.pfp = "/static/img/robot_pfp.jpg"
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/06 16:33:56 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/20 15:48:47 by edbernar ### ########.fr #
|
||||
# Updated: 2024/10/22 01:30:44 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -46,4 +46,5 @@ class GameSettings:
|
||||
maxScore = 1
|
||||
|
||||
maxPlayerSpeed = 6
|
||||
BotMovement = False
|
||||
BotMovement = True
|
||||
maxTimePlayerWait = 10
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/04 17:17:07 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/20 15:30:13 by tomoron ### ########.fr #
|
||||
# Updated: 2024/10/22 01:34:49 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -121,7 +121,18 @@ class Tournament:
|
||||
self.broadcast({"action":6, "p1" : p1, "p2" : p2, "p1Win": p1Win})
|
||||
self.history.append({"p1": p1, "p2" : p2, "p1Win":p1Win})
|
||||
|
||||
def allPlayersReady(self):
|
||||
for x in self.players:
|
||||
if (not x.isTournamentReady()):
|
||||
return False
|
||||
return True
|
||||
|
||||
async def tournamentLoop(self):
|
||||
while self.finalGame.winner == None:
|
||||
await asyncio.sleep(1)
|
||||
nbLoop = 0
|
||||
while not self.allPlayersReady() and nbLoop < GameSettings.maxTimePlayerWait * 10:
|
||||
nbLoop += 1
|
||||
await asyncio.sleep(0.1)
|
||||
self.broadcast({"action":7, "winnerId" : self.players.index(self.finalGame.winner)})
|
||||
print("tournament done, winner is ", self.finalGame.winner.socket.username)
|
||||
|
@ -3,13 +3,15 @@
|
||||
# ::: :::::::: #
|
||||
# TournamentGame.py :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ # +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/12 22:49:00 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/15 13:36:34 by tomoron ### ########.fr #
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/22 01:37:00 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/22 01:37:12 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
from .Game import Game
|
||||
from .GameSettings import GameSettings
|
||||
import asyncio
|
||||
|
||||
class TournamentGame:
|
||||
@ -31,9 +33,15 @@ class TournamentGame:
|
||||
else:
|
||||
l = self.left
|
||||
r = self.right
|
||||
while (not l.isTournamentReady() or not r.isTournamentReady()):
|
||||
nbLoop = 0
|
||||
while (not l.isTournamentReady() or not r.isTournamentReady()) and nbLoop < GameSettings.maxTimePlayerWait * 10:
|
||||
print("waiting for player")
|
||||
nbLoop += 1
|
||||
await asyncio.sleep(0.1)
|
||||
if(not l.socket.online or not r.socket.online):
|
||||
print("player is not online, opponent is winner")
|
||||
self.winner = l if l.socket.online else r
|
||||
return;
|
||||
await asyncio.sleep(3)
|
||||
self.game = Game(l, r, self.tournament.code)
|
||||
l.socket.sync_send("tournament", {
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/01 13:16:39 by edbernar #+# #+# #
|
||||
# Updated: 2024/10/20 15:02:51 by edbernar ### ########.fr #
|
||||
# Updated: 2024/10/22 01:02:00 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -51,6 +51,9 @@ from .tournamentActions.fetchAllData import fetchAllData
|
||||
# - p1 : id of the player 1
|
||||
# - p2 : id of the player 2
|
||||
# - p1Win : true/false
|
||||
#
|
||||
# 7 : tournament end : when the tournament ends
|
||||
# - winnerId : id of the player who won the game
|
||||
|
||||
|
||||
#client actions (actions sent by the client) :
|
||||
|
Reference in New Issue
Block a user