Lose influence helper function, encoding and line endings
This commit is contained in:
parent
4101157e5f
commit
d0f9054a1a
37
src/lib.rs
37
src/lib.rs
@ -229,22 +229,23 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
fn player_lose_influence(&mut self, id: usize, agents: &[&dyn Agent]) {
|
||||
let player = &mut self.players[id];
|
||||
let card = agents[id]
|
||||
.choose_lost_influence(&player.cards);
|
||||
player.lose(card, &mut self.discard);
|
||||
}
|
||||
|
||||
|
||||
pub fn block_challenge(&mut self, block_challenge: 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
|
||||
let current_player = &mut self.players[self.turn];
|
||||
let card = agents[self.turn]
|
||||
.choose_lost_influence(¤t_player.cards);
|
||||
current_player.lose(card, &mut self.discard);
|
||||
self.player_lose_influence(self.turn, agents);
|
||||
Ok(Phase::Done)
|
||||
} else {
|
||||
// Player challenged correctly, blocker loses a card
|
||||
let blocking_player = &mut self.players[block_challenge.blocker];
|
||||
let card = agents[block_challenge.blocker]
|
||||
.choose_lost_influence(&blocking_player.cards);
|
||||
blocking_player.lose(card, &mut self.discard);
|
||||
|
||||
self.player_lose_influence(block_challenge.blocker, agents);
|
||||
// Game continues
|
||||
Ok(Phase::Resolution(Resolution {
|
||||
action: block_challenge.action,
|
||||
@ -266,10 +267,10 @@ impl Game {
|
||||
ForeignAid => current_player.coins += 2,
|
||||
Coup | Assassinate => match resolution.target {
|
||||
Some(target) => {
|
||||
let target_player = &self.players[target];
|
||||
if target_player.is_alive() { // Target may have died from challenge
|
||||
let card = agents[target].choose_lost_influence(&target_player.cards);
|
||||
self.players[target].lose(card, &mut self.discard);
|
||||
// Target may have died from challenge
|
||||
let target_alive = self.players[target].is_alive();
|
||||
if target_alive {
|
||||
self.player_lose_influence(target, agents);
|
||||
}
|
||||
}
|
||||
_ => return Err("Coup/Assassinate resolution has no target"),
|
||||
@ -309,12 +310,17 @@ impl Game {
|
||||
pub enum Phase {
|
||||
Action(Action),
|
||||
//ActionChallenge(ActionChallenge),
|
||||
//Block(Block),
|
||||
Block(Block),
|
||||
BlockChallenge(BlockChallenge),
|
||||
Resolution(Resolution),
|
||||
Done,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Block {
|
||||
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct BlockChallenge {
|
||||
blocker: usize,
|
||||
@ -429,9 +435,6 @@ mod test {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_resolution() {
|
||||
let dummy_agent = make_dummy_agent!(unimplemented!(), [Contessa, Duke], Captain);
|
||||
|
Loading…
Reference in New Issue
Block a user