Move phases definition to mod
This commit is contained in:
parent
9f545949a5
commit
a846919c88
85
src/lib.rs
85
src/lib.rs
@ -236,8 +236,7 @@ impl Game {
|
||||
player.lose(card, &mut self.discard);
|
||||
}
|
||||
|
||||
|
||||
pub fn block_challenge(&mut self, block_challenge: BlockChallenge, agents: &[&dyn Agent]) -> CoupResult<Phase> {
|
||||
pub fn block_challenge(&mut self, block_challenge: phase::BlockChallenge, agents: &[&dyn Agent]) -> CoupResult<Phase> {
|
||||
if agents[self.turn].should_block_challenge(&block_challenge) {
|
||||
if self.players[block_challenge.blocker].holds(block_challenge.block_card) {
|
||||
// Player challenged incorrectly, loses influence and turn is forfeit
|
||||
@ -247,7 +246,7 @@ impl Game {
|
||||
// Player challenged correctly, blocker loses a card
|
||||
self.player_lose_influence(block_challenge.blocker, agents);
|
||||
// Game continues
|
||||
Ok(Phase::Resolution(Resolution {
|
||||
Ok(Phase::Resolution(phase::Resolution {
|
||||
action: block_challenge.action,
|
||||
target: block_challenge.target,
|
||||
}))
|
||||
@ -259,7 +258,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolution(&mut self, resolution: Resolution, agents: &[&dyn Agent]) -> CoupResult<Phase> {
|
||||
pub fn resolution(&mut self, resolution: phase::Resolution, agents: &[&dyn Agent]) -> CoupResult<Phase> {
|
||||
let current_player = &mut self.players.get_mut(self.turn).unwrap();
|
||||
let current_agent = agents[self.turn];
|
||||
match resolution.action {
|
||||
@ -305,38 +304,42 @@ impl Game {
|
||||
Ok(Phase::Done)
|
||||
}
|
||||
}
|
||||
pub mod phase {
|
||||
use super::{ Card, Action };
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Phase {
|
||||
Action(Action),
|
||||
//ActionChallenge(ActionChallenge),
|
||||
Block(Block),
|
||||
BlockChallenge(BlockChallenge),
|
||||
Resolution(Resolution),
|
||||
Done,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Phase {
|
||||
Action(Action),
|
||||
//ActionChallenge(ActionChallenge),
|
||||
Block(Block),
|
||||
BlockChallenge(BlockChallenge),
|
||||
Resolution(Resolution),
|
||||
Done,
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Block {
|
||||
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct BlockChallenge {
|
||||
pub blocker: usize,
|
||||
pub block_card: Card,
|
||||
pub action: Action,
|
||||
pub target: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Resolution {
|
||||
pub action: Action,
|
||||
pub target: Option<usize>,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Block {
|
||||
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct BlockChallenge {
|
||||
blocker: usize,
|
||||
block_card: Card,
|
||||
action: Action,
|
||||
target: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Resolution {
|
||||
action: Action,
|
||||
target: Option<usize>,
|
||||
}
|
||||
use phase::Phase;
|
||||
|
||||
pub trait Agent : fmt::Debug {
|
||||
fn should_block_challenge(&self, block_challenge: &BlockChallenge) -> bool;
|
||||
fn should_block_challenge(&self, block_challenge: &phase::BlockChallenge) -> bool;
|
||||
fn exchange(&self, cards: &[Card]) -> [Card; 2];
|
||||
fn choose_lost_influence(&self, cards: &[Card]) -> Card;
|
||||
}
|
||||
@ -351,7 +354,7 @@ mod test {
|
||||
struct DummyAgent;
|
||||
impl Agent for DummyAgent {
|
||||
#[allow(unused)]
|
||||
fn should_block_challenge(&self, block_challenge: &BlockChallenge) -> bool {
|
||||
fn should_block_challenge(&self, block_challenge: &phase::BlockChallenge) -> bool {
|
||||
$sbc
|
||||
}
|
||||
#[allow(unused)]
|
||||
@ -389,7 +392,7 @@ mod test {
|
||||
{
|
||||
let mut game = game.clone();
|
||||
assert_eq!(
|
||||
game.block_challenge( BlockChallenge {
|
||||
game.block_challenge( phase::BlockChallenge {
|
||||
blocker: 1,
|
||||
block_card: Contessa,
|
||||
action: Assassinate,
|
||||
@ -404,7 +407,7 @@ mod test {
|
||||
{
|
||||
let mut game = game.clone();
|
||||
assert_eq!(
|
||||
game.block_challenge( BlockChallenge {
|
||||
game.block_challenge( phase::BlockChallenge {
|
||||
blocker: 1,
|
||||
block_card: Contessa,
|
||||
action: Assassinate,
|
||||
@ -419,13 +422,13 @@ mod test {
|
||||
{
|
||||
let mut game = game.clone();
|
||||
assert_eq!(
|
||||
game.block_challenge( BlockChallenge {
|
||||
game.block_challenge( phase::BlockChallenge {
|
||||
blocker: 1,
|
||||
block_card: Duke,
|
||||
action: ForeignAid,
|
||||
target: None,
|
||||
}, &[&challenge_agent, &block_agent]),
|
||||
Ok(Phase::Resolution(Resolution {
|
||||
Ok(Phase::Resolution(phase::Resolution {
|
||||
action: ForeignAid,
|
||||
target: None,
|
||||
}))
|
||||
@ -454,7 +457,7 @@ mod test {
|
||||
// Test income
|
||||
{
|
||||
let mut game = game.clone();
|
||||
game.resolution(Resolution {
|
||||
game.resolution(phase::Resolution {
|
||||
action: Income,
|
||||
target: None,
|
||||
}, &[&dummy_agent, &dummy_agent]).unwrap();
|
||||
@ -464,7 +467,7 @@ mod test {
|
||||
// Test foreign aid
|
||||
{
|
||||
let mut game = game.clone();
|
||||
game.resolution(Resolution {
|
||||
game.resolution(phase::Resolution {
|
||||
action: ForeignAid,
|
||||
target: None,
|
||||
}, &[&dummy_agent, &dummy_agent]).unwrap();
|
||||
@ -474,7 +477,7 @@ mod test {
|
||||
// Test coup / assassinate
|
||||
{
|
||||
let mut game = game.clone();
|
||||
game.resolution(Resolution {
|
||||
game.resolution(phase::Resolution {
|
||||
action: Coup,
|
||||
target: Some(1),
|
||||
}, &[&dummy_agent, &dummy_agent]).unwrap();
|
||||
@ -485,7 +488,7 @@ mod test {
|
||||
// Test steal
|
||||
{
|
||||
let mut game = game.clone();
|
||||
game.resolution(Resolution {
|
||||
game.resolution(phase::Resolution {
|
||||
action: Steal,
|
||||
target: Some(1),
|
||||
}, &[&dummy_agent, &dummy_agent]).unwrap();
|
||||
@ -496,7 +499,7 @@ mod test {
|
||||
// Test exchange
|
||||
{
|
||||
let mut game = game.clone();
|
||||
game.resolution(Resolution {
|
||||
game.resolution(phase::Resolution {
|
||||
action: Exchange,
|
||||
target: Some(1),
|
||||
}, &[&dummy_agent, &dummy_agent]).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user