summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-09-02 09:29:14 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-09-02 09:29:14 +0200
commitc405ac9bd5b6e34fca1d743949992b605a15d13e (patch)
treef8fb68233f7a2f00a5bc966396f6961fb3636a86 /src
parentdafb9cf03cc5e8ad0a2b2d1857bb635d237f47b0 (diff)
Clippy suggested improvements
Diffstat (limited to 'src')
-rw-r--r--src/engine/command.rs4
-rw-r--r--src/engine/geometry.rs6
-rw-r--r--src/input/json.rs2
-rw-r--r--src/strategy/monte_carlo.rs10
4 files changed, 11 insertions, 11 deletions
diff --git a/src/engine/command.rs b/src/engine/command.rs
index b34553f..76cfaee 100644
--- a/src/engine/command.rs
+++ b/src/engine/command.rs
@@ -20,7 +20,7 @@ impl fmt::Display for Command {
}
impl Command {
- pub fn cant_build_yet(&self, energy: u16) -> bool {
+ pub fn cant_build_yet(self, energy: u16) -> bool {
use self::Command::*;
match self {
@@ -52,7 +52,7 @@ impl BuildingType {
if id <= 4 && id != 3 { Some(unsafe { mem::transmute(id) }) } else { None }
}
- pub fn cant_build_yet(&self, energy: u16) -> bool {
+ pub fn cant_build_yet(self, energy: u16) -> bool {
use self::BuildingType::*;
let required = match self {
diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs
index b9b556a..b8b38dd 100644
--- a/src/engine/geometry.rs
+++ b/src/engine/geometry.rs
@@ -32,11 +32,11 @@ impl Point {
}
}
- pub fn x(&self) -> u8 {
+ pub fn x(self) -> u8 {
self.index % SINGLE_MAP_WIDTH
}
- pub fn y(&self) -> u8 {
+ pub fn y(self) -> u8 {
self.index / SINGLE_MAP_WIDTH
}
}
@@ -51,7 +51,7 @@ impl Point {
* This involves mirroring the x dimension for the opponent's side
*/
- pub fn to_either_bitfield(&self) -> u64 {
+ pub fn to_either_bitfield(self) -> u64 {
1u64 << self.index
}
}
diff --git a/src/input/json.rs b/src/input/json.rs
index 843f228..4e10f9a 100644
--- a/src/input/json.rs
+++ b/src/input/json.rs
@@ -127,7 +127,7 @@ impl State {
&mut opponent
};
- for mut tier in bitwise_buildings.missiles.iter_mut() {
+ for mut tier in &mut bitwise_buildings.missiles {
let setting = (!tier.0 & left, !tier.1 & right);
tier.0 |= setting.0;
tier.1 |= setting.1;
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 347af96..0587e31 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -58,11 +58,11 @@ pub fn choose_move(state: &BitwiseGameState, start_time: PreciseTime, max_time:
println!("NOTHING");
println!("{}", command_scores.iter().find(|c| c.command == Command::Nothing).map(|s| s.win_ratio()).unwrap_or(0));
- println!("");
+ println!();
println!("IRON CURTAIN");
println!("{}", command_scores.iter().find(|c| c.command == Command::IronCurtain).map(|s| s.win_ratio()).unwrap_or(0));
- println!("");
+ println!();
}
command
@@ -83,7 +83,7 @@ fn debug_print_choices<F: FnMut(&CommandScore) -> Option<(Point, i32)>>(label: &
}
println!(" |");
}
- println!("");
+ println!();
}
#[cfg(not(feature = "discard-poor-performers"))]
@@ -174,7 +174,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
let mut m = [Command::Nothing; NUMBER_OF_POSSIBLE_MOVES];
m[1] = Command::IronCurtain;
let mut i = 2;
- for b in [BuildingType::Energy, BuildingType::Defence, BuildingType::Attack, BuildingType::Tesla].iter() {
+ for b in &[BuildingType::Energy, BuildingType::Defence, BuildingType::Attack, BuildingType::Tesla] {
for p in 0..NUMBER_OF_MAP_POSITIONS as u8 {
let point = Point::new_index(p);
m[i] = Command::Build(point, *b);
@@ -284,7 +284,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
// TODO can this be a more efficient lookup?
let index = cdf.iter().position(|&c| c > choice).expect("Random number has exceeded cumulative distribution");
- MOVES[index].clone()
+ MOVES[index]
}
#[cfg(not(feature = "heuristic-random"))]