Skip to content

Commit c70fa4f

Browse files
committed
day 22 update
1 parent 8e3d8d2 commit c70fa4f

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

day22/src/main.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,30 @@ Recharge costs 229 mana. It starts an effect that lasts for 5 turns. At the star
77
*/
88

99
fn one_spell(spell_id: &str, hp: i8, mp: u8, s_e: u8, p_e: u8, r_e: u8, m_spend: u16, b_hp: u8, b_dmg: &u8, m_spend_min: &mut u16) -> u16 {
10-
let bdmg = *b_gmg;
11-
if s_e > 0 {
12-
let s_e = s_e - 1;
13-
10+
if ((spell_id == "S" && s_e > 0) || (spell_id == "P" && p_e > 0) || (spell_id == "R" && r_e > 0)) {
11+
return 0;
12+
};
13+
let (s_e, bdmg) = if s_e > 0 {(s_e - 1, *b_dmg - 7)} else {(0, *b_dmg)};
14+
let (p_e, b_hp) = if p_e > 0 {(p_e - 1, b_hp - 3)} else {(0, b_hp)};
15+
let (r_e, mp) = if r_e > 0 {(r_e - 1, mp + 101)} else {(0, mp)};
16+
if (mp <= 0 || hp <= 0) {
17+
return 0;
1418
}
15-
let (hp, mp, s_e, p_e, r_e, now_spend, b_hp) = match spell_id {
16-
"M" => {(hp, mp - 53, s_e, p_e, r_e, 53, b_hp - 4)},
17-
"D" => {(hp + 2, mp - 73, s_e, p_e, r_e, 73, b_hp - 2)},
18-
"S" => {(hp, mp - 113, 6, p_e, r_e, 113, b_hp)},
19-
"P" => {(hp, mp - 173, s_e, 6, r_e, 173, b_hp)},
20-
_ => {(hp, mp - 229, s_e, p_e, 5, 229, b_hp)},
19+
if (bhp <= 0) {
20+
return m_spend;
21+
*m_spend_min = m_spend;
22+
}
23+
let (hp, mp, s_e, p_e, r_e, m_spend, b_hp) = match spell_id {
24+
"M" => {(hp, mp - 53, s_e, p_e, r_e, m_spend + 53, b_hp - 4)},
25+
"D" => {(hp + 2, mp - 73, s_e, p_e, r_e, m_spend + 73, b_hp - 2)},
26+
"S" => {(hp, mp - 113, 6, p_e, r_e, m_spend + 113, b_hp)},
27+
"P" => {(hp, mp - 173, s_e, 6, r_e, m_spend + 173, b_hp)},
28+
_ => {(hp, mp - 229, s_e, p_e, 5, m_spend + 229, b_hp)},
2129

2230
};
23-
0
31+
if hp - bdmg <= 0 {
32+
return 0;
33+
}
2434
}
2535

2636

0 commit comments

Comments
 (0)