diff --git a/werewolves-proto/src/game/night.rs b/werewolves-proto/src/game/night.rs index 388b197..28a86f5 100644 --- a/werewolves-proto/src/game/night.rs +++ b/werewolves-proto/src/game/night.rs @@ -307,13 +307,15 @@ impl Night { } // remove prompts by the reverting wolf that are in the queue - for prompt in action_queue { + // for prompt in action_queue { + while let Some(prompt) = action_queue.pop_front() { + log::warn!("prompt: {:?}", prompt.title()); let (wolf_id, prompt) = match prompt { ActionPrompt::WolvesIntro { mut wolves } => { if let Some(w) = wolves.iter_mut().find(|w| w.0.character_id == reverting) { w.1 = reverting_into; } - new_queue.push_front(ActionPrompt::WolvesIntro { wolves }); + new_queue.push_back(ActionPrompt::WolvesIntro { wolves }); continue; } @@ -358,12 +360,12 @@ impl Night { }, ), other => { - new_queue.push_front(other); + new_queue.push_back(other); continue; } }; if wolf_id != reverting { - new_queue.push_front(prompt); + new_queue.push_back(prompt); } } @@ -435,9 +437,36 @@ impl Night { // put it back in self.action_queue.push_front(next); } + + let ss_target = changes.iter().find_map(|c| match c { + NightChange::Shapeshift { into, .. } => Some(into), + _ => None, + }); + core::mem::swap(&mut prompt, current_prompt); let last_prompt = prompt; - self.action_queue.push_front(last_prompt); + let next_prompt_ss_related_role_change = match (&last_prompt, ss_target) { + ( + ActionPrompt::RoleChange { + character_id, + new_role: RoleTitle::Werewolf, + }, + Some(ss_target), + ) => character_id.character_id == *ss_target, + (_, _) => false, + }; + if !next_prompt_ss_related_role_change { + // only push the last prompt back in if it's not the + // role change associated with the shapeshift + self.action_queue.push_front(last_prompt); + } + log::warn!( + "next prompts: {:?}", + self.action_queue + .iter() + .map(ActionPrompt::title) + .collect::>() + ); *current_result = None; *current_changes = Vec::new(); Ok(()) diff --git a/werewolves-proto/src/game_test/mod.rs b/werewolves-proto/src/game_test/mod.rs index d33d4d5..f419ed9 100644 --- a/werewolves-proto/src/game_test/mod.rs +++ b/werewolves-proto/src/game_test/mod.rs @@ -609,36 +609,11 @@ fn no_wolf_kill_n1() { let mut settings = GameSettings::default(); settings.new_slot(RoleTitle::Shapeshifter); settings.new_slot(RoleTitle::Protector); - for _ in 0..7 { - settings.new_slot(RoleTitle::Villager); - } - if let Some(slot) = settings - .slots() - .iter() - .find(|s| matches!(s.role, SetupRole::Werewolf)) - { - settings.remove_slot(slot.slot_id); - } + settings.fill_remaining_slots_with_villagers(players.len()); let mut game = Game::new(&players, settings).unwrap(); - assert_eq!( - game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( - ActionResponse::Continue - ))) - .unwrap(), - ServerToHostMessage::ActionResult(None, ActionResult::Continue) - ); - assert!(matches!( - game.process(HostGameMessage::Night(HostNightMessage::Next)) - .unwrap(), - ServerToHostMessage::ActionPrompt(ActionPrompt::WolvesIntro { wolves: _ }, 0) - )); - assert_eq!( - game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( - ActionResponse::Continue - ))) - .unwrap(), - ServerToHostMessage::ActionResult(None, ActionResult::GoBackToSleep), - ); + game.r#continue().r#continue(); + game.next().title().wolves_intro(); + game.r#continue().sleep(); game.next_expect_day(); } @@ -725,17 +700,8 @@ fn wolfpack_kill_all_targets_valid() { init_log(); let players = gen_players(1..10); let mut settings = GameSettings::default(); - for _ in 0..8 { - settings.new_slot(RoleTitle::Villager); - } settings.new_slot(RoleTitle::Shapeshifter); - if let Some(slot) = settings - .slots() - .iter() - .find(|s| matches!(s.role, SetupRole::Werewolf)) - { - settings.remove_slot(slot.slot_id); - } + settings.fill_remaining_slots_with_villagers(players.len()); let mut game = Game::new(&players, settings).unwrap(); game.r#continue().r#continue(); @@ -923,10 +889,6 @@ fn big_game_test_based_on_story_test() { game.mark(game.character_by_player_id(werewolf).character_id()); game.r#continue().power_seer(); - game.next().title().beholder(); - game.mark(game.character_by_player_id(arcanist).character_id()); - game.r#continue().role_blocked(); - game.next_expect_day(); game.mark_for_execution(game.character_by_player_id(dire_wolf).character_id()); game.mark_for_execution(game.character_by_player_id(alpha_wolf).character_id()); @@ -1067,18 +1029,21 @@ fn big_game_test_based_on_story_test() { game.living_villager_excl(protect.player_id()) .character_id(), ); - game.execute().title().vindicator(); + assert_eq!( + game.execute(), + ActionPrompt::RoleChange { + character_id: game.character_by_player_id(shapeshifter).identity(), + new_role: RoleTitle::Werewolf + } + ); + game.r#continue().sleep(); + + game.next().title().vindicator(); game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().wolf_pack_kill(); game.mark(game.character_by_player_id(empath).character_id()); - game.r#continue().r#continue(); - - game.next().title().shapeshifter(); - game.response(ActionResponse::Shapeshift).r#continue(); - - game.next().title().role_change(); game.r#continue().sleep(); game.next().title().seer(); @@ -1132,20 +1097,20 @@ fn big_game_test_based_on_story_test() { game.next().title().arcanist(); game.mark(game.character_by_player_id(insomniac).character_id()); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().arcanist(); game.next().title().adjudicator(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().adjudicator(); game.next().title().power_seer(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().power_seer(); game.next().title().gravedigger(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); - assert_eq!(game.r#continue().gravedigger(), None); + game.mark(game.character_by_player_id(empath).character_id()); + assert_eq!(game.r#continue().gravedigger(), Some(RoleTitle::Empath)); game.next().title().mortician(); game.mark(game.character_by_player_id(werewolf).character_id()); @@ -1159,7 +1124,7 @@ fn big_game_test_based_on_story_test() { game.r#continue().sleep(); game.next().title().hunter(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().insomniac(); diff --git a/werewolves-proto/src/game_test/previous.rs b/werewolves-proto/src/game_test/previous.rs index ccf4e12..d7147ce 100644 --- a/werewolves-proto/src/game_test/previous.rs +++ b/werewolves-proto/src/game_test/previous.rs @@ -79,6 +79,7 @@ fn previous_shapeshifter_undone_redone() { #[test] fn previous_shapeshifter_undone_and_changed_to_no() { + init_log(); let players = gen_players(1..21); let shapeshifter_player_id = players[0].player_id; let wolf_player_id = players[1].player_id; @@ -318,10 +319,6 @@ fn previous_prompt() { game.mark(game.character_by_player_id(werewolf).character_id()); game.r#continue().power_seer(); - game.next().title().beholder(); - game.mark(game.character_by_player_id(arcanist).character_id()); - game.r#continue().role_blocked(); - game.next_expect_day(); game.mark_for_execution(game.character_by_player_id(dire_wolf).character_id()); game.mark_for_execution(game.character_by_player_id(alpha_wolf).character_id()); diff --git a/werewolves-proto/src/game_test/role/beholder.rs b/werewolves-proto/src/game_test/role/beholder.rs index 034da7b..69a60af 100644 --- a/werewolves-proto/src/game_test/role/beholder.rs +++ b/werewolves-proto/src/game_test/role/beholder.rs @@ -32,6 +32,15 @@ fn beholding_seer() { game.mark(game.character_by_player_id(wolf_player_id).character_id()); game.r#continue().seer().wolves(); + game.next_expect_day(); + game.execute().title().wolf_pack_kill(); + game.mark(game.living_villager().character_id()); + game.r#continue().sleep(); + + game.next().title().seer(); + game.mark(game.character_by_player_id(wolf_player_id).character_id()); + game.r#continue().seer().wolves(); + game.next().title().beholder(); game.mark(game.character_by_player_id(seer_player_id).character_id()); game.r#continue().seer().wolves(); @@ -53,10 +62,6 @@ fn beholding_wolf() { assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro); game.r#continue().sleep(); - game.next().title().beholder(); - game.mark(game.character_by_player_id(wolf_player_id).character_id()); - game.r#continue().sleep(); - game.next_expect_day(); game.execute().title().wolf_pack_kill(); game.mark(game.living_villager_excl(beholder_player_id).character_id()); diff --git a/werewolves-proto/src/game_test/role/shapeshifter.rs b/werewolves-proto/src/game_test/role/shapeshifter.rs index 2163eae..601c49f 100644 --- a/werewolves-proto/src/game_test/role/shapeshifter.rs +++ b/werewolves-proto/src/game_test/role/shapeshifter.rs @@ -22,24 +22,9 @@ fn protect_stops_shapeshift() { let mut settings = GameSettings::default(); settings.new_slot(RoleTitle::Shapeshifter); settings.new_slot(RoleTitle::Protector); - for _ in 0..7 { - settings.new_slot(RoleTitle::Villager); - } - if let Some(slot) = settings - .slots() - .iter() - .find(|s| matches!(s.role, SetupRole::Werewolf)) - { - settings.remove_slot(slot.slot_id); - } + settings.fill_remaining_slots_with_villagers(players.len()); let mut game = Game::new(&players, settings).unwrap(); - assert_eq!( - game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( - ActionResponse::Continue, - ))) - .unwrap(), - ServerToHostMessage::ActionResult(None, ActionResult::Continue) - ); + game.r#continue().r#continue(); game.next().title().wolves_intro(); assert_eq!( game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( @@ -154,19 +139,12 @@ fn protect_stops_shapeshift() { #[test] fn only_1_shapeshift_prompt_if_first_shifts() { let players = gen_players(1..10); - let mut settings = GameSettings::default(); + let mut settings = GameSettings::empty(); + settings.new_slot(RoleTitle::Werewolf); settings.new_slot(RoleTitle::Shapeshifter); settings.new_slot(RoleTitle::Shapeshifter); - for _ in 0..7 { - settings.new_slot(RoleTitle::Villager); - } - if let Some(slot) = settings - .slots() - .iter() - .find(|s| matches!(s.role, SetupRole::Werewolf)) - { - settings.remove_slot(slot.slot_id); - } + settings.fill_remaining_slots_with_villagers(players.len()); + let mut game = Game::new(&players, settings).unwrap(); game.r#continue().r#continue(); assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro); diff --git a/werewolves/src/clients/host/story_test.rs b/werewolves/src/clients/host/story_test.rs index 4fd0221..cd21b23 100644 --- a/werewolves/src/clients/host/story_test.rs +++ b/werewolves/src/clients/host/story_test.rs @@ -174,10 +174,6 @@ pub fn test_story() -> GameStory { game.mark(game.character_by_player_id(werewolf).character_id()); game.r#continue().power_seer(); - game.next().title().beholder(); - game.mark(game.character_by_player_id(arcanist).character_id()); - game.r#continue().role_blocked(); - game.next_expect_day(); game.mark_for_execution(game.character_by_player_id(dire_wolf).character_id()); game.mark_for_execution(game.character_by_player_id(alpha_wolf).character_id()); @@ -318,18 +314,21 @@ pub fn test_story() -> GameStory { game.living_villager_excl(protect.player_id()) .character_id(), ); - game.execute().title().vindicator(); + assert_eq!( + game.execute(), + ActionPrompt::RoleChange { + character_id: game.character_by_player_id(shapeshifter).identity(), + new_role: RoleTitle::Werewolf + } + ); + game.r#continue().sleep(); + + game.next().title().vindicator(); game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().wolf_pack_kill(); game.mark(game.character_by_player_id(empath).character_id()); - game.r#continue().r#continue(); - - game.next().title().shapeshifter(); - game.response(ActionResponse::Shapeshift).r#continue(); - - game.next().title().role_change(); game.r#continue().sleep(); game.next().title().seer(); @@ -383,20 +382,20 @@ pub fn test_story() -> GameStory { game.next().title().arcanist(); game.mark(game.character_by_player_id(insomniac).character_id()); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().arcanist(); game.next().title().adjudicator(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().adjudicator(); game.next().title().power_seer(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().power_seer(); game.next().title().gravedigger(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); - assert_eq!(game.r#continue().gravedigger(), None); + game.mark(game.character_by_player_id(empath).character_id()); + assert_eq!(game.r#continue().gravedigger(), Some(RoleTitle::Empath)); game.next().title().mortician(); game.mark(game.character_by_player_id(werewolf).character_id()); @@ -410,7 +409,7 @@ pub fn test_story() -> GameStory { game.r#continue().sleep(); game.next().title().hunter(); - game.mark(game.character_by_player_id(empath).character_id()); + game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().insomniac();