swap reveals i need a better targeting

This commit is contained in:
Bel LaPointe
2025-03-20 20:34:25 -06:00
parent 6007c2f2ed
commit f493a5e98c

View File

@@ -104,6 +104,14 @@ pub mod mon {
damage: 0,
}
}
pub fn hit(&mut self, damage: i32) {
let cap = self.dex.new().hp;
self.damage = match self.damage + damage {
v if v < cap => v,
_ => cap,
};
}
}
#[cfg(test)]
@@ -160,11 +168,18 @@ pub mod battle {
}
}
}
Move::Swap(to_idx) => {
todo!("not impl");
}
};
});
self.new_turn();
}
pub fn teams(&self) -> Vec<Team> {
self.teams.iter().map(|t| t.clone()).collect()
}
fn new_turn(&mut self) {
self.q = vec![];
}
@@ -176,6 +191,7 @@ pub mod battle {
i,
match &self.q[i] {
Move::Pass(_) => 0,
Move::Swap(_) => -10,
Move::Attack(w, _) => self.teams[w.team].mons[w.mon].mon.dex.new().spd,
},
));
@@ -194,10 +210,7 @@ pub mod battle {
v => v,
};
w.damage = match w.damage + power {
v if v < w.dex.new().hp => v,
_ => w.dex.new().hp,
};
w.hit(power);
w
}
@@ -263,8 +276,8 @@ pub mod battle {
}
}
#[derive(Debug)]
struct Team {
#[derive(Clone, Debug)]
pub struct Team {
mons: Vec<Instance>,
}
@@ -284,7 +297,7 @@ pub mod battle {
}
#[derive(Clone, Debug)]
struct Instance {
pub struct Instance {
mon: mon::Instance,
out: bool,
}
@@ -333,5 +346,47 @@ pub mod battle {
pub enum Move {
Pass(Idx),
Attack(Idx, Idx),
Swap(Idx),
}
}
#[cfg(test)]
mod mon_tests {
use super::*;
#[test]
fn test() {
let mut my_mons = vec![
mon::Instance::roll(mon::Dex::Pika),
mon::Instance::roll(mon::Dex::Mari),
];
my_mons[0].hit(5);
let they_mons = vec![
mon::Instance::roll(mon::Dex::Mari),
mon::Instance::roll(mon::Dex::Mari),
mon::Instance::roll(mon::Dex::Mari),
];
let mut engine = battle::Engine::new(my_mons, they_mons);
engine.enqueue(battle::Move::Attack(
battle::Idx { team: 1, mon: 0 },
battle::Idx { team: 0, mon: 0 },
));
engine.enqueue(battle::Move::Attack(
battle::Idx { team: 0, mon: 0 },
battle::Idx { team: 1, mon: 0 },
));
engine.exec();
engine.enqueue(battle::Move::Attack(
battle::Idx { team: 1, mon: 0 },
battle::Idx { team: 0, mon: 0 },
));
engine.enqueue(battle::Move::Swap(battle::Idx { team: 0, mon: 1 }));
engine.exec();
eprintln!("{:?}", engine.teams()[0]);
eprintln!("{:?}", engine.teams()[1]);
}
}