diff options
Diffstat (limited to '2015/src')
| -rw-r--r-- | 2015/src/day22.cpp | 29 |
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 | ||
| 566 | RoundState | 566 | RoundState |
| 567 | battle_round(Player& player, Boss& boss, Spells& spells) | 567 | battle_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 | ||
| 604 | void | 608 | void |
| 605 | part1() | 609 | play(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 | ||
| 635 | void | ||
| 636 | part1() | ||
| 637 | { | ||
| 638 | play(); | ||
| 639 | } | ||
| 640 | |||
| 641 | void | ||
| 642 | part2() | ||
| 643 | { | ||
| 644 | play(true); | ||
| 645 | } | ||
| 646 | |||
| 631 | int | 647 | int |
| 632 | main() | 648 | main() |
| 633 | { | 649 | { |
| 634 | srand((unsigned int) time(NULL)); | 650 | srand((unsigned int) time(NULL)); |
| 635 | part1(); | 651 | part1(); |
| 652 | part2(); | ||
| 636 | } | 653 | } |
