aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-01 09:10:58 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-01 09:10:58 +0800
commit4348c6981803d7004d5246370e95d2dca97d790c (patch)
tree23bf594d174d2352f2ca871518361da43c6b94ff /src
parentf37bab92c49dcbd4cf08ad5962dad5cb83fef68e (diff)
downloadadvent-of-code-4348c6981803d7004d5246370e95d2dca97d790c.tar.gz
advent-of-code-4348c6981803d7004d5246370e95d2dca97d790c.zip
cast spell
Diffstat (limited to 'src')
-rw-r--r--src/2015/day22/aoc.h50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/2015/day22/aoc.h b/src/2015/day22/aoc.h
index eae4825..d2ccd7d 100644
--- a/src/2015/day22/aoc.h
+++ b/src/2015/day22/aoc.h
@@ -1,14 +1,25 @@
#pragma once
#include "common.h"
#include <set>
+#include <stack>
#include <vector>
namespace aoc2015 {
+enum class stype {
+ magic_missile = 0,
+ drain,
+ shield,
+ poison,
+ recharge,
+};
+
+struct spell;
struct wizard {
int hitpoints;
int armor;
int mana;
+ std::stack<spell*> spells[5];
bool alive() const noexcept { return mana > 0 && hitpoints > 0; }
};
@@ -59,6 +70,43 @@ struct recharge : public spell {
virtual void unapply(wizard& w) override { w.mana -= 101; }
};
-struct arena {};
+struct arena {
+ void cast(int s, wizard& w1, wizard& w2) {
+ switch (stype(s)) {
+ case stype::magic_missile:
+ if (w1.spells[s].empty()) {
+ w1.spells[s].emplace(new magic_missile);
+ }
+ break;
+ case stype::drain:
+ if (w1.spells[s].empty() && w2.spells[s].empty()) {
+ w1.spells[s].emplace(new drain_hurt);
+ w2.spells[s].emplace(new drain_heal);
+ }
+ break;
+ case stype::shield:
+ if (w1.spells[s].empty()) {
+ for (int i = 0; i < 6; i++) {
+ w1.spells[s].emplace(new shield);
+ }
+ }
+ break;
+ case stype::poison:
+ if (w1.spells[s].empty()) {
+ for (int i = 0; i < 6; i++) {
+ w1.spells[s].emplace(new poison);
+ }
+ }
+ break;
+ case stype::recharge:
+ if (w1.spells[s].empty()) {
+ for (int i = 0; i < 5; i++) {
+ w1.spells[s].emplace(new recharge);
+ }
+ break;
+ }
+ }
+ }
+};
} // namespace aoc2015