aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-07 22:16:53 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-07 22:16:53 +0800
commit5eb95d08e5d8947ca4d2c1521607c917b8ac9daa (patch)
tree9ae8bce8b873b51d6e8a33e32abedd4cf4105161 /src
parentc5adb2f1ede041114bd380ddf2729c60234165a0 (diff)
downloadadvent-of-code-5eb95d08e5d8947ca4d2c1521607c917b8ac9daa.tar.gz
advent-of-code-5eb95d08e5d8947ca4d2c1521607c917b8ac9daa.zip
2015 day22 part1
Diffstat (limited to 'src')
-rw-r--r--src/2015/day22/aoc.cpp35
-rw-r--r--src/2015/day22/aoc.h1
2 files changed, 33 insertions, 3 deletions
diff --git a/src/2015/day22/aoc.cpp b/src/2015/day22/aoc.cpp
index 1e6ae41..e9aa969 100644
--- a/src/2015/day22/aoc.cpp
+++ b/src/2015/day22/aoc.cpp
@@ -1,4 +1,5 @@
#include "aoc.h"
+#include <vector>
namespace aoc2015 {
@@ -11,14 +12,42 @@ static spell spells[5] = {
{229, 5, 0, 0, 101, 0, 0},
};
-bool effects(wizard&);
+void effects(wizard& w) {
+ for (int i = 0; i < 5; i++) {
+ spell* s = w.spells[i];
+ if (s != nullptr && s->tick > 0) {
+ w.points -= s->damage;
+ w.wp->points += s->heals;
+ w.wp->mana += s->payback;
+ w.wp->armor += s->protect;
+ s->tick -= 1;
+ }
+ }
+}
+
+void fight(int turn, wizard& me, wizard& boss, int* cost, std::vector<int>& costs) {
+ // wizard* w = turn % 2 == 1 ? &me : &boss;
+}
std::pair<int, int> day22(wizard me, wizard boss) {
- me.spells[0] = & bosskill;
+ me.wp = &boss;
+ boss.wp = &me;
+ me.spells[0] = &bosskill;
for (int i = 0; i < 5; i++) {
boss.spells[i] = spells + i;
}
- return {0, 0};
+ int cost{0};
+ std::vector<int> costs;
+ fight(1, me, boss, &cost, costs);
+
+ int min{INT32_MAX};
+ for(auto& c : costs) {
+ if (c < min) {
+ min = c;
+ }
+ }
+
+ return {min, 0};
}
}
diff --git a/src/2015/day22/aoc.h b/src/2015/day22/aoc.h
index 1c53c20..8596f55 100644
--- a/src/2015/day22/aoc.h
+++ b/src/2015/day22/aoc.h
@@ -8,6 +8,7 @@ struct wizard {
int points;
int armor;
int mana;
+ wizard* wp = nullptr;
spell* spells[5] = {nullptr, nullptr, nullptr, nullptr, nullptr};
};