Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring + Cleanups #123

Merged
merged 7 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 22 additions & 40 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ language: rust

rust:
- nightly

- stable

cache:
- cargo
- apt
# cache:
# directories:
# - $HOME/.cache/pip

sudo: required
sudo: false

env:
global:
Expand All @@ -20,42 +17,27 @@ env:
- RUST_MIN_STACK=8000000
# - RUST_TEST_THREADS=1


#addons:
# apt:
# packages:
# - libcurl4-openssl-dev
# - libelf-dev
# - libdw-dev
# - binutils-dev
# - cmake
# sources:
# - kalakris-cmake


before_script:
- rustup install stable-x86_64-unknown-linux-gnu

os:
- linux

script:
- cargo build --verbose
- echo " ------ TESTING STABLE BRANCH ------- "
- cargo +stable test --package pleco
- cargo +stable bench --package pleco
- echo " ------ TESTING NIGHTLY BRANCH ------- "
- cargo test --verbose
- cargo bench
# - cd pleco/ && cargo bench
# - cd ../pleco_engine/ && cargo bench --bench eval_benches

#after_success:
# - |
# if [[ "$TRAVIS_BRANCH" = "master" ]] AND [ "$TRAVIS_PULL_REQUEST" = "false" ]
# then
# cargo install cargo-travis || echo "cargo-travis has been already installed"
# export PATH=$HOME/.cargo/bin:$PATH
# cargo coveralls
# fi
#
- if [ "$TRAVIS_RUST_VERSION" == "stable" ];
then
cargo build --verbose --package pleco;
cargo test --package pleco;
cargo bench --package pleco;
else
cargo build --verbose;
cargo test;
cargo bench --package pleco --all-features;
cargo bench --package pleco_engine --all-features;
fi

# - cargo build --verbose
# - echo " ------ TESTING STABLE BRANCH ------- "
# - cargo +stable test --package pleco
# - cargo +stable bench --package pleco
# - echo " ------ TESTING NIGHTLY BRANCH ------- "
# - cargo test --verbose
# - cargo bench --package pleco --all-features
# - cargo bench --package pleco_engine --all-features
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ And add the following to a `main.rs` or `lib.rs`:
extern crate pleco;
```

As of version `0.5.0`, the pleco library is available on all three Rust channels (stable, beta, nightly).

### Basic Usage
Setting up a board position is extremely simple.
```rust
Expand Down
2 changes: 1 addition & 1 deletion pleco/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pleco"
version = "0.4.4"
version = "0.5.0"
authors = ["Stephen Fleischman <stephenf@cs.washington.edu>"]
description = "A blazingly-fast chess library."
homepage = "https://github.com/sfleischman105/Pleco"
Expand Down
3 changes: 2 additions & 1 deletion pleco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Some of the features `pleco` implements:
Use
-------

To use Pleco inside your own Rust projects, [Pleco.rs is available as a library on crates.io](https://crates.io/crates/pleco).
To use Pleco inside your own Rust projects,
[Pleco.rs is available as a library on crates.io](https://crates.io/crates/pleco).
Pleco runs on all three distributions (`nightly`, `beta`, `stable`) of rust.

### Basic Usage
Expand Down
2 changes: 1 addition & 1 deletion pleco/src/board/board_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl BoardState {
/// If there was no previous state, returns `None`.
#[inline]
pub fn get_prev(&self) -> Option<Arc<BoardState>> {
(&self).prev.as_ref().cloned()
self.prev.as_ref().cloned()
}

/// Iterates through all previous `BoardStates` and prints debug information for each.
Expand Down
8 changes: 4 additions & 4 deletions pleco/src/board/castle_rights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Castling {

/// Returns if a player can castle for a given side
#[inline]
pub fn castle_rights(&self, player: Player, side: CastleType) -> bool {
pub fn castle_rights(self, player: Player, side: CastleType) -> bool {
match player {
Player::White => {
match side {
Expand All @@ -102,15 +102,15 @@ impl Castling {
}

#[inline]
pub fn player_can_castle(&self, player: Player) -> Castling {
pub fn player_can_castle(self, player: Player) -> Castling {
Castling {
bits: self.bits & (Castling::WHITE_ALL.bits >> (2 * player as u16))
}
}

/// Returns if both players have lost their ability to castle
#[inline]
pub fn no_castling(&self) -> bool {
pub fn no_castling(self) -> bool {
!self.contains(Castling::WHITE_K) &&
!self.contains(Castling::WHITE_Q) &&
!self.contains(Castling::BLACK_K) &&
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Castling {
/// Used for FEN Strings, with (`K` | `Q`) representing white castling abilities,
/// and (`k` | `q`) representing black castling abilities. If there are no bits set,
/// returns a String containing "-".
pub fn pretty_string(&self) -> String {
pub fn pretty_string(self) -> String {
if self.no_castling() {
"-".to_owned()
} else {
Expand Down
12 changes: 5 additions & 7 deletions pleco/src/board/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ impl Board {
pub fn shallow_clone(&self) -> Board {
Board {
turn: self.turn,
bbs: self.bbs.clone(),
bbs_player: self.bbs_player.clone(),
bbs: self.bbs,
bbs_player: self.bbs_player,
half_moves: self.half_moves,
depth: 0,
piece_counts: self.piece_counts,
Expand Down Expand Up @@ -279,8 +279,8 @@ impl Board {
pub fn parallel_clone(&self) -> Board {
Board {
turn: self.turn,
bbs: self.bbs.clone(),
bbs_player: self.bbs_player.clone(),
bbs: self.bbs,
bbs_player: self.bbs_player,
half_moves: self.half_moves,
depth: self.depth,
piece_counts: self.piece_counts,
Expand Down Expand Up @@ -2519,9 +2519,7 @@ impl RandBoard {
moves[self.random() % moves.len()]
} else if self.random() % 5 == 0 {
AlphaBetaSearcher::best_move(board.shallow_clone(),2)
} else if self.random() % 3 == 0 {
AlphaBetaSearcher::best_move(board.shallow_clone(),3)
} else if !favorable && self.random() % 5 < 4 {
} else if self.random() % 3 == 0 || !favorable && self.random() % 5 < 4 {
AlphaBetaSearcher::best_move(board.shallow_clone(),3)
} else {
AlphaBetaSearcher::best_move(board.shallow_clone(),4)
Expand Down
30 changes: 15 additions & 15 deletions pleco/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ impl Player {
/// assert_eq!(b.other_player(), Player::White);
/// ```
#[inline(always)]
pub fn other_player(&self) -> Player {
!(*self)
pub fn other_player(self) -> Player {
!(self)
}

/// Returns the relative square from a given square.
#[inline(always)]
pub fn relative_square(&self, sq: SQ) -> SQ {
pub fn relative_square(self, sq: SQ) -> SQ {
assert!(sq.is_okay());
sq ^ SQ((*self) as u8 * 56)
sq ^ SQ((self) as u8 * 56)
}

/// Gets the direction of a pawn push for a given player.
#[inline(always)]
pub fn pawn_push(&self) -> i8 {
match *self {
pub fn pawn_push(self) -> i8 {
match self {
Player::White => NORTH,
Player::Black => SOUTH,
}
Expand All @@ -111,7 +111,7 @@ impl Player {
/// assert_eq!(b.relative_rank_of_sq(SQ::A1), Rank::R8);
/// ```
#[inline(always)]
pub fn relative_rank_of_sq(&self, sq: SQ) -> Rank {
pub fn relative_rank_of_sq(self, sq: SQ) -> Rank {
self.relative_rank(sq.rank())
}

Expand All @@ -131,8 +131,8 @@ impl Player {
/// assert_eq!(b.relative_rank(Rank::R1), Rank::R8);
/// ```
#[inline]
pub fn relative_rank(&self, rank: Rank) -> Rank {
let r = (rank as u8) ^ (*self as u8 * 7);
pub fn relative_rank(self, rank: Rank) -> Rank {
let r = (rank as u8) ^ (self as u8 * 7);
debug_assert!(r < 8);
// ALL_RANKS[((rank as u8) ^ (*self as u8 * 7)) as usize]
unsafe {
Expand Down Expand Up @@ -219,8 +219,8 @@ impl PieceType {
///
/// Used for sorting moves.
#[inline]
pub fn value(&self) -> i8 {
match *self {
pub fn value(self) -> i8 {
match self {
PieceType::P => 1,
PieceType::N | PieceType::B => 3,
PieceType::R => 5,
Expand Down Expand Up @@ -250,8 +250,8 @@ impl PieceType {

/// Return the lowercase character of a `Piece`.
#[inline]
pub fn char_lower(&self) -> char {
match *self {
pub fn char_lower(self) -> char {
match self {
PieceType::P => 'p',
PieceType::N => 'n',
PieceType::B => 'b',
Expand All @@ -264,8 +264,8 @@ impl PieceType {

/// Return the uppercase character of a `Piece`.
#[inline]
pub fn char_upper(&self) -> char {
match *self {
pub fn char_upper(self) -> char {
match self {
PieceType::P => 'P',
PieceType::N => 'N',
PieceType::B => 'B',
Expand Down
Loading