-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81a475d
commit ddb574a
Showing
1 changed file
with
62 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,86 @@ | ||
use mexx::ataxx::{Board, FEN, Move, Position, Square}; | ||
use std::str::FromStr; | ||
use std::{env, time}; | ||
use std::sync::Arc; | ||
use mexx::ataxx::zobrist::Hash; | ||
use std::str::FromStr; | ||
|
||
use mexx::ataxx::{Board, Hash}; | ||
|
||
#[derive(Copy, Clone)] | ||
struct TTEntry { | ||
hash: Hash, | ||
depth: u8, | ||
nodes: usize, | ||
hash: Hash, | ||
depth: u8, | ||
nodes: usize, | ||
} | ||
|
||
const ENTRIES: usize = 1000000;//174762666; | ||
|
||
struct Table { | ||
table: Vec<TTEntry> | ||
table: Vec<TTEntry>, | ||
} | ||
|
||
impl Table { | ||
fn get(&mut self, hash: Hash) -> &mut TTEntry { | ||
let length = self.table.len(); | ||
&mut self.table[hash.0 as usize % length] | ||
} | ||
fn get(&mut self, hash: Hash) -> &mut TTEntry { | ||
let length = self.table.len(); | ||
&mut self.table[hash.0 as usize % length] | ||
} | ||
} | ||
|
||
fn main() { | ||
let fen = FEN::from_str("x5o/7/7/7/7/7/o5x x 0 1").unwrap(); | ||
let mut board = Board::from(&fen); | ||
let mut board = Board::from_str("x5o/7/7/7/7/7/o5x x 0 1").unwrap(); | ||
|
||
println!("{}\n", board.current_pos()); | ||
println!("{}\n", board.position()); | ||
|
||
let mut tt = Table{table: vec![TTEntry{hash: Hash(0), depth: 0, nodes: 0}; ENTRIES]}; | ||
let mut tt = Table { table: vec![TTEntry { hash: Hash(0), depth: 0, nodes: 0 }; ENTRIES] }; | ||
|
||
let depth = env::args().nth(1).unwrap(); | ||
let depth = depth.parse::<u8>().unwrap(); | ||
let depth = env::args().nth(1).unwrap(); | ||
let depth = depth.parse::<u8>().unwrap(); | ||
|
||
let start = time::Instant::now(); | ||
let nodes = perft::<false, true>(&mut board, depth, &mut tt); | ||
let duration = start.elapsed(); | ||
let start = time::Instant::now(); | ||
let nodes = perft::<true, true>(&mut board, depth, &mut tt); | ||
let duration = start.elapsed(); | ||
|
||
println!("nodes {} time {} nps {}", nodes, duration.as_millis(), (nodes as u128/duration.as_millis().max(1))*1000); | ||
println!("nodes {} time {} nps {}", nodes, duration.as_millis(), (nodes as u128 / duration.as_millis().max(1)) * 1000); | ||
} | ||
|
||
fn perft<const BULK: bool, const SPLIT: bool>(board: &mut Board, depth: u8, tt: &mut Table) -> usize { | ||
if BULK && depth == 1 { | ||
return board.count_moves(); | ||
} | ||
|
||
if depth == 0 { | ||
return 1; | ||
} | ||
|
||
let mut nodes: usize = 0; | ||
let movelist = board.generate_moves(); | ||
|
||
for m in movelist.iter() { | ||
board.make_move(m); | ||
// let hash = board.zobrist_hash(); | ||
// let entry = tt.get(hash); | ||
// | ||
let new_nodes = //if entry.hash == hash && entry.depth == depth { | ||
// entry.nodes | ||
// } else { | ||
perft::<BULK, false>(board, depth-1, tt) | ||
// } | ||
; | ||
|
||
board.undo_move(); | ||
|
||
if SPLIT { | ||
println!("{}: {}", m, new_nodes); | ||
} | ||
|
||
nodes += new_nodes; | ||
|
||
// let entry = tt.get(hash); | ||
// if depth >= 7 || entry.depth < depth { | ||
// *entry = TTEntry { | ||
// hash, | ||
// depth, | ||
// nodes: new_nodes, | ||
// } | ||
// } | ||
} | ||
|
||
nodes | ||
if BULK && depth == 1 { | ||
return board.count_moves(); | ||
} | ||
|
||
if depth == 0 { | ||
return 1; | ||
} | ||
|
||
let mut nodes: usize = 0; | ||
let movelist = board.generate_moves(); | ||
|
||
for m in movelist.iter() { | ||
board.make_move(m); | ||
let hash = board.checksum(); | ||
let entry = tt.get(hash); | ||
|
||
let new_nodes = if entry.hash == hash && entry.depth == depth { | ||
entry.nodes | ||
} else { | ||
perft::<BULK, false>(board, depth - 1, tt) | ||
} | ||
; | ||
|
||
board.undo_move(); | ||
|
||
if SPLIT { | ||
println!("{}: {}", m, new_nodes); | ||
} | ||
|
||
nodes += new_nodes; | ||
|
||
let entry = tt.get(hash); | ||
if depth >= 7 || entry.depth < depth { | ||
*entry = TTEntry { | ||
hash, | ||
depth, | ||
nodes: new_nodes, | ||
} | ||
} | ||
} | ||
|
||
nodes | ||
} |