From f493a5e98c3be140c927dda1787c319dba4a153f Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:34:25 -0600 Subject: [PATCH] swap reveals i need a better targeting --- src/purerust/src/src.rs | 69 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/src/purerust/src/src.rs b/src/purerust/src/src.rs index 757d6bd..a9fc4e3 100755 --- a/src/purerust/src/src.rs +++ b/src/purerust/src/src.rs @@ -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 { + 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, } @@ -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]); } }