Skip to content

Commit

Permalink
feat: Improve error handling and AI shutdown process
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius-P1 committed Jun 22, 2024
1 parent 62c6989 commit 592d963
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ai/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ def main():
host, port, teamName = getArgs()
try:
ai = AI(host, port, teamName)
ai.run()
try:
ai.run()
except KeyboardInterrupt:
ai.api.close()
ai.isRunning = False
ai.threads[0].join()
print("The AI has been stopped by a keyboard interrupt", file=sys.stderr)
except PlayerDeathException as e:
print(e, file=sys.stderr)
if ai.player.isLeader == Role.LEADER:
print("The leader is dead, the AI will fork", file=sys.stderr)
main() # TODO: Need to be fixed (can't connect if there is no slot available)
sys.exit(0)
except Exception as e:
print(e, file=sys.stderr)
sys.exit(84)


if __name__ == "__main__":
Expand All @@ -88,3 +95,4 @@ def main():
except Exception as e:
print(e, file=sys.stderr)
sys.exit(84)
sys.exit(0)

0 comments on commit 592d963

Please sign in to comment.