Cannot block with the incorrect card, Duke blocks foreign aid not income
This commit is contained in:
parent
30fcafe293
commit
443e3a91c5
49
src/lib.rs
49
src/lib.rs
@ -29,7 +29,7 @@ impl Card {
|
|||||||
}
|
}
|
||||||
pub fn blocks_action(self, action: Action) -> bool {
|
pub fn blocks_action(self, action: Action) -> bool {
|
||||||
matches!((self, action),
|
matches!((self, action),
|
||||||
(Duke, Income) |
|
(Duke, ForeignAid) |
|
||||||
(Captain, Steal) |
|
(Captain, Steal) |
|
||||||
(Ambassador, Steal) |
|
(Ambassador, Steal) |
|
||||||
(Contessa, Assassinate))
|
(Contessa, Assassinate))
|
||||||
@ -243,12 +243,18 @@ impl Game {
|
|||||||
target: block.target,
|
target: block.target,
|
||||||
})),
|
})),
|
||||||
ResMode::Target => match agents[block.target.unwrap()].choose_block_card(&block) {
|
ResMode::Target => match agents[block.target.unwrap()].choose_block_card(&block) {
|
||||||
Some(card) => Ok(Phase::BlockChallenge(phase::BlockChallenge {
|
Some(card) => {
|
||||||
blocker: block.target.unwrap(),
|
if card.blocks_action(block.action) {
|
||||||
block_card: card,
|
Ok(Phase::BlockChallenge(phase::BlockChallenge {
|
||||||
action: block.action,
|
blocker: block.target.unwrap(),
|
||||||
target: block.target,
|
block_card: card,
|
||||||
})),
|
action: block.action,
|
||||||
|
target: block.target,
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Err("Card does not block action")
|
||||||
|
}
|
||||||
|
},
|
||||||
None => Ok(Phase::Resolution(phase::Resolution {
|
None => Ok(Phase::Resolution(phase::Resolution {
|
||||||
action: block.action,
|
action: block.action,
|
||||||
target: block.target,
|
target: block.target,
|
||||||
@ -257,12 +263,16 @@ impl Game {
|
|||||||
ResMode::Anyone => {
|
ResMode::Anyone => {
|
||||||
for id in self.turn_iterator() {
|
for id in self.turn_iterator() {
|
||||||
if let Some(card) = agents[id].choose_block_card(&block) {
|
if let Some(card) = agents[id].choose_block_card(&block) {
|
||||||
return Ok(Phase::BlockChallenge(phase::BlockChallenge {
|
if card.blocks_action(block.action) {
|
||||||
blocker: id,
|
return Ok(Phase::BlockChallenge(phase::BlockChallenge {
|
||||||
block_card: card,
|
blocker: id,
|
||||||
action: block.action,
|
block_card: card,
|
||||||
target: block.target,
|
action: block.action,
|
||||||
}))
|
target: block.target,
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
return Err("Card does not block action")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Phase::Resolution(phase::Resolution {
|
Ok(Phase::Resolution(phase::Resolution {
|
||||||
@ -512,6 +522,19 @@ mod test {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test bad block card
|
||||||
|
{
|
||||||
|
let mut game = game.clone();
|
||||||
|
assert!(
|
||||||
|
game.block(phase::Block {
|
||||||
|
action: ForeignAid,
|
||||||
|
target: None,
|
||||||
|
}, &[&non_blocking_agent, &ambassador_block_agent, &non_blocking_agent])
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user