-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a small set with the eight most recent zobrist hashes for detecting ko with the is_valid method. This is used to detect positional super-ko during play.
- Loading branch information
Showing
2 changed files
with
160 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2017 Karl Sundequist Blomdahl <karl.sundequist.blomdahl@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// A LRA set that only keeps the eight most recently added values. | ||
#[derive(Clone)] | ||
pub struct SmallSet { | ||
buf: [u64; 8], | ||
count: usize | ||
} | ||
|
||
impl SmallSet { | ||
/// Returns an empty set. | ||
pub fn new() -> SmallSet { | ||
SmallSet { buf: [0; 8], count: 0 } | ||
} | ||
|
||
/// Adds the given value to this set, removing the oldest value if the set overflows. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - the value to add to the set | ||
/// | ||
pub fn push(&mut self, value: u64) { | ||
self.buf[self.count] = value; | ||
self.count += 1; | ||
|
||
if self.count == 8 { | ||
self.count = 0; | ||
} | ||
} | ||
|
||
/// Returns true if this set contains the given value. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `other` - the value to look for | ||
/// | ||
pub fn contains(&self, other: u64) -> bool { | ||
(0..8).any(|x| self.buf[x] == other) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use go::small_set::*; | ||
|
||
#[test] | ||
fn check() { | ||
let mut s = SmallSet::new(); | ||
|
||
s.push(1); | ||
s.push(2); | ||
s.push(3); | ||
|
||
assert!(s.contains(1)); | ||
assert!(s.contains(2)); | ||
assert!(s.contains(3)); | ||
assert!(!s.contains(4)); | ||
} | ||
} |