From 5985ee505cc316a1121352cb6c502f92b485387e Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Sat, 14 Sep 2024 10:31:23 -0600 Subject: [PATCH 1/3] Add reversed score cycle function for s7 --- CHANGELOG.md | 5 +++++ src/constants/seasonal.rs | 42 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd02128..2ef0e4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ Unreleased - Change inner u8 of `RoomCoordinate` to private - Use `f64` instead of `u64` to work around bindgen expecting `BigInt` return values +### Additions: + +- Add `s7_score_cycle_at_tick` seasonal constant function to reflect the reversed score cycle in + season 7 + 0.22.0 (2024-08-27) =================== diff --git a/src/constants/seasonal.rs b/src/constants/seasonal.rs index 2e5c1962..36229a74 100644 --- a/src/constants/seasonal.rs +++ b/src/constants/seasonal.rs @@ -106,6 +106,7 @@ pub mod season_1 { } } + /// Calculates the state of the score cycle for season 1 pub const fn score_cycle_at_tick(tick: u32) -> ScoreCycleState { match tick % SCORE_CYCLE_DURATION { // the bonus/crisis periods are exclusive of their boundaries @@ -120,12 +121,28 @@ pub mod season_1 { } } + /// Calculates the state of the score cycle for season 7, which reverses the + /// crisis/bonus order + pub const fn s7_score_cycle_at_tick(tick: u32) -> ScoreCycleState { + match tick % SCORE_CYCLE_DURATION { + // the bonus/crisis periods are exclusive of their boundaries + // https://github.com/screeps/mod-season1/blob/7ca3c7ddb47bf9dfbdfb4e72b666a3159fde8780/src/scoreContainer.roomObject.js#L77-L81 + // match on those exact values first + SCORE_CYCLE_CRISIS_START => ScoreCycleState::Normal, + SCORE_CYCLE_BONUS_START => ScoreCycleState::Normal, + // then on the remaining ranges + SCORE_CYCLE_CRISIS_START..SCORE_CYCLE_CRISIS_END => ScoreCycleState::Bonus, + SCORE_CYCLE_BONUS_START..SCORE_CYCLE_BONUS_END => ScoreCycleState::Crisis, + _ => ScoreCycleState::Normal, + } + } + #[cfg(test)] mod test { use super::{score_cycle_at_tick, ScoreCycleState}; #[test] - fn score_cycle() { + fn s1_score_cycle() { assert_eq!(score_cycle_at_tick(0), ScoreCycleState::Normal); assert_eq!(score_cycle_at_tick(10_000), ScoreCycleState::Normal); assert_eq!(score_cycle_at_tick(10_001), ScoreCycleState::Crisis); @@ -146,6 +163,29 @@ pub mod season_1 { assert_eq!(score_cycle_at_tick(249_999), ScoreCycleState::Bonus); assert_eq!(score_cycle_at_tick(250_000), ScoreCycleState::Normal); } + + #[test] + fn s7_score_cycle() { + assert_eq!(s7_score_cycle_at_tick(0), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(10_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(10_001), ScoreCycleState::Bonus); + assert_eq!(s7_score_cycle_at_tick(14_999), ScoreCycleState::Bonus); + assert_eq!(s7_score_cycle_at_tick(15_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(45_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(45_001), ScoreCycleState::Crisis); + assert_eq!(s7_score_cycle_at_tick(49_999), ScoreCycleState::Crisis); + assert_eq!(s7_score_cycle_at_tick(50_000), ScoreCycleState::Normal); + + assert_eq!(s7_score_cycle_at_tick(200_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(210_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(210_001), ScoreCycleState::Bonus); + assert_eq!(s7_score_cycle_at_tick(214_999), ScoreCycleState::Bonus); + assert_eq!(s7_score_cycle_at_tick(215_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(245_000), ScoreCycleState::Normal); + assert_eq!(s7_score_cycle_at_tick(245_001), ScoreCycleState::Crisis); + assert_eq!(s7_score_cycle_at_tick(249_999), ScoreCycleState::Crisis); + assert_eq!(s7_score_cycle_at_tick(250_000), ScoreCycleState::Normal); + } } } From db5684b692203b9a5f645b9cc4d9ed498a12e7d1 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Sat, 14 Sep 2024 10:32:37 -0600 Subject: [PATCH 2/3] improve comment --- src/constants/seasonal.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/constants/seasonal.rs b/src/constants/seasonal.rs index 36229a74..4de79b78 100644 --- a/src/constants/seasonal.rs +++ b/src/constants/seasonal.rs @@ -130,7 +130,8 @@ pub mod season_1 { // match on those exact values first SCORE_CYCLE_CRISIS_START => ScoreCycleState::Normal, SCORE_CYCLE_BONUS_START => ScoreCycleState::Normal, - // then on the remaining ranges + // then on the remaining ranges - these are flipped from normal in s7, which is + // not currently open sourced SCORE_CYCLE_CRISIS_START..SCORE_CYCLE_CRISIS_END => ScoreCycleState::Bonus, SCORE_CYCLE_BONUS_START..SCORE_CYCLE_BONUS_END => ScoreCycleState::Crisis, _ => ScoreCycleState::Normal, From bdf139a8781c3f12e88020d59deb41c9a8aeeac5 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Sat, 14 Sep 2024 10:34:42 -0600 Subject: [PATCH 3/3] fix tests --- src/constants/seasonal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/seasonal.rs b/src/constants/seasonal.rs index 4de79b78..b347a256 100644 --- a/src/constants/seasonal.rs +++ b/src/constants/seasonal.rs @@ -140,7 +140,7 @@ pub mod season_1 { #[cfg(test)] mod test { - use super::{score_cycle_at_tick, ScoreCycleState}; + use super::{s7_score_cycle_at_tick, score_cycle_at_tick, ScoreCycleState}; #[test] fn s1_score_cycle() {