From deb699164f84073ed15729764360c62b46cfd4c4 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Mon, 6 Jan 2025 10:11:08 +0100 Subject: aoc 2015, day 22, part 2 --- 2015/src/day22.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to '2015/src') diff --git a/2015/src/day22.cpp b/2015/src/day22.cpp index b7a23d0..0ec54ee 100644 --- a/2015/src/day22.cpp +++ b/2015/src/day22.cpp @@ -564,12 +564,16 @@ enum RoundState { }; RoundState -battle_round(Player& player, Boss& boss, Spells& spells) +battle_round(Player& player, Boss& boss, Spells& spells, bool hard_mode) { debug << "\n-- Player turn --\n" << player << '\n' << boss << endl; + if ( hard_mode ) { + player.SubHitPoints(1); + } + spells.Play(player, boss); if ( player.HasLost() ) { return Player_Lost; @@ -602,23 +606,23 @@ battle_round(Player& player, Boss& boss, Spells& spells) } void -part1() +play(bool hard_mode = false) { const Boss boss_master("data/day22.txt"); static const Mana start_mana = 500; static const HitPoints start_hitpoints = 50; - auto min_mana{ 999999 }; + auto min_mana{ 999999999 }; - for ( int i = 0; i != 500000; ++i ) { + for ( int i = 0; i != 1000000; ++i ) { Boss boss{ boss_master }; Player player(start_mana, start_hitpoints); Spells spells; - auto roundState = battle_round(player, boss, spells); + auto roundState = battle_round(player, boss, spells, hard_mode); while ( roundState == Undecided ) { - roundState = battle_round(player, boss, spells); + roundState = battle_round(player, boss, spells, hard_mode); } if ( roundState == Boss_Lost ) { @@ -628,9 +632,22 @@ part1() cout << min_mana << endl; } +void +part1() +{ + play(); +} + +void +part2() +{ + play(true); +} + int main() { srand((unsigned int) time(NULL)); part1(); + part2(); } -- cgit v1.3