Skip to content

Commit b3a5d6a

Browse files
committed
Update
1 parent 8c401fb commit b3a5d6a

File tree

15 files changed

+59
-42
lines changed

15 files changed

+59
-42
lines changed

AIService/Server.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,17 @@ def CloseServer(self, request, context):
5151

5252
class Server:
5353

54-
_instance = None
55-
_lock = Lock()
56-
57-
def __new__(cls, *args, **kwargs):
58-
with cls._lock:
59-
if not cls._instance:
60-
cls._instance = super().__new__(cls)
61-
cls._instance.active_bots = 0
62-
cls._instance.server = None
63-
cls._instance.lock = Lock()
64-
return cls._instance
65-
54+
def __init__(self):
55+
self.active_bots = 0
6656
def add_bot(self):
67-
with self.lock:
68-
self.active_bots += 1
69-
print(f"Bot connected. Active bots: {self.active_bots}")
57+
self.active_bots += 1
58+
print(f"Bot connected. Active bots: {self.active_bots}")
7059

7160
def bot_disconnected(self):
72-
with self.lock:
73-
self.active_bots -= 1
74-
print(f"Bot disconnected. Active bots: {self.active_bots}")
75-
if self.active_bots == 0:
76-
self.shutdown_server()
61+
self.active_bots -= 1
62+
print(f"Bot disconnected. Active bots: {self.active_bots}")
63+
if self.active_bots == 0:
64+
self.shutdown_server()
7765

7866
def shutdown_server(self):
7967
if self.server:

Bots/MaxPrestigeBot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ def select_patron(self, available_patrons):
99
return random.choice(available_patrons)
1010

1111
def play(self, game_state, possible_moves):
12-
#print(f"MaxPrestigeBot play")
13-
# game_state.debug_print()
12+
best_move = None
13+
best_prestige = -1
14+
15+
for first_move in possible_moves:
16+
new_game_state, new_moves = game_state.apply_move(first_move)
17+
18+
for second_move in new_moves:
19+
final_game_state, _ = new_game_state.apply_move(second_move)
20+
1421
return random.choice(possible_moves)
1522

1623
def game_end(self, final_state):

Bots/RandomBot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def select_patron(self, available_patrons):
99
return random.choice(available_patrons)
1010

1111
def play(self, game_state, possible_moves):
12-
game_state.debug_print()
12+
# game_state.debug_print()
1313
return random.choice(possible_moves)
1414

1515
def game_end(self, final_state):

Game/game.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ def __init__(self):
1010
def register_bot(self, bot_instance: BaseAI):
1111
self.bots.append(bot_instance)
1212

13-
def run(self, bot1Name: str, bot2Name: str, start_game_runner=True, runs=1, enable_logs="NONE", log_destination="", seed=None, timeout=30):
14-
server = Server()
15-
grpc_server = server.run_grpc_server(filter(lambda bot: bot.bot_name == bot1Name or bot.bot_name == bot2Name, self.bots))
13+
def run(self, bot1Name: str, bot2Name: str, start_game_runner=True, runs=1, threads=1, enable_logs="NONE", log_destination="", seed=None, timeout=30):
14+
bots = filter(lambda bot: bot.bot_name == bot1Name or bot.bot_name == bot2Name, self.bots)
1615
if start_game_runner:
1716
if any([bot1Name == bot.bot_name for bot in self.bots]):
1817
bot1Name = "grpc:" + bot1Name
@@ -21,13 +20,20 @@ def run(self, bot1Name: str, bot2Name: str, start_game_runner=True, runs=1, enab
2120
run_game_runner(
2221
bot1Name,
2322
bot2Name,
24-
runs=runs,
23+
runs=runs,
24+
threads=threads,
2525
enable_logs=enable_logs,
2626
log_destination=log_destination,
2727
seed=seed,
2828
timeout=timeout
2929
)
30+
31+
def _run_bot_instances(self, bots: List[BaseAI]):
32+
server = Server()
33+
grpc_server = server.run_grpc_server(bots)
34+
3035
try:
3136
grpc_server.wait_for_termination()
3237
except KeyboardInterrupt:
38+
grpc_server.close()
3339
print("Server interrupted by user.")

GameRunner/GameRunner.dll

0 Bytes
Binary file not shown.

GameRunner/GameRunner.exe

0 Bytes
Binary file not shown.

GameRunner/GameRunner.pdb

-96 Bytes
Binary file not shown.

GameRunner/TalesOfTribute.dll

0 Bytes
Binary file not shown.

GameRunner/TalesOfTribute.pdb

-16 Bytes
Binary file not shown.

GameRunner/gRPC.dll

2 KB
Binary file not shown.

0 commit comments

Comments
 (0)