ben
/
aoc
1
0
Fork 0
aoc/AOC2015/Day22.cs

111 lines
3.1 KiB
C#
Raw Normal View History

2023-11-07 22:34:25 +00:00
using MoreLinq.Extensions;
2022-12-03 05:55:49 +00:00
namespace AOC2015;
/// <summary>
2022-12-03 05:41:38 +00:00
/// Day 22: <a href="https://adventofcode.com/2015/day/22"/>
/// </summary>
2023-09-20 18:38:58 +00:00
public sealed class Day22() : Day(2015, 22, "Wizard Simulator 20XX")
{
2023-12-01 07:30:47 +00:00
private static readonly List<Spell> Spells =
[
2023-11-07 22:34:25 +00:00
new("Magic Missile", Mana: 53, Damage: 4),
new("Drain", Mana: 73, Damage: 2, Heal: 2),
new("Shield", Mana: 113, Armor: 7, Duration: 6),
new("Poison", Mana: 173, Damage: 3, Duration: 6),
new("Recharge", Mana: 229, ManaCharge: 101, Duration: 5)
2023-12-01 07:30:47 +00:00
];
2023-11-07 22:34:25 +00:00
private Dictionary<string, int> _boss;
2023-12-01 18:21:24 +00:00
private record Spell(
// ReSharper disable once NotAccessedPositionalProperty.Local
2023-12-01 07:30:47 +00:00
string Name,
int Mana,
int Duration = 0,
int Damage = 0,
int Heal = 0,
int Armor = 0,
int ManaCharge = 0
);
2023-11-07 22:34:25 +00:00
2023-12-01 18:21:24 +00:00
private struct GameState(bool HardMode = false, int RoundNumber = 0, int TotalManaSpent = 0, int PlayerHealth = 50,
2023-11-07 22:34:25 +00:00
int PlayerMana = 500, int BossHealth = 0, int BossDamage = 0, Dictionary<Spell, int>? ActiveSpells = null)
{
public GameResult DoTurn(Spell spell)
{
RoundNumber++;
CastSpell(spell);
ProcessActiveSpells();
if (BossHealth <= 0) return GameResult.Win;
PlayerHealth -= Math.Max(1, BossDamage - ActiveSpells.Sum(x => x.Key.Armor));
if (PlayerHealth <= 0) return GameResult.Loss;
if (HardMode)
{
}
ProcessActiveSpells();
return BossHealth <= 0 ? GameResult.Win : GameResult.Continue;
}
private void CastSpell(Spell spell)
{
TotalManaSpent += spell.Mana;
PlayerMana -= spell.Mana;
if (spell.Duration == 0) ProcessSpell(spell);
else ActiveSpells.Add(spell, spell.Duration);
}
private void ProcessActiveSpells()
{
ActiveSpells.Keys.ForEach(ProcessSpell);
foreach (var (spell, duration) in ActiveSpells.ToList())
{
if (duration == 1) ActiveSpells.Remove(spell);
else ActiveSpells[spell]--;
}
}
private void ProcessSpell(Spell spell)
{
BossHealth -= spell.Damage;
PlayerHealth += spell.Heal;
PlayerMana += spell.ManaCharge;
}
}
2023-12-01 18:21:24 +00:00
private enum GameResult
2023-11-07 22:34:25 +00:00
{
Win,
Loss,
Continue
}
private GameState ProcessStates(GameState initialState)
{
var stateQueue = new Queue<GameState>();
stateQueue.Enqueue(initialState);
GameState bestGame = new(BossHealth: _boss["Hit Points"], BossDamage: _boss["Damage"]);
var roundsProcessed = 0;
while (stateQueue.Count > 0)
{
}
return initialState;
}
2023-12-01 07:30:47 +00:00
public override void ProcessInput() =>
2023-11-07 22:34:25 +00:00
_boss = Input.ToDictionary(k => k.Split(": ")[0], v => int.Parse(v.Split(": ")[1]));
2023-12-01 07:30:47 +00:00
public override object Part1() =>
ProcessStates(new(BossHealth: _boss["Hit Points"], BossDamage: _boss["Damage"]));
public override object Part2() => "";
2023-12-01 07:30:47 +00:00
}