werewolves/werewolves-proto/src/game_test/role/black_knight.rs

105 lines
3.6 KiB
Rust
Raw Normal View History

// 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-06 21:59:44 +01:00
use core::num::NonZeroU8;
#[allow(unused)]
use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
use crate::{
diedto::DiedTo,
game::{Game, GameSettings, OrRandom, SetupRole},
game_test::{
ActionPromptTitleExt, ActionResultExt, AlignmentExt, GameExt, ServerToHostMessageExt,
SettingsExt, gen_players,
},
message::{
host::{HostDayMessage, HostGameMessage},
night::{ActionPrompt, ActionPromptTitle, ActionResult},
},
role::Role,
};
#[test]
fn dies_day_after() {
let players = gen_players(1..10);
let black_knight = players[0].player_id;
let wolf_player_id = players[1].player_id;
let mut settings = GameSettings::empty();
settings.add_and_assign(SetupRole::BlackKnight, black_knight);
settings.add_and_assign(SetupRole::Werewolf, 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.execute().title().wolf_pack_kill();
game.mark(game.character_by_player_id(black_knight).character_id());
game.r#continue().sleep();
game.next_expect_day();
assert_eq!(game.character_by_player_id(black_knight).died_to(), None);
game.execute().title().wolf_pack_kill();
game.mark(game.villager_character_ids().into_iter().next().unwrap());
game.r#continue().sleep();
game.next_expect_day();
assert_eq!(
game.character_by_player_id(black_knight).died_to().cloned(),
Some(DiedTo::Wolfpack {
killing_wolf: game.character_by_player_id(wolf_player_id).character_id(),
night: NonZeroU8::new(2).unwrap()
})
);
}
#[test]
fn you_can_just_keep_whacking_it() {
let players = gen_players(1..10);
let black_knight = players[0].player_id;
let wolf_player_id = players[1].player_id;
let mut settings = GameSettings::empty();
settings.add_and_assign(SetupRole::BlackKnight, black_knight);
settings.add_and_assign(SetupRole::Werewolf, 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.execute().title().wolf_pack_kill();
game.mark(game.character_by_player_id(black_knight).character_id());
game.r#continue().sleep();
game.next_expect_day();
for _ in 0..100 {
assert_eq!(game.character_by_player_id(black_knight).died_to(), None);
game.execute().title().wolf_pack_kill();
game.mark(game.character_by_player_id(black_knight).character_id());
game.r#continue().sleep();
game.next_expect_day();
}
}