-
Notifications
You must be signed in to change notification settings - Fork 32
How_to play multiple games with a GUI
Tuana Durmayüksel edited this page Jan 22, 2025
·
1 revision
server.py is a piece of code like any other.
engine = SchnapsenGamePlayEngine()
with SchnapsenServer() as s:
bot1 = RandBot(random.Random(12))
# bot1 = s.make_gui_bot(name="mybot1")
bot2 = s.make_gui_bot(name="mybot2")
engine.play_game(bot1, bot2, random.Random(100))
First it creates an engine to play schnapsen. But then, because GUI bots are somewhat special, it creates a server which will manage the GUI bot. Then it creates two bots, a normal one (RandomBot) and a GUIbot. After that it can use these bots to play a game with the engine.
Now, we can look at the code in CLI to play muliple games. For example:
engine = SchnapsenGamePlayEngine()
bot1 = RandBot(random.Random(12112121))
bot2 = RandBot(random.Random(464566))
for i in range(1000):
winner_id, game_points, score = engine.play_game(bot1, bot2, random.Random(i))
print(f"Game ended. Winner is {winner_id} with {game_points} points, score {score}")
Here you can see that the bots and engine can be reused multiple times. you can do the same for the server, i.e., make a loop. However, the GUIbot can only be used once, so you have to create it in the loop, instead of before.
Project Intelligent Systems - Vrije Universiteit Amsterdam