From 07defabce40bbb5f3b092b44c5c69a3a4130a8c0 Mon Sep 17 00:00:00 2001 From: SilverEmber Date: Sat, 1 Jan 2022 17:59:27 +1100 Subject: [PATCH] tested traditional chess knight movement --- src/apr.rs | 17 +++++++++++++++++ src/behaviour.rs | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/apr.rs b/src/apr.rs index 64fc13b..6396fbc 100644 --- a/src/apr.rs +++ b/src/apr.rs @@ -58,6 +58,14 @@ impl Apr { vec![(1, -1), (-1, -1)], )); } + for i in 0..=1 { + // white side knights + actors.push(actor::Actor::new(_ctx, "/pawn.png", i, 0, 0)); + behaviours.push(behaviour::Behaviour::new( + vec![(1, 2)], + vec![(1, -1), (-1, -1)], + )); + } for i in 0..r { // black side pawns actors.push(actor::Actor::new(_ctx, "/pawn2.png", i, c - 2, 0)); @@ -66,6 +74,15 @@ impl Apr { vec![(1, 1), (-1, 1)], )); } + for i in 0..=1 { + // black side knights + actors.push(actor::Actor::new(_ctx, "/pawn2.png", i, c - 1, 0)); + behaviours.push(behaviour::Behaviour::new( + vec![(1, 2)], + vec![(1, 1), (-1, 1)], + )); + } + Ok(Apr { grid: make_grid(_ctx, r, c, board.board.as_slice())?, board, diff --git a/src/behaviour.rs b/src/behaviour.rs index 291fba1..b4dc9af 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -10,14 +10,14 @@ impl Behaviour { pub fn validate_dest(&self, origin: (u8, u8), destination: (u8, u8)) -> bool { // original plan was to use match but i felt for loops would work better since we dont yet know the extent of moves vector - // println!("origin: ({}, {}), destination: ({}, {})", origin.0, origin.1, destination.0, destination.1); + // println!("origin: ({}, {}), destination: ({}, {})",origin.0, origin.1, destination.0, destination.1); for moveset in self.moves.iter() { for dir in self.dirs.iter() { // mind blanking need to add something to confirm which direction we are iterating through - // println!("Permissible: ({}, {})", (origin.0 as i8) + dir.0 * moveset.0,(origin.1 as i8) - dir.1 * moveset.1); + // println!("Permissible: ({}, {})",(origin.0 as i8) + dir.0 * moveset.0,(origin.1 as i8) - dir.1 * moveset.1); if ( - ((origin.0 as i8) + dir.0 * moveset.0) as u8, - ((origin.1 as i8) - dir.1 * moveset.1) as u8, + ((origin.0 as i8) + moveset.0 * dir.0) as u8, + ((origin.1 as i8) - moveset.1 * dir.1) as u8, ) == destination { return true;