aboutsummaryrefslogtreecommitdiff
path: root/2015/src/day22.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-01-06 10:11:08 +0100
committerThomas Schmucker <ts@its1.de>2025-01-06 10:11:08 +0100
commitdeb699164f84073ed15729764360c62b46cfd4c4 (patch)
tree5e39aa23be3b8fd73f4e290219944e68f68f8324 /2015/src/day22.cpp
parent4e483dc86733bbc7dc877a382c1cf0115dfe8eb0 (diff)
downloadadvent-of-code-deb699164f84073ed15729764360c62b46cfd4c4.tar.gz
advent-of-code-deb699164f84073ed15729764360c62b46cfd4c4.tar.bz2
advent-of-code-deb699164f84073ed15729764360c62b46cfd4c4.zip
aoc 2015, day 22, part 2
Diffstat (limited to '2015/src/day22.cpp')
-rw-r--r--2015/src/day22.cpp29
1 files changed, 23 insertions, 6 deletions
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 {
564}; 564};
565 565
566RoundState 566RoundState
567battle_round(Player& player, Boss& boss, Spells& spells) 567battle_round(Player& player, Boss& boss, Spells& spells, bool hard_mode)
568{ 568{
569 debug << "\n-- Player turn --\n" 569 debug << "\n-- Player turn --\n"
570 << player << '\n' 570 << player << '\n'
571 << boss << endl; 571 << boss << endl;
572 572
573 if ( hard_mode ) {
574 player.SubHitPoints(1);
575 }
576
573 spells.Play(player, boss); 577 spells.Play(player, boss);
574 if ( player.HasLost() ) { 578 if ( player.HasLost() ) {
575 return Player_Lost; 579 return Player_Lost;
@@ -602,23 +606,23 @@ battle_round(Player& player, Boss& boss, Spells& spells)
602} 606}
603 607
604void 608void
605part1() 609play(bool hard_mode = false)
606{ 610{
607 const Boss boss_master("data/day22.txt"); 611 const Boss boss_master("data/day22.txt");
608 612
609 static const Mana start_mana = 500; 613 static const Mana start_mana = 500;
610 static const HitPoints start_hitpoints = 50; 614 static const HitPoints start_hitpoints = 50;
611 615
612 auto min_mana{ 999999 }; 616 auto min_mana{ 999999999 };
613 617
614 for ( int i = 0; i != 500000; ++i ) { 618 for ( int i = 0; i != 1000000; ++i ) {
615 Boss boss{ boss_master }; 619 Boss boss{ boss_master };
616 Player player(start_mana, start_hitpoints); 620 Player player(start_mana, start_hitpoints);
617 Spells spells; 621 Spells spells;
618 622
619 auto roundState = battle_round(player, boss, spells); 623 auto roundState = battle_round(player, boss, spells, hard_mode);
620 while ( roundState == Undecided ) { 624 while ( roundState == Undecided ) {
621 roundState = battle_round(player, boss, spells); 625 roundState = battle_round(player, boss, spells, hard_mode);
622 } 626 }
623 627
624 if ( roundState == Boss_Lost ) { 628 if ( roundState == Boss_Lost ) {
@@ -628,9 +632,22 @@ part1()
628 cout << min_mana << endl; 632 cout << min_mana << endl;
629} 633}
630 634
635void
636part1()
637{
638 play();
639}
640
641void
642part2()
643{
644 play(true);
645}
646
631int 647int
632main() 648main()
633{ 649{
634 srand((unsigned int) time(NULL)); 650 srand((unsigned int) time(NULL));
635 part1(); 651 part1();
652 part2();
636} 653}