Skip to content

Commit

Permalink
chore: add not operator for Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed May 25, 2024
1 parent e57783a commit 0f2cc00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions ataxx/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;
use std::{fmt, ops};

use crate::{BitBoard, Piece};

Expand All @@ -24,7 +24,9 @@ pub struct Hash(pub u64);
impl Hash {
/// new creates a new Hash from the given black and white piece BitBoards.
/// This function is used in the backend by Position, and it is usually
/// unnecessary for it to be used explicitly by end-users.
/// unnecessary for it to be used explicitly by end-users. new doesn't take
/// the blocker configuration into account since that remains unchanged
/// throughout an ataxx game.
pub fn new(black: BitBoard, white: BitBoard, stm: Piece) -> Hash {
let a = black.0;
let b = white.0;
Expand Down Expand Up @@ -61,6 +63,15 @@ impl Hash {
}
}

impl ops::Not for Hash {
type Output = Self;

/// Not operator (!) switches the side to move for the Hash.
fn not(self) -> Self::Output {
Hash(!self.0)
}
}

impl fmt::Display for Hash {
/// Display allows Hash to be formatted in a human-readable form.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion ataxx/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Position {
if m == Move::PASS {
return Position {
bitboards: self.bitboards,
checksum: Hash(!self.checksum.0),
checksum: !self.checksum,
side_to_move: !self.side_to_move,
ply_count: self.ply_count + 1,
half_move_clock: self.half_move_clock + 1,
Expand Down

0 comments on commit 0f2cc00

Please sign in to comment.