summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-07-07 12:10:42 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-07-07 12:10:42 +0200
commit352ad4a297511dfe843bad5206879983ad34f3e2 (patch)
tree5e77aa34ea23b9080eaee4885ff1129c4249aec8
parentd385199c48d565d9ffc8948f137d716e534d5d0d (diff)
Cleaned up dead code
-rw-r--r--Cargo.lock145
-rw-r--r--Cargo.toml7
-rw-r--r--src/bin/benchmark.rs10
-rw-r--r--src/main.rs4
-rw-r--r--src/strategy.rs46
5 files changed, 12 insertions, 200 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 061d44e..165a251 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,34 +9,11 @@ dependencies = [
]
[[package]]
-name = "autocfg"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "bitflags"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "cloudabi"
-version = "0.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "fnv"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "fuchsia-cprng"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "itoa"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -73,110 +50,6 @@ dependencies = [
]
[[package]]
-name = "rand"
-version = "0.6.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "rand_hc"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_isaac"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_jitter"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_os"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_pcg"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rand_xorshift"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "rdrand"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "redox_syscall"
version = "0.1.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -216,12 +89,11 @@ dependencies = [
[[package]]
name = "steam-powered-wyrm"
-version = "0.1.0"
+version = "0.2.0"
dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -273,28 +145,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
-"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
-"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
-"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
-"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
-"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
-"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
-"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
-"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
-"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
-"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
-"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832"
-"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
-"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
-"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
-"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4"
diff --git a/Cargo.toml b/Cargo.toml
index 860129e..ae7d46e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,12 +1,11 @@
[package]
name = "steam-powered-wyrm"
-version = "0.1.0"
+version = "0.2.0"
edition = "2018"
[dependencies]
serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0.39"
-rand = "0.6.5"
time = "0.1.42"
num-traits = "0.2.6"
arrayvec = "0.4.10"
@@ -14,5 +13,5 @@ fnv = "1.0.6"
[profile.release]
debug = true
-# debug-assertions = true
-# overflow-checks = true \ No newline at end of file
+debug-assertions = true
+overflow-checks = true \ No newline at end of file
diff --git a/src/bin/benchmark.rs b/src/bin/benchmark.rs
index 098192c..0cee8d6 100644
--- a/src/bin/benchmark.rs
+++ b/src/bin/benchmark.rs
@@ -2,19 +2,19 @@ use std::path::Path;
use time::{Duration, PreciseTime};
-use steam_powered_wyrm::strategy::choose_move;
-use steam_powered_wyrm::json;
use steam_powered_wyrm::game;
+use steam_powered_wyrm::json;
+use steam_powered_wyrm::strategy::choose_move;
fn main() {
let max_time = Duration::milliseconds(19950);
let start_time = PreciseTime::now();
-
+
match json::read_state_from_json_file(&Path::new(&format!("./tests/example-state.json"))) {
Ok(json_state) => {
let new_board = game::GameBoard::new(json_state);
- let _ = choose_move(&new_board, None, &start_time, max_time);
- },
+ let _ = choose_move(&new_board, None, start_time, max_time);
+ }
Err(e) => {
eprintln!("WARN: State file could not be parsed: {}", e);
}
diff --git a/src/main.rs b/src/main.rs
index 00b96cf..280df8a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,7 @@ fn main() {
None => {
let new_board = game::GameBoard::new(json_state);
let (command, cache) =
- choose_move(&new_board, strategy_cache, &start_time, max_time);
+ choose_move(&new_board, strategy_cache, start_time, max_time);
strategy_cache = Some(cache);
game_board = Some(new_board);
command
@@ -34,7 +34,7 @@ fn main() {
Some(game_board) => {
game_board.update(json_state);
let (command, cache) =
- choose_move(&game_board, strategy_cache, &start_time, max_time);
+ choose_move(&game_board, strategy_cache, start_time, max_time);
strategy_cache = Some(cache);
command
}
diff --git a/src/strategy.rs b/src/strategy.rs
index 036a620..0c86eeb 100644
--- a/src/strategy.rs
+++ b/src/strategy.rs
@@ -6,13 +6,10 @@ use std::collections::HashMap;
use std::ops::*;
use time::{Duration, PreciseTime};
-use rand;
-use rand::prelude::*;
-
pub fn choose_move(
state: &GameBoard,
previous_root: Option<Node>,
- start_time: &PreciseTime,
+ start_time: PreciseTime,
max_time: Duration,
) -> (Command, Node) {
let mut root_node = match previous_root {
@@ -205,28 +202,6 @@ fn rollout(state: &GameBoard) -> Score {
score(state)
}
-// fn rollout(state: &GameBoard) -> Score {
-// let mut s = state.clone();
-// let mut rng = rand::thread_rng();
-// while s.outcome == SimulationOutcome::Continue {
-// let player_moves = rollout_moves(&s, 0);
-// let opponent_moves = rollout_moves(&s, 1);
-
-// s.simulate([
-// player_moves
-// .choose(&mut rng)
-// .cloned()
-// .unwrap_or_else(|| Command::new(Action::DoNothing)),
-// opponent_moves
-// .choose(&mut rng)
-// .cloned()
-// .unwrap_or_else(|| Command::new(Action::DoNothing)),
-// ]);
-// }
-
-// score(&s)
-// }
-
fn choose_existing(node: &Node) -> [Command; 2] {
[choose_one_existing(node, 0), choose_one_existing(node, 1)]
}
@@ -255,25 +230,6 @@ fn update(node: &mut Node, commands: [Command; 2], score: Score) {
node.score_sum += score;
}
-fn rollout_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
- // TODO: Have this return one move, chosen randomly?
- // TODO: Heuristic based move
- valid_moves(state, player_index)
- //
- // if let Some(worm) = state.players[player_index].active_worm() {
-
- // let shoots = state.sensible_shoot_commands(player_index, worm.position, worm.weapon_range);
-
- // if !shoots.is_empty() {
- // return shoots.into_iter().collect();
- // }
-
- // state.valid_move_commands(player_index).into_iter().collect()
- // } else {
- // [Command::new(Action::DoNothing)].into_iter().cloned().collect()
- // }
-}
-
fn valid_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
state
.valid_shoot_commands(player_index)