From 2e7ebe7c6179ed2e91882b10e5e67150f4295310 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Thu, 23 Nov 2023 11:59:54 +0100 Subject: [PATCH 1/2] Officially support two-stage-bot, Trigger CI --- src/schnapsen/bots/__init__.py | 3 ++- src/schnapsen/bots/two_stage_bot.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/schnapsen/bots/two_stage_bot.py diff --git a/src/schnapsen/bots/__init__.py b/src/schnapsen/bots/__init__.py index dc1cbd0..f15e9dc 100644 --- a/src/schnapsen/bots/__init__.py +++ b/src/schnapsen/bots/__init__.py @@ -7,5 +7,6 @@ from .ml_bot import MLDataBot, MLPlayingBot, train_ML_model from .gui.guibot import SchnapsenServer from .minimax import MiniMaxBot +from .two_stage_bot import TwoStageBot -__all__ = ["RandBot", "AlphaBetaBot", "RdeepBot", "MLDataBot", "MLPlayingBot", "train_ML_model", "SchnapsenServer", "MiniMaxBot"] +__all__ = ["RandBot", "AlphaBetaBot", "RdeepBot", "MLDataBot", "MLPlayingBot", "train_ML_model", "SchnapsenServer", "MiniMaxBot", "TwoStageBot"] diff --git a/src/schnapsen/bots/two_stage_bot.py b/src/schnapsen/bots/two_stage_bot.py new file mode 100644 index 0000000..deff85c --- /dev/null +++ b/src/schnapsen/bots/two_stage_bot.py @@ -0,0 +1,29 @@ +"""Two stage bot""" +from typing import Optional +from schnapsen.game import ( + Bot, + Move, + PlayerPerspective, + GamePhase, +) + + +class TwoStageBot(Bot): + """Bot which plays first the one, than the other startegy""" + + def __init__( + self, bot1: Bot, bot2: Bot, name: Optional[str] = "ProbabilityBot" + ) -> None: + super().__init__(name) + self.bot_phase1: Bot = bot1 + self.bot_phase2: Bot = bot2 + + def get_move( + self, perspective: PlayerPerspective, leader_move: Optional[Move] + ) -> Move: + if perspective.get_phase() == GamePhase.ONE: + return self.bot_phase1.get_move(perspective, leader_move) + elif perspective.get_phase() == GamePhase.TWO: + return self.bot_phase2.get_move(perspective, leader_move) + else: + raise AssertionError("Phase ain't right.") From faf543013924a2d5d40c45c356107b925dfd824c Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Thu, 23 Nov 2023 12:14:18 +0100 Subject: [PATCH 2/2] Officially support two-stage-bot, Trigger CI --- src/schnapsen/bots/two_stage_bot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/schnapsen/bots/two_stage_bot.py b/src/schnapsen/bots/two_stage_bot.py index deff85c..ab37585 100644 --- a/src/schnapsen/bots/two_stage_bot.py +++ b/src/schnapsen/bots/two_stage_bot.py @@ -11,9 +11,7 @@ class TwoStageBot(Bot): """Bot which plays first the one, than the other startegy""" - def __init__( - self, bot1: Bot, bot2: Bot, name: Optional[str] = "ProbabilityBot" - ) -> None: + def __init__(self, bot1: Bot, bot2: Bot, name: Optional[str] = None) -> None: super().__init__(name) self.bot_phase1: Bot = bot1 self.bot_phase2: Bot = bot2