2025-11-05 20:24:51 +00:00
|
|
|
// 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/>.
|
2025-10-05 10:52:37 +01:00
|
|
|
use core::num::NonZero;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
diedto::DiedTo,
|
2025-10-12 23:48:52 +01:00
|
|
|
game::{Game, GameSettings, OrRandom, SetupRole},
|
2025-10-06 20:45:15 +01:00
|
|
|
game_test::{ActionPromptTitleExt, ActionResultExt, GameExt, SettingsExt, gen_players},
|
2025-10-05 10:52:37 +01:00
|
|
|
message::night::{ActionPrompt, ActionPromptTitle},
|
2025-10-07 21:18:31 +01:00
|
|
|
player::RoleChange,
|
|
|
|
|
role::{Alignment, Role, RoleTitle},
|
2025-10-05 10:52:37 +01:00
|
|
|
};
|
|
|
|
|
#[allow(unused)]
|
|
|
|
|
use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn redeemed_scapegoat_role_changes() {
|
|
|
|
|
let players = gen_players(1..10);
|
2025-10-05 10:54:47 +01:00
|
|
|
let scapegoat_player_id = players[0].player_id;
|
|
|
|
|
let seer_player_id = players[1].player_id;
|
|
|
|
|
let wolf_player_id = players[2].player_id;
|
|
|
|
|
let wolf_target_2_player_id = players[3].player_id;
|
2025-10-05 10:52:37 +01:00
|
|
|
let mut settings = GameSettings::default();
|
|
|
|
|
{
|
|
|
|
|
let scapegoat_slot = settings.new_slot(RoleTitle::Scapegoat);
|
|
|
|
|
let mut scapegoat_slot = settings
|
|
|
|
|
.slots()
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|s| s.slot_id == scapegoat_slot)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.clone();
|
|
|
|
|
scapegoat_slot.role = SetupRole::Scapegoat {
|
|
|
|
|
redeemed: OrRandom::Determined(true),
|
|
|
|
|
};
|
2025-10-05 10:54:47 +01:00
|
|
|
scapegoat_slot.assign_to = Some(scapegoat_player_id);
|
2025-10-05 10:52:37 +01:00
|
|
|
settings.update_slot(scapegoat_slot);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
let mut slot = settings
|
|
|
|
|
.slots()
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|s| matches!(s.role, SetupRole::Werewolf))
|
|
|
|
|
.unwrap()
|
|
|
|
|
.clone();
|
2025-10-05 10:54:47 +01:00
|
|
|
slot.assign_to = Some(wolf_player_id);
|
2025-10-05 10:52:37 +01:00
|
|
|
settings.update_slot(slot);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
let slot = settings.new_slot(RoleTitle::Seer);
|
|
|
|
|
let mut slot = settings
|
|
|
|
|
.slots()
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|s| s.slot_id == slot)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.clone();
|
2025-10-05 10:54:47 +01:00
|
|
|
slot.assign_to = Some(seer_player_id);
|
2025-10-05 10:52:37 +01:00
|
|
|
settings.update_slot(slot);
|
|
|
|
|
}
|
|
|
|
|
for _ in 0..6 {
|
|
|
|
|
settings.new_slot(RoleTitle::Villager);
|
|
|
|
|
}
|
|
|
|
|
let mut game = Game::new(&players, settings).unwrap();
|
|
|
|
|
game.r#continue().r#continue();
|
|
|
|
|
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
|
|
|
|
|
game.r#continue().sleep();
|
|
|
|
|
assert_eq!(game.next().title(), ActionPromptTitle::Seer);
|
|
|
|
|
let wolf_char_id = game
|
|
|
|
|
.village()
|
|
|
|
|
.characters()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.find(|c| c.player_id() == wolf_player_id)
|
|
|
|
|
.unwrap()
|
2025-10-05 10:54:47 +01:00
|
|
|
.character_id();
|
2025-10-05 10:52:37 +01:00
|
|
|
game.mark_and_check(wolf_char_id);
|
|
|
|
|
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
|
2025-10-17 21:16:10 +01:00
|
|
|
game.r#continue().sleep();
|
2025-10-05 10:52:37 +01:00
|
|
|
game.next_expect_day();
|
|
|
|
|
|
2025-10-06 20:45:15 +01:00
|
|
|
game.execute().title().wolf_pack_kill();
|
2025-10-05 10:52:37 +01:00
|
|
|
let seer = game
|
|
|
|
|
.village()
|
|
|
|
|
.characters()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.find(|c| c.player_id() == seer_player_id)
|
|
|
|
|
.unwrap()
|
2025-10-05 10:54:47 +01:00
|
|
|
.character_id();
|
2025-10-05 10:52:37 +01:00
|
|
|
|
|
|
|
|
game.mark_and_check(seer);
|
|
|
|
|
game.r#continue().sleep();
|
|
|
|
|
|
|
|
|
|
assert_eq!(game.next().title(), ActionPromptTitle::Seer);
|
|
|
|
|
game.mark_and_check(wolf_char_id);
|
|
|
|
|
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
|
2025-10-17 21:16:10 +01:00
|
|
|
game.r#continue().sleep();
|
2025-10-05 10:52:37 +01:00
|
|
|
game.next_expect_day();
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*game
|
|
|
|
|
.village()
|
|
|
|
|
.character_by_id(seer)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.died_to()
|
|
|
|
|
.unwrap(),
|
|
|
|
|
DiedTo::Wolfpack {
|
2025-10-05 10:54:47 +01:00
|
|
|
killing_wolf: wolf_char_id,
|
2025-10-05 10:52:37 +01:00
|
|
|
night: NonZero::new(1).unwrap()
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-11-07 20:33:04 +00:00
|
|
|
assert_eq!(
|
|
|
|
|
game.execute(),
|
|
|
|
|
ActionPrompt::RoleChange {
|
|
|
|
|
character_id: game.character_by_player_id(scapegoat_player_id).identity(),
|
|
|
|
|
new_role: RoleTitle::Seer
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
game.r#continue().r#continue();
|
|
|
|
|
game.next().title().seer();
|
|
|
|
|
game.mark(game.character_by_player_id(wolf_player_id).character_id());
|
|
|
|
|
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
|
|
|
|
|
game.r#continue().sleep();
|
2025-10-05 10:52:37 +01:00
|
|
|
|
2025-11-07 20:33:04 +00:00
|
|
|
assert_eq!(game.next().title(), ActionPromptTitle::WolfPackKill);
|
2025-10-05 10:52:37 +01:00
|
|
|
let wolf_target_2 = game
|
|
|
|
|
.village()
|
|
|
|
|
.characters()
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|c| c.player_id() == wolf_target_2_player_id)
|
|
|
|
|
.unwrap()
|
2025-10-05 10:54:47 +01:00
|
|
|
.character_id();
|
2025-10-05 10:52:37 +01:00
|
|
|
game.mark_and_check(wolf_target_2);
|
|
|
|
|
game.r#continue().sleep();
|
|
|
|
|
|
|
|
|
|
game.next_expect_day();
|
2025-10-07 21:18:31 +01:00
|
|
|
|
|
|
|
|
let scapegoat = game.character_by_player_id(scapegoat_player_id);
|
|
|
|
|
assert_eq!(*scapegoat.role(), Role::Seer);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
scapegoat.role_changes(),
|
|
|
|
|
&[RoleChange {
|
|
|
|
|
role: Role::Scapegoat { redeemed: true },
|
|
|
|
|
new_role: RoleTitle::Seer,
|
|
|
|
|
changed_on_night: 2,
|
|
|
|
|
}]
|
|
|
|
|
);
|
2025-10-05 10:52:37 +01:00
|
|
|
}
|
2025-10-06 20:45:15 +01:00
|
|
|
|
|
|
|
|
#[test]
|
2025-10-06 21:59:44 +01:00
|
|
|
fn cannot_redeem_into_wolf() {
|
2025-10-06 20:45:15 +01:00
|
|
|
let players = gen_players(1..10);
|
|
|
|
|
let scapegoat_player_id = players[0].player_id;
|
|
|
|
|
let wolf_player_id = players[1].player_id;
|
|
|
|
|
let sacrificial_wolf_player_id = players[2].player_id;
|
|
|
|
|
let mut settings = GameSettings::empty();
|
|
|
|
|
settings.add_and_assign(
|
|
|
|
|
SetupRole::Scapegoat {
|
|
|
|
|
redeemed: OrRandom::Determined(true),
|
|
|
|
|
},
|
|
|
|
|
scapegoat_player_id,
|
|
|
|
|
);
|
|
|
|
|
settings.add_and_assign(SetupRole::Werewolf, wolf_player_id);
|
|
|
|
|
settings.add_and_assign(SetupRole::Werewolf, sacrificial_wolf_player_id);
|
|
|
|
|
settings.fill_remaining_slots_with_villagers(9);
|
|
|
|
|
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.mark_for_execution(
|
|
|
|
|
game.character_by_player_id(sacrificial_wolf_player_id)
|
|
|
|
|
.character_id(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
game.execute().title().wolf_pack_kill();
|
|
|
|
|
game.mark_and_check(
|
|
|
|
|
game.living_villager_excl(scapegoat_player_id)
|
|
|
|
|
.character_id(),
|
|
|
|
|
);
|
|
|
|
|
game.r#continue().sleep();
|
|
|
|
|
|
|
|
|
|
game.next_expect_day();
|
|
|
|
|
|
|
|
|
|
let day_scapegoat = game.character_by_player_id(scapegoat_player_id);
|
|
|
|
|
assert_eq!(day_scapegoat.role().title(), RoleTitle::Scapegoat);
|
|
|
|
|
}
|