Skip to content

Commit

Permalink
feat: Add isRunning flag to AI class for better control of server com…
Browse files Browse the repository at this point in the history
…munication
  • Loading branch information
Marius-P1 committed Jun 22, 2024
1 parent b446ba2 commit 7dfaf7d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ai/src/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ def __init__(self, host, port, teamName):
self.threads = []
self.creationTime = time.time_ns()
self.myuuid = str(uuid.uuid4())
self.isRunning = True


def serverCommunicationInThread(self):
"""
Handle the communication with the server in a thread
"""
while True:
while self.isRunning:
if self.player.currentMode == Mode.REGROUP and self.player.isLeader == Role.SLAVE:
break
for _ in range(0, len(self.player.callbacks)):
Expand All @@ -83,7 +84,7 @@ def serverCommunicationInThread(self):
self.player.commands.pop(0)
self.player.callbacks.pop(0)
print("Regrouping Start", flush=True, file=sys.stderr)
while True:
while self.isRunning:
responses = self.api.receiveData(0.1)
if responses is not None :
responses = responses.split("\n")
Expand Down

0 comments on commit 7dfaf7d

Please sign in to comment.