Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Feb 23, 2021
1 parent e00de2e commit ea56552
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
39 changes: 21 additions & 18 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use iai::black_box;

use shakmaty::{perft, CastlingMode, Chess, Move, Position, Role, Square, Bitboard};
use shakmaty::san::{San, ParseSanError};
use shakmaty::fen::Fen;
use shakmaty::san::{ParseSanError, San};
use shakmaty::{perft, Bitboard, CastlingMode, Chess, Move, Position, Role, Square};

fn bench_shallow_perft() {
let pos = Chess::default();
Expand All @@ -20,7 +20,8 @@ fn bench_parse_san_move_complicated() -> Result<San, ParseSanError> {

fn bench_generate_moves() {
let fen = "rn1qkb1r/pbp2ppp/1p2p3/3n4/8/2N2NP1/PP1PPPBP/R1BQ1RK1 b kq -";
let pos: Chess = fen.parse::<Fen>()
let pos: Chess = fen
.parse::<Fen>()
.expect("valid fen")
.position(CastlingMode::Chess960)
.expect("legal position");
Expand All @@ -30,7 +31,8 @@ fn bench_generate_moves() {

fn bench_play_unchecked() -> Chess {
let fen = "rn1qkb1r/pbp2ppp/1p2p3/3n4/8/2N2NP1/PP1PPPBP/R1BQ1RK1 b kq -";
let pos: Chess = fen.parse::<Fen>()
let pos: Chess = fen
.parse::<Fen>()
.expect("valid fen")
.position(CastlingMode::Chess960)
.expect("legal position");
Expand All @@ -50,7 +52,8 @@ fn bench_play_unchecked() -> Chess {

fn bench_san_candidates() {
let fen = "r2q1rk1/pb1nbppp/5n2/1p2p3/3NP3/P1NB4/1P2QPPP/R1BR2K1 w - -";
let pos: Chess = fen.parse::<Fen>()
let pos: Chess = fen
.parse::<Fen>()
.expect("valid fen")
.position(CastlingMode::Chess960)
.expect("legal position");
Expand All @@ -60,22 +63,22 @@ fn bench_san_candidates() {
}

fn bench_play_sans() -> Chess {
let pgn = ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5",
"Na5", "Bb5+", "c6", "dxc6", "bxc6", "Ba4", "Ba6", "d3", "Bc5", "O-O",
"O-O", "Nc3", "Qc7", "Nge4", "Be7", "Nxf6+", "Bxf6", "Ne4", "Be7",
"Re1", "Rad8", "f3", "c5", "Be3", "c4", "Qc1", "cxd3", "cxd3", "Qb8",
"Nf2", "Bxd3", "Nxd3", "Rxd3", "Qc2", "Rxe3", "Rxe3", "Qb6", "Re1",
"Bc5", "Qe4", "f5", "Qxe5", "f4", "Qd5+", "Kh8", "Kh1", "Bxe3", "b3",
"Qd8", "Rd1", "Qxd5", "Rxd5", "Nb7", "b4", "Rd8", "Rxd8+", "Nxd8",
"Bd7", "Kg8", "a4", "Kf8", "g4", "Ke7", "Bf5", "h6", "h4", "Nf7", "h5",
"Nd6", "Bd3", "Ke6", "Kg2", "Kd5", "Kh3", "Nf7", "b5", "Bb6", "Kg2",
"Kc5", "Kf1", "Ne5", "Be2", "Kb4", "Bd1", "Nc4", "Ke2", "Ne3", "g5",
"hxg5", "Kd2", "Nxd1", "Kxd1", "Kxa4", "Kd2", "Kxb5", "Kd3", "a5",
"Ke4", "a4", "Kf5", "a3", "h6", "gxh6"];
let pgn = [
"e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5", "Na5", "Bb5+", "c6", "dxc6",
"bxc6", "Ba4", "Ba6", "d3", "Bc5", "O-O", "O-O", "Nc3", "Qc7", "Nge4", "Be7", "Nxf6+",
"Bxf6", "Ne4", "Be7", "Re1", "Rad8", "f3", "c5", "Be3", "c4", "Qc1", "cxd3", "cxd3", "Qb8",
"Nf2", "Bxd3", "Nxd3", "Rxd3", "Qc2", "Rxe3", "Rxe3", "Qb6", "Re1", "Bc5", "Qe4", "f5",
"Qxe5", "f4", "Qd5+", "Kh8", "Kh1", "Bxe3", "b3", "Qd8", "Rd1", "Qxd5", "Rxd5", "Nb7",
"b4", "Rd8", "Rxd8+", "Nxd8", "Bd7", "Kg8", "a4", "Kf8", "g4", "Ke7", "Bf5", "h6", "h4",
"Nf7", "h5", "Nd6", "Bd3", "Ke6", "Kg2", "Kd5", "Kh3", "Nf7", "b5", "Bb6", "Kg2", "Kc5",
"Kf1", "Ne5", "Be2", "Kb4", "Bd1", "Nc4", "Ke2", "Ne3", "g5", "hxg5", "Kd2", "Nxd1",
"Kxd1", "Kxa4", "Kd2", "Kxb5", "Kd3", "a5", "Ke4", "a4", "Kf5", "a3", "h6", "gxh6",
];

let mut pos = black_box(Chess::default());
for san in black_box(pgn).iter() {
let m = san.parse::<San>()
let m = san
.parse::<San>()
.expect("valid san")
.to_move(&pos)
.expect("legal move");
Expand Down
45 changes: 26 additions & 19 deletions tests/perft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use shakmaty::{CastlingMode, Chess, FromSetup, Position};
use shakmaty::variants::{Atomic, Antichess, Crazyhouse, RacingKings, Horde};
use shakmaty::fen::Fen;
use shakmaty::perft;
use shakmaty::variants::{Antichess, Atomic, Crazyhouse, Horde, RacingKings};
use shakmaty::{CastlingMode, Chess, FromSetup, Position};

use std::io::BufReader;
use std::io::prelude::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;

fn test_perft_file<P>(path: &str, node_limit: u64)
where
Expand All @@ -40,21 +40,28 @@ where

match slices.next() {
Some("epd") => {
pos = slices.next()
pos = slices
.next()
.expect("missing epd")
.parse::<Fen>()
.expect("invalid fen")
.position(CastlingMode::Chess960)
.expect("illegal fen");
},
}
Some("perft") => {
let mut params = slices.next().expect("missing perft params").splitn(2, ' ');

let depth = params.next().expect("missing perft depth")
.parse().expect("depth not an integer");
let depth = params
.next()
.expect("missing perft depth")
.parse()
.expect("depth not an integer");

let nodes = params.next().expect("missing perft nodes")
.parse().expect("nodes not an integer");
let nodes = params
.next()
.expect("missing perft nodes")
.parse()
.expect("nodes not an integer");

if nodes <= node_limit {
assert_eq!(perft(&pos, depth), nodes);
Expand All @@ -70,7 +77,7 @@ macro_rules! gen_tests {
($($fn_name:ident, $t:ty, $path:tt, $num:expr,)+) => {
$(
#[test]
#[cfg_attr(miri, ignore)]
#[cfg_attr(miri, ignore)]
fn $fn_name() {
test_perft_file::<$t>($path, $num);
}
Expand All @@ -79,12 +86,12 @@ macro_rules! gen_tests {
}

// generate tests
gen_tests! {
test_random, Chess, "tests/random.perft", 10_000 ,
test_tricky, Chess, "tests/tricky.perft", 100_000 ,
test_atomic, Atomic, "tests/atomic.perft", 1_000_000 ,
test_antichess, Antichess, "tests/antichess.perft", 1_000_000 ,
test_crazyhouse, Crazyhouse, "tests/crazyhouse.perft", 1_000_000 ,
test_racingkings, RacingKings, "tests/racingkings.perft", 1_000_000 ,
test_horde, Horde, "tests/horde.perft", 1_000_000 ,
gen_tests! {
test_random, Chess, "tests/random.perft", 10_000 ,
test_tricky, Chess, "tests/tricky.perft", 100_000 ,
test_atomic, Atomic, "tests/atomic.perft", 1_000_000 ,
test_antichess, Antichess, "tests/antichess.perft", 1_000_000 ,
test_crazyhouse, Crazyhouse, "tests/crazyhouse.perft", 1_000_000 ,
test_racingkings, RacingKings, "tests/racingkings.perft", 1_000_000 ,
test_horde, Horde, "tests/horde.perft", 1_000_000 ,
}

0 comments on commit ea56552

Please sign in to comment.