334 lines
9.2 KiB
Rust
334 lines
9.2 KiB
Rust
// Copyright (C) 2025 Emilis Bliūdžius
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use core::num::NonZeroU8;
|
|
|
|
#[allow(unused)]
|
|
use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
|
|
|
|
use crate::{
|
|
aura::Aura,
|
|
bag::DrunkBag,
|
|
diedto::DiedTo,
|
|
game::{Game, GameSettings, SetupRole},
|
|
game_test::{
|
|
ActionPromptTitleExt, ActionResultExt, GameExt, SettingsExt, gen_players, init_log,
|
|
},
|
|
message::night::ActionPromptTitle,
|
|
};
|
|
|
|
#[test]
|
|
fn maple_starves() {
|
|
init_log();
|
|
let players = gen_players(1..21);
|
|
let mut player_ids = players.iter().map(|p| p.player_id);
|
|
let maple = player_ids.next().unwrap();
|
|
let wolf = player_ids.next().unwrap();
|
|
let mut settings = GameSettings::empty();
|
|
settings.add_and_assign(SetupRole::MapleWolf, maple);
|
|
settings.add_and_assign(SetupRole::Werewolf, wolf);
|
|
settings.fill_remaining_slots_with_villagers(20);
|
|
let mut game = Game::new(&players, settings).unwrap();
|
|
game.r#continue().r#continue();
|
|
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark_villager();
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark_villager();
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark_villager();
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark_villager();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
game.character_by_player_id(maple).died_to().cloned(),
|
|
Some(DiedTo::MapleWolfStarved {
|
|
night: NonZeroU8::new(3).unwrap()
|
|
})
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn maple_last_eat_counter_increments() {
|
|
init_log();
|
|
let players = gen_players(1..21);
|
|
let mut player_ids = players.iter().map(|p| p.player_id);
|
|
let maple = player_ids.next().unwrap();
|
|
let wolf = player_ids.next().unwrap();
|
|
let mut settings = GameSettings::empty();
|
|
settings.add_and_assign(SetupRole::MapleWolf, maple);
|
|
settings.add_and_assign(SetupRole::Werewolf, wolf);
|
|
settings.fill_remaining_slots_with_villagers(20);
|
|
let mut game = Game::new(&players, settings).unwrap();
|
|
game.r#continue().r#continue();
|
|
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
1
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
2
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
3
|
|
);
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
4
|
|
);
|
|
|
|
assert_eq!(game.character_by_player_id(maple).died_to().cloned(), None);
|
|
}
|
|
|
|
#[test]
|
|
fn drunk_maple_doesnt_eat() {
|
|
init_log();
|
|
let players = gen_players(1..21);
|
|
let mut player_ids = players.iter().map(|p| p.player_id);
|
|
let maple = player_ids.next().unwrap();
|
|
let wolf = player_ids.next().unwrap();
|
|
let mut settings = GameSettings::empty();
|
|
settings.add_and_assign(SetupRole::MapleWolf, maple);
|
|
settings.add_and_assign(SetupRole::Werewolf, wolf);
|
|
settings.fill_remaining_slots_with_villagers(20);
|
|
let mut game = Game::new(&players, settings).unwrap();
|
|
game.village_mut()
|
|
.characters_mut()
|
|
.into_iter()
|
|
.find(|c| c.player_id() == maple)
|
|
.unwrap()
|
|
.apply_aura(Aura::Drunk(DrunkBag::all_drunk()));
|
|
game.r#continue().r#continue();
|
|
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().drunk();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
assert_eq!(
|
|
game.village()
|
|
.character_by_id(maple_kill)
|
|
.unwrap()
|
|
.died_to(),
|
|
None
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().drunk();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
assert_eq!(
|
|
game.village()
|
|
.character_by_id(maple_kill)
|
|
.unwrap()
|
|
.died_to(),
|
|
None
|
|
);
|
|
|
|
let (maple_kill, wolf_kill) = {
|
|
let mut cid = game
|
|
.villager_character_ids()
|
|
.into_iter()
|
|
.filter(|c| game.village().character_by_id(*c).unwrap().alive());
|
|
(cid.next().unwrap(), cid.next().unwrap())
|
|
};
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
game.mark(wolf_kill);
|
|
game.r#continue().sleep();
|
|
|
|
game.next().title().maple_wolf();
|
|
game.mark(maple_kill);
|
|
game.r#continue().drunk();
|
|
game.r#continue().sleep();
|
|
|
|
game.next_expect_day();
|
|
|
|
assert_eq!(
|
|
*game.character_by_player_id(maple).maple_wolf_mut().unwrap(),
|
|
0
|
|
);
|
|
|
|
assert_eq!(
|
|
game.character_by_player_id(maple).died_to().cloned(),
|
|
Some(DiedTo::MapleWolfStarved {
|
|
night: NonZeroU8::new(3).unwrap()
|
|
})
|
|
);
|
|
}
|