some changes
This commit is contained in:
parent
81c08f5407
commit
dafe585f0c
155
Cargo.lock
generated
155
Cargo.lock
generated
@ -32,6 +32,12 @@ dependencies = [
|
|||||||
"wyz",
|
"wyz",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@ -44,12 +50,31 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console"
|
||||||
|
version = "0.15.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b"
|
||||||
|
dependencies = [
|
||||||
|
"encode_unicode",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"unicode-width",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "encode_unicode"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "funty"
|
name = "funty"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -68,6 +93,29 @@ dependencies = [
|
|||||||
"windows-targets",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indicatif"
|
||||||
|
version = "0.17.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
|
||||||
|
dependencies = [
|
||||||
|
"console",
|
||||||
|
"number_prefix",
|
||||||
|
"portable-atomic",
|
||||||
|
"unicode-width",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.77"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@ -80,6 +128,12 @@ version = "0.2.169"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num"
|
name = "num"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
@ -153,6 +207,18 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_prefix"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "othello"
|
name = "othello"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -160,12 +226,19 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"either",
|
"either",
|
||||||
|
"indicatif",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"num",
|
"num",
|
||||||
"rand",
|
"rand",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.20"
|
version = "0.2.20"
|
||||||
@ -259,6 +332,12 @@ version = "1.0.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.13.3+wasi-0.2.2"
|
version = "0.13.3+wasi-0.2.2"
|
||||||
@ -268,6 +347,82 @@ dependencies = [
|
|||||||
"wit-bindgen-rt",
|
"wit-bindgen-rt",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-time"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
|
|||||||
@ -11,6 +11,7 @@ debug = true
|
|||||||
arrayvec = "0.7"
|
arrayvec = "0.7"
|
||||||
bitvec = "1.0.1"
|
bitvec = "1.0.1"
|
||||||
either = "1.13"
|
either = "1.13"
|
||||||
|
indicatif = "0.17.11"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
num = "0.4"
|
num = "0.4"
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
|
|||||||
@ -25,8 +25,7 @@ impl BitBoard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, row: usize, col: usize, value: bool) {
|
pub fn set(&mut self, row: usize, col: usize, value: bool) {
|
||||||
let index = Self::get_index(row, col);
|
self.0.set(Self::get_index(row, col), value);
|
||||||
self.0.set(index, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn count(&self) -> usize {
|
pub fn count(&self) -> usize {
|
||||||
|
|||||||
52
src/board.rs
52
src/board.rs
@ -190,7 +190,7 @@ impl Board {
|
|||||||
|
|
||||||
/// Returns a bool which represents whether or not a move would propegate and be valid
|
/// Returns a bool which represents whether or not a move would propegate and be valid
|
||||||
pub fn would_prop(&self, i: usize, j: usize, piece: Piece) -> bool {
|
pub fn would_prop(&self, i: usize, j: usize, piece: Piece) -> bool {
|
||||||
self.get(i, j).is_none() && !self.propegate_from_dry(i, j, piece).is_empty()
|
self.get(i, j).is_none() && self.propegate_from_dry(i, j, piece).next().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn place(&mut self, i: usize, j: usize, piece: Piece) -> Result<(), &'static str> {
|
pub fn place(&mut self, i: usize, j: usize, piece: Piece) -> Result<(), &'static str> {
|
||||||
@ -207,7 +207,7 @@ impl Board {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
let pos_s = self.propegate_from_dry(i, j, starting_color);
|
let pos_s: Vec<(usize, usize)> = self.propegate_from_dry(i, j, starting_color).collect();
|
||||||
let pos_len = pos_s.len();
|
let pos_len = pos_s.len();
|
||||||
for (i, j) in pos_s {
|
for (i, j) in pos_s {
|
||||||
self.place_unchecked(i, j, starting_color);
|
self.place_unchecked(i, j, starting_color);
|
||||||
@ -219,40 +219,36 @@ impl Board {
|
|||||||
/// Propegate piece captures originating from (i, j)
|
/// Propegate piece captures originating from (i, j)
|
||||||
/// DO NOT USE THIS ALONE, this should be called as a part of
|
/// DO NOT USE THIS ALONE, this should be called as a part of
|
||||||
/// [`Board::place`] or [`Board::place_and_prop_unchecked`]
|
/// [`Board::place`] or [`Board::place_and_prop_unchecked`]
|
||||||
fn propegate_from_dry(&self, i: usize, j: usize, starting_color: Piece) -> Vec<(usize, usize)> {
|
fn propegate_from_dry(
|
||||||
// Longest chain is (BOARD_SIZE - 2) as there needs to be the two pieces containing it
|
&self,
|
||||||
let mut fill: Vec<(usize, usize)> = Vec::with_capacity((BOARD_SIZE - 2) * 8);
|
i: usize,
|
||||||
|
j: usize,
|
||||||
for chain in &ADJ_LOOKUP[i][j] {
|
starting_color: Piece,
|
||||||
for (chain_length, &(new_i, new_j)) in chain.iter().enumerate() {
|
) -> impl Iterator<Item = (usize, usize)> + use<'_> {
|
||||||
let Some(piece) = self.get(new_i, new_j) else {
|
ADJ_LOOKUP[i][j]
|
||||||
// chain interupted by blank space
|
.iter()
|
||||||
break;
|
.filter_map(move |chain| {
|
||||||
};
|
let mut end_idx = None;
|
||||||
|
for (idx, &(new_i, new_j)) in chain.iter().enumerate() {
|
||||||
if piece == starting_color {
|
let piece = self.get(new_i, new_j)?;
|
||||||
// Chain is only ever added to `fill` if it is completed
|
if piece == starting_color {
|
||||||
|
end_idx = Some(idx);
|
||||||
if let Some(history) = chain.get(..chain_length) {
|
break;
|
||||||
// fill all opposite colors with this color
|
|
||||||
fill.extend(history);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// either the other pieces were replaced, or this was an invalid chain,
|
|
||||||
// in both cases, the loop needs to be broken
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
end_idx.map(|idx| &chain[..idx])
|
||||||
}
|
})
|
||||||
fill
|
.flatten()
|
||||||
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count the number of a type of [`Piece`] on the board
|
/// Count the number of a type of [`Piece`] on the board
|
||||||
pub fn count(&self, piece: Piece) -> usize {
|
pub fn count(&self, piece: Piece) -> usize {
|
||||||
match piece {
|
match piece {
|
||||||
Piece::Black => self.black_board.count(),
|
Piece::Black => self.black_board,
|
||||||
Piece::White => self.white_board.count(),
|
Piece::White => self.white_board,
|
||||||
}
|
}
|
||||||
|
.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns (White score, Black score)
|
/// Returns (White score, Black score)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use either::Either;
|
use either::Either;
|
||||||
|
use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
|
||||||
|
|
||||||
use crate::{agent::Agent, board::Board, piece::Piece};
|
use crate::{agent::Agent, board::Board, piece::Piece};
|
||||||
|
|
||||||
@ -92,16 +93,21 @@ impl FutureMoves {
|
|||||||
if self.arena.len() >= self.max_arena {
|
if self.arena.len() >= self.max_arena {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
next_nodes = next_nodes
|
let arena_len = self.arena.len();
|
||||||
.into_iter()
|
next_nodes =
|
||||||
.flat_map(|node_idx| {
|
next_nodes
|
||||||
self.generate_children(
|
.into_iter()
|
||||||
Some(node_idx),
|
.flat_map(|node_idx| {
|
||||||
&self.arena[node_idx].board.clone(),
|
self.generate_children(
|
||||||
next_color,
|
Some(node_idx),
|
||||||
)
|
&self.arena[node_idx].board.clone(),
|
||||||
})
|
next_color,
|
||||||
.collect();
|
)
|
||||||
|
})
|
||||||
|
.progress_with(ProgressBar::new(arena_len as u64).with_style(
|
||||||
|
ProgressStyle::with_template("({pos}/{len}) {per_sec}").unwrap(),
|
||||||
|
))
|
||||||
|
.collect();
|
||||||
next_color = !next_color;
|
next_color = !next_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,8 +283,8 @@ pub struct ComplexAgent {
|
|||||||
|
|
||||||
impl ComplexAgent {
|
impl ComplexAgent {
|
||||||
pub const fn new(color: Piece) -> Self {
|
pub const fn new(color: Piece) -> Self {
|
||||||
const MAX_DEPTH: usize = 8;
|
const MAX_DEPTH: usize = 10;
|
||||||
const MAX_ARENA: usize = 20_000_000;
|
const MAX_ARENA: usize = 100_000_000;
|
||||||
Self {
|
Self {
|
||||||
color,
|
color,
|
||||||
future_moves: FutureMoves::new(color, MAX_DEPTH, MAX_ARENA),
|
future_moves: FutureMoves::new(color, MAX_DEPTH, MAX_ARENA),
|
||||||
|
|||||||
@ -12,8 +12,8 @@ mod piece;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let player1 = complexagent::ComplexAgent::new(Piece::Black);
|
let player1 = complexagent::ComplexAgent::new(Piece::Black);
|
||||||
// let player2 = complexagent::ComplexAgent::new(Piece::White);
|
// let player2 = complexagent::ComplexAgent::new(Piece::White);
|
||||||
let player2 = agent::ManualAgent::new(Piece::White);
|
// let player2 = agent::ManualAgent::new(Piece::White);
|
||||||
// let player2 = agent::RandomAgent::new(Piece::White);
|
let player2 = agent::RandomAgent::new(Piece::White);
|
||||||
let mut game = Game::new(Box::new(player1), Box::new(player2));
|
let mut game = Game::new(Box::new(player1), Box::new(player2));
|
||||||
game.game_loop();
|
game.game_loop();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user