Add in choose action phase
This commit is contained in:
parent
b41e4fa052
commit
a4efaff9a8
14
src/lib.rs
14
src/lib.rs
@ -258,6 +258,18 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn action(&mut self, agents: &[&dyn Agent]) -> CoupResult<Phase> {
|
||||
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<Phase> {
|
||||
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.
|
||||
|
@ -3,6 +3,9 @@ use super::*;
|
||||
#[derive(Debug)]
|
||||
struct DummyAgent(Card, Option<Card>, 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user