Skip to content

Commit

Permalink
Merge pull request #69 from sfleischman105/Beta-Branch
Browse files Browse the repository at this point in the history
Beta branch
  • Loading branch information
sfleischman105 committed Dec 28, 2017
2 parents 83d4af9 + dd34534 commit 1fd7d1b
Show file tree
Hide file tree
Showing 38 changed files with 1,242 additions and 641 deletions.
15 changes: 1 addition & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ cache:
- cargo
- apt


sudo: required

env:
Expand All @@ -30,22 +29,10 @@ addons:
os:
- linux


script:
- cargo build --verbose
- cargo test --verbose
- |
if [[ "$TRAVIS_RUST_VERSION" == nightly ]]
then
cargo bench
fi
- |
if [[ "$TRAVIS_RUST_VERSION" == stable ]]
then
cargo doc
fi
- cargo bench

after_success:
- |
Expand Down
16 changes: 5 additions & 11 deletions pleco/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "pleco"
# REMINDER TO CHANGE IN README
version = "0.2.3"
version = "0.3.0"
authors = ["Stephen Fleischman <stephenf@cs.washington.edu>"]
description = "A blazingly-fast chess engine and Chess AI."
description = "A blazingly-fast chess library."
homepage = "https://github.com/sfleischman105/Pleco"
documentation = "https://docs.rs/pleco/"
readme = "README.md"
Expand Down Expand Up @@ -72,10 +72,10 @@ doctest = true


[dependencies]
clippy = {version = "0.0.174", optional = true}
lazy_static = "0.2"
clippy = {version = "0.0.177", optional = true}
lazy_static = "1.0.0"
bitflags = "1.0.1"
rand = "0.3"
rand = "0.4.1"
rayon = "0.9.0"
num_cpus = "1.0"
failure = "0.1.1"
Expand All @@ -85,9 +85,3 @@ failure_derive = "0.1.1"
[features]
default = []
dev = ["clippy"]


#
#[[bench]]
#path = "benches/bench.rs"
#name = "integration_benches"
2 changes: 1 addition & 1 deletion pleco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To use Pleco inside your own Rust projects, [Pleco.rs is available as a library

```
[dependencies]
pleco = "0.2.3"
pleco = "0.3.0"
```

And add the following to a `main.rs` or `lib.rs`:
Expand Down
2 changes: 1 addition & 1 deletion pleco/benches/bot_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ fn _4_ply_jamboree(b: &mut Bencher) {
black_box(JamboreeSearcher::best_move_depth(board.shallow_clone(),4));
}
})
}
}
38 changes: 0 additions & 38 deletions pleco/benches/searcher_benches.rs

This file was deleted.

4 changes: 3 additions & 1 deletion pleco/src/board/board_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ use std::sync::Arc;
/// [`Board`]: ../struct.Board.html
#[derive(Clone)]
pub struct BoardState {
// The Following Fields are easily copied from the previous version and possbily modified
// The Following Fields are easily copied from the previous version and possibly modified
/// The castling rights for the current board.
pub castling: Castling,
/// Rule 50 for the current board. Tracks the moves since a capture, pawn move, or castle.
pub rule_50: i16,
pub ply: u16,
pub ep_square: SQ,
Expand Down
1 change: 1 addition & 0 deletions pleco/src/board/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub const PIECE_VALS: [i16; PIECE_CNT] = [


impl Eval {
/// Evaluates the score of a `Board` for the current side to move.
pub fn eval_low(board: &Board) -> i16 {
match board.turn() {
Player::White => eval_all::<WhiteType>(board) - eval_all::<BlackType>(board),
Expand Down
12 changes: 4 additions & 8 deletions pleco/src/board/fen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,10 @@ pub fn is_valid_fen(board: Board) -> Result<Board,FenBuildError> {
if piece_2 == Piece::B || piece_2 == Piece::N || piece_2 == Piece::P {
return Err(FenBuildError::IllegalCheckState {piece_1, piece_2});
}
} else if piece_1 == Piece::B {
if piece_2 == Piece::P || piece_2 == Piece::B {
return Err(FenBuildError::IllegalCheckState {piece_1, piece_2});
}
} else if piece_1 == Piece::N {
if piece_2 == Piece::P || piece_2 == Piece::N {
return Err(FenBuildError::IllegalCheckState { piece_1, piece_2 });
}
} else if piece_1 == Piece::B && (piece_2 == Piece::P || piece_2 == Piece::B) {
return Err(FenBuildError::IllegalCheckState {piece_1, piece_2});
} else if piece_1 == Piece::N && (piece_2 == Piece::P || piece_2 == Piece::N) {
return Err(FenBuildError::IllegalCheckState { piece_1, piece_2 });
}
}

Expand Down
20 changes: 10 additions & 10 deletions pleco/src/board/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl From<num::ParseIntError> for FenBuildError {
/// Square A1, bit 1 is B1, etc.). Indexes increase first horizontally by File, and then by Rank. See
/// [BitBoards article ChessWiki](https://chessprogramming.wikispaces.com/Bitboards) for more information.
///
/// The exact mapping from each square to bits is below,
/// The exact mapping from each square to bits is as follows:
///
/// ```md,ignore
/// 8 | 56 57 58 59 60 61 62 63
Expand Down Expand Up @@ -819,8 +819,8 @@ impl Board {
///
/// # Panics
///
/// Cannot be done if after a [Board::shallow_clone()] or [Board::parallel_clone()] has been done
/// and no subsequent moves have been played.
/// Cannot be done if after any `Board::shallow_clone()` has been applied,
/// or if `Board::parallel_clone()` has been done and there is no previous move.
///
/// # Examples
///
Expand Down Expand Up @@ -948,7 +948,7 @@ impl Board {
/// # Safety
///
/// This method should only be used if it can be guaranteed that the last played move from
/// the current state is a Null-Move. Otherwise, a panic will occur.
/// the current state is a Null-Move, eg `Board::apply_null_move()`. Otherwise, a panic will occur.
///
/// # Examples
///
Expand Down Expand Up @@ -1000,10 +1000,10 @@ impl Board {
MoveGen::generate::<PseudoLegal, AllGenType>(self)
}

/// Get a List of legal `BitMove`s for the player whose turn it is to move or a certain type.
/// Get a List of legal `BitMove`s for the player whose turn it is to move and of a certain type.
///
/// This method already takes into account if the Board is currently in check, and will return
/// legal moves only. If a non-ALL GenType is supplied, only a subset of the total moves will be given.
/// legal moves only. If a non-ALL `GenTypes` is supplied, only a subset of the total moves will be given.
///
/// # Panics
///
Expand Down Expand Up @@ -1302,7 +1302,7 @@ impl Board {
self.turn
}

/// Return the Zobrist Hash.
/// Return the Zobrist Hash of the board.
pub fn zobrist(&self) -> u64 {
self.state.zobrast
}
Expand Down Expand Up @@ -1551,7 +1551,7 @@ impl Board {
}

/// Returns the pinned pieces for a given players king. Can contain piece of from both players,
/// but all are garunteed to be pinned to the given player's king.
/// but all are guaranteed to be pinned to the given player's king.
pub fn all_pinned_pieces(&self, player: Player) -> BitBoard {
self.state.blockers_king[player as usize]
}
Expand Down Expand Up @@ -1691,12 +1691,12 @@ impl Board {
}

#[doc(hidden)]
pub fn pseudo_legal_move(&self, m: BitMove) -> bool {
pub fn pseudo_legal_move(&self, _m: BitMove) -> bool {
unimplemented!()
// TODO: create pseduo-legal-move
}

/// Returns if a move will give check to the opposing player's King.
/// Returns if a move gives check to the opposing player's King.
pub fn gives_check(&self, m: BitMove) -> bool {
// I am too drunk to be making this right now
let src: SQ = m.get_src();
Expand Down
2 changes: 1 addition & 1 deletion pleco/src/board/movegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ mod tests {
let b = Board::default();
let mut m = b.generate_moves();
let mut i = 0;
for d in m.iter() {
for _d in m.iter() {
i+= 1;
}
{
Expand Down
15 changes: 9 additions & 6 deletions pleco/src/board/pgn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ impl ChessRound {
let mut cr = ChessRound::default();
let args = round[1..(round.len() - 1)].split('.');
args.for_each(|r: &str| {
r.parse().map(|m: u32| cr.rounds.push(m));
// r.parse().map(|m: u32| cr.rounds.push(m));
if let Ok(m) = r.parse() {
cr.rounds.push(m)
}
});
cr
}
Expand Down Expand Up @@ -350,10 +353,10 @@ mod tests {

#[test]
fn tags_test() {
let mut m = PGNTags::default();
m = m.add(TEST_WHITE).unwrap();
m = m.add(TEST_BLACK).unwrap();
m = m.add(TEST_DATE).unwrap();
m = m.add(TEST_ROUND).unwrap();
PGNTags::default()
.add(TEST_WHITE).unwrap()
.add(TEST_BLACK).unwrap()
.add(TEST_DATE).unwrap()
.add(TEST_ROUND).unwrap();
}
}
4 changes: 2 additions & 2 deletions pleco/src/bots/alphabeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub fn alpha_beta_search(board: &mut Board, mut alpha: i16, beta: i16, max_depth

if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
} else {
return BestMove::new(-STALEMATE);
return BestMove::new_none(-STALEMATE);
}
}
let mut best_move: Option<BitMove> = None;
Expand Down
12 changes: 6 additions & 6 deletions pleco/src/bots/iterative_parallel_mvv_lva.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn iterative_deepening(board: Board, max_depth: u16) -> BitMove {
let mut beta: i16 = INFINITY;

// Create a dummy best_move
let mut best_move = BestMove::new(NEG_INFINITY);
let mut best_move = BestMove::new_none(NEG_INFINITY);

// Loop until max_depth is reached
while i <= max_depth {
Expand Down Expand Up @@ -86,9 +86,9 @@ fn jamboree(
let mut moves = board.generate_moves();
if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
} else {
return BestMove::new(STALEMATE);
return BestMove::new_none(STALEMATE);
}
}

Expand Down Expand Up @@ -212,9 +212,9 @@ fn alpha_beta_search(board: &mut Board, mut alpha: i16, beta: i16, max_depth: u1

if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
} else {
return BestMove::new(-STALEMATE);
return BestMove::new_none(-STALEMATE);
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ fn quiescence_search(board: &mut Board, mut alpha: i16, beta: i16, max_depth: u1

if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
}
return eval_board(board);
}
Expand Down
8 changes: 4 additions & 4 deletions pleco/src/bots/jamboree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub fn jamboree(board: &mut Board, mut alpha: i16, beta: i16,
let moves = board.generate_moves();
if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
} else {
return BestMove::new(STALEMATE);
return BestMove::new_none(STALEMATE);
}
}

Expand Down Expand Up @@ -143,9 +143,9 @@ fn alpha_beta_search(board: &mut Board, mut alpha: i16, beta: i16, max_depth: u1

if moves.is_empty() {
if board.in_check() {
return BestMove::new(MATE + (board.depth() as i16));
return BestMove::new_none(MATE + (board.depth() as i16));
} else {
return BestMove::new(-STALEMATE);
return BestMove::new_none(-STALEMATE);
}
}
let mut best_move: Option<BitMove> = None;
Expand Down

0 comments on commit 1fd7d1b

Please sign in to comment.