summaryrefslogtreecommitdiff
path: root/src/json.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-05-26 00:28:28 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-05-26 00:28:28 +0200
commitd37be51f196eebdb8df57c87e8ab5bb684e1dcd9 (patch)
tree9625bf847698fd4072682839ede1f917c74bebbd /src/json.rs
parent7b3fe83b4bdb943d3d44ed036150d017279cfe05 (diff)
Score based MCTS
Diffstat (limited to 'src/json.rs')
-rw-r--r--src/json.rs58
1 files changed, 2 insertions, 56 deletions
diff --git a/src/json.rs b/src/json.rs
index 3cd603c..09095b0 100644
--- a/src/json.rs
+++ b/src/json.rs
@@ -39,7 +39,7 @@ pub struct Player {
impl Player {
pub fn health_score(&self) -> i32 {
- self.health / self.worms.len() as i32
+ self.health / 3
}
}
@@ -155,37 +155,11 @@ impl State {
self.my_player
.worms
.iter()
+ .filter(|w| w.health > 0)
.position(|w| w.id == self.current_worm_id)
}
}
-impl Position {
- pub fn west(&self, distance: i8) -> Option<Position> {
- self.x
- .checked_sub(distance)
- .filter(|&x| x >= 0)
- .map(|x| Position { x, y: self.y })
- }
- pub fn east(&self, distance: i8, max: i8) -> Option<Position> {
- self.x
- .checked_add(distance)
- .filter(|&x| x < max)
- .map(|x| Position { x, y: self.y })
- }
- pub fn north(&self, distance: i8) -> Option<Position> {
- self.y
- .checked_sub(distance)
- .filter(|&y| y >= 0)
- .map(|y| Position { x: self.x, y })
- }
- pub fn south(&self, distance: i8, max: i8) -> Option<Position> {
- self.y
- .checked_add(distance)
- .filter(|&y| y < max)
- .map(|y| Position { x: self.x, y })
- }
-}
-
#[cfg(test)]
mod test {
use super::*;
@@ -418,32 +392,4 @@ mod test {
parsed, expected
);
}
-
- #[test]
- fn west_moving_stays_in_bounds() {
- let pos = Position { x: 1, y: 1 };
- assert_eq!(pos.west(1), Some(Position { x: 0, y: 1 }));
- assert_eq!(pos.west(2), None);
- }
-
- #[test]
- fn east_moving_stays_in_bounds() {
- let pos = Position { x: 1, y: 1 };
- assert_eq!(pos.east(1, 3), Some(Position { x: 2, y: 1 }));
- assert_eq!(pos.east(2, 3), None);
- }
-
- #[test]
- fn north_moving_stays_in_bounds() {
- let pos = Position { x: 1, y: 1 };
- assert_eq!(pos.north(1), Some(Position { x: 1, y: 0 }));
- assert_eq!(pos.north(2), None);
- }
-
- #[test]
- fn south_moving_stays_in_bounds() {
- let pos = Position { x: 1, y: 1 };
- assert_eq!(pos.south(1, 3), Some(Position { x: 1, y: 2 }));
- assert_eq!(pos.south(2, 3), None);
- }
}