From a4efaff9a8b6edf70b5654ecb0e315470ebd8b95 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Fri, 20 May 2022 13:26:26 -0500 Subject: [PATCH] Add in choose action phase --- src/lib.rs | 14 ++++++++++++++ src/test.rs | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f4d8b1c..05ea960 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,18 @@ impl Game { } } + pub fn action(&mut self, agents: &[&dyn Agent]) -> CoupResult { + let move_ = agents[self.turn].choose_move(self); + if move_.action.is_targeted() && move_.target.is_none() { + Err("Targeted action with no target") + } else if move_.action.coin_cost() > self.players[self.turn].coins { + Err("Cannot afford action") + } else { + Ok(Phase::ActionChallenge(move_)) + } + // TODO there're definately more cases, find and cover these + } + pub fn action_challenge(&mut self, move_: Move, agents: &[&dyn Agent]) -> CoupResult { match move_.action.challenger_mode() { ResMode::None => Ok(Phase::Block(move_)), @@ -410,6 +422,8 @@ pub enum Phase { /// An interface to a game to make strategic decisions. pub trait Agent : fmt::Debug { + /// What move should the agent take? + fn choose_move(&self, game: &Game) -> Move; /// Should the agent challenge the action? fn should_action_challenge(&self, game: &Game, move_: Move) -> bool; /// Which [card](Card) the agent wishes to use to block the current action. diff --git a/src/test.rs b/src/test.rs index 5683bc4..f7ad68a 100644 --- a/src/test.rs +++ b/src/test.rs @@ -3,6 +3,9 @@ use super::*; #[derive(Debug)] struct DummyAgent(Card, Option, bool); impl Agent for DummyAgent { + fn choose_move(&self, _game: &Game) -> Move { + unimplemented!(); + } fn should_action_challenge(&self, _game: &Game, _move: Move) -> bool { self.2 }