Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 87a0719

Browse files
committedSep 5, 2024··
chore: fix all tests
1 parent 9744355 commit 87a0719

File tree

6 files changed

+141
-164
lines changed

6 files changed

+141
-164
lines changed
 

‎games/src/ataxx/bitboard.rs

+122
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,125 @@ bitboard_type! {
2424
FirstRank = Self(0x000000000007f);
2525
}
2626
}
27+
28+
use crate::interface::{BitBoardType, RepresentableType};
29+
30+
impl BitBoard {
31+
pub fn singles(bb: BitBoard) -> BitBoard {
32+
let bar = bb | bb.east() | bb.west();
33+
bar | bar.north() | bar.south()
34+
}
35+
36+
/// single returns the targets of a singular Move from the given Square.
37+
pub const fn single(square: Square) -> BitBoard {
38+
SINGLES[square as usize]
39+
}
40+
41+
/// double returns the targets of a jump Move from the given Square.
42+
pub const fn double(square: Square) -> BitBoard {
43+
DOUBLES[square as usize]
44+
}
45+
}
46+
47+
const SINGLES: [BitBoard; Square::N] = [
48+
BitBoard(0x0000000000182),
49+
BitBoard(0x0000000000385),
50+
BitBoard(0x000000000070a),
51+
BitBoard(0x0000000000e14),
52+
BitBoard(0x0000000001c28),
53+
BitBoard(0x0000000003850),
54+
BitBoard(0x0000000003020),
55+
BitBoard(0x000000000c103),
56+
BitBoard(0x000000001c287),
57+
BitBoard(0x000000003850e),
58+
BitBoard(0x0000000070a1c),
59+
BitBoard(0x00000000e1438),
60+
BitBoard(0x00000001c2870),
61+
BitBoard(0x0000000181060),
62+
BitBoard(0x0000000608180),
63+
BitBoard(0x0000000e14380),
64+
BitBoard(0x0000001c28700),
65+
BitBoard(0x0000003850e00),
66+
BitBoard(0x00000070a1c00),
67+
BitBoard(0x000000e143800),
68+
BitBoard(0x000000c083000),
69+
BitBoard(0x000003040c000),
70+
BitBoard(0x0000070a1c000),
71+
BitBoard(0x00000e1438000),
72+
BitBoard(0x00001c2870000),
73+
BitBoard(0x00003850e0000),
74+
BitBoard(0x000070a1c0000),
75+
BitBoard(0x0000604180000),
76+
BitBoard(0x0001820600000),
77+
BitBoard(0x0003850e00000),
78+
BitBoard(0x00070a1c00000),
79+
BitBoard(0x000e143800000),
80+
BitBoard(0x001c287000000),
81+
BitBoard(0x003850e000000),
82+
BitBoard(0x003020c000000),
83+
BitBoard(0x00c1030000000),
84+
BitBoard(0x01c2870000000),
85+
BitBoard(0x03850e0000000),
86+
BitBoard(0x070a1c0000000),
87+
BitBoard(0x0e14380000000),
88+
BitBoard(0x1c28700000000),
89+
BitBoard(0x1810600000000),
90+
BitBoard(0x0081800000000),
91+
BitBoard(0x0143800000000),
92+
BitBoard(0x0287000000000),
93+
BitBoard(0x050e000000000),
94+
BitBoard(0x0a1c000000000),
95+
BitBoard(0x1438000000000),
96+
BitBoard(0x0830000000000),
97+
];
98+
const DOUBLES: [BitBoard; Square::N] = [
99+
BitBoard(0x000000001c204),
100+
BitBoard(0x000000003c408),
101+
BitBoard(0x000000007c891),
102+
BitBoard(0x00000000f9122),
103+
BitBoard(0x00000001f2244),
104+
BitBoard(0x00000001e0408),
105+
BitBoard(0x00000001c0810),
106+
BitBoard(0x0000000e10204),
107+
BitBoard(0x0000001e20408),
108+
BitBoard(0x0000003e44891),
109+
BitBoard(0x0000007c89122),
110+
BitBoard(0x000000f912244),
111+
BitBoard(0x000000f020408),
112+
BitBoard(0x000000e040810),
113+
BitBoard(0x0000070810207),
114+
BitBoard(0x00000f102040f),
115+
BitBoard(0x00001f224489f),
116+
BitBoard(0x00003e448913e),
117+
BitBoard(0x00007c891227c),
118+
BitBoard(0x0000781020478),
119+
BitBoard(0x0000702040870),
120+
BitBoard(0x0003840810380),
121+
BitBoard(0x0007881020780),
122+
BitBoard(0x000f912244f80),
123+
BitBoard(0x001f224489f00),
124+
BitBoard(0x003e448913e00),
125+
BitBoard(0x003c081023c00),
126+
BitBoard(0x0038102043800),
127+
BitBoard(0x01c204081c000),
128+
BitBoard(0x03c408103c000),
129+
BitBoard(0x07c891227c000),
130+
BitBoard(0x0f912244f8000),
131+
BitBoard(0x1f224489f0000),
132+
BitBoard(0x1e040811e0000),
133+
BitBoard(0x1c081021c0000),
134+
BitBoard(0x0102040e00000),
135+
BitBoard(0x0204081e00000),
136+
BitBoard(0x0448913e00000),
137+
BitBoard(0x0891227c00000),
138+
BitBoard(0x112244f800000),
139+
BitBoard(0x020408f000000),
140+
BitBoard(0x040810e000000),
141+
BitBoard(0x0102070000000),
142+
BitBoard(0x02040f0000000),
143+
BitBoard(0x04489f0000000),
144+
BitBoard(0x08913e0000000),
145+
BitBoard(0x11227c0000000),
146+
BitBoard(0x0204780000000),
147+
BitBoard(0x0408700000000),
148+
];

‎games/src/ataxx/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ mod piece;
1414
mod position;
1515
mod square;
1616

17-
pub mod moves;
17+
#[cfg(test)]
18+
mod tests;

‎games/src/ataxx/move.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl Move {
5858
pub const NULL: Move = Move(1 << 15);
5959
/// PASS Move represents a no move, where only the side to move changes.
6060
/// ```
61-
/// use ataxx::*;
61+
/// use tetka_games::ataxx::*;
62+
/// use tetka_games::interface::PositionType;
6263
/// use std::str::FromStr;
6364
///
6465
/// let old_pos = Position::from_str("x5o/7/7/7/7/7/o5x x 0 1").unwrap();
@@ -74,7 +75,7 @@ impl Move {
7475
/// target Square. For a singular Move, [`Move::source`] and [`Move::target`]
7576
/// are equal since the source Square is irrelevant to the Move.
7677
/// ```
77-
/// use ataxx::*;
78+
/// use tetka_games::ataxx::*;
7879
///
7980
/// let mov = Move::new_single(Square::A1);
8081
///
@@ -90,7 +91,7 @@ impl Move {
9091
/// target Square. These Squares can be recovered with the [`Move::source`] and
9192
/// [`Move::target`] methods respectively.
9293
/// ```
93-
/// use ataxx::*;
94+
/// use tetka_games::ataxx::*;
9495
///
9596
/// let mov = Move::new(Square::A1, Square::A3);
9697
///
@@ -109,7 +110,7 @@ impl Move {
109110
/// Source returns the source Square of the moving piece. This is equal to the
110111
/// target Square if the given Move is of singular type.
111112
/// ```
112-
/// use ataxx::*;
113+
/// use tetka_games::ataxx::*;
113114
///
114115
/// let mov = Move::new(Square::A1, Square::A3);
115116
///
@@ -121,7 +122,7 @@ impl Move {
121122

122123
/// Target returns the target Square of the moving piece.
123124
/// ```
124-
/// use ataxx::*;
125+
/// use tetka_games::ataxx::*;
125126
///
126127
/// let mov = Move::new(Square::A1, Square::A3);
127128
///
@@ -134,7 +135,7 @@ impl Move {
134135
/// is_single checks if the given Move is singular in nature. The result of this
135136
/// function for [`Move::NULL`] and [`Move::PASS`] is undefined.
136137
/// ```
137-
/// use ataxx::*;
138+
/// use tetka_games::ataxx::*;
138139
///
139140
/// let sing = Move::new_single(Square::A1);
140141
/// let jump = Move::new(Square::A1, Square::A3);
@@ -166,7 +167,7 @@ impl FromStr for Move {
166167
/// [`Square::FromStr`](Square::from_str). This function can be treated as the
167168
/// inverse of the [`fmt::Display`] trait for [Move].
168169
/// ```
169-
/// use ataxx::*;
170+
/// use tetka_games::ataxx::*;
170171
/// use std::str::FromStr;
171172
///
172173
/// let pass = Move::PASS;
@@ -207,7 +208,7 @@ impl fmt::Display for Move {
207208
/// refer to `Square::Display`. [`Move::NULL`] is formatted as `null`, while
208209
/// [`Move::PASS`] is formatted as `0000`.
209210
/// ```
210-
/// use ataxx::*;
211+
/// use tetka_games::ataxx::*;
211212
///
212213
/// let null = Move::NULL;
213214
/// let pass = Move::PASS;

‎games/src/ataxx/moves.rs

-146
This file was deleted.

‎games/src/ataxx/position.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ use crate::ataxx::{
3131
};
3232
use crate::interface::MoveStore;
3333

34-
use super::moves;
35-
3634
/// Position represents the snapshot of an Ataxx Board, the state of the an
3735
/// ataxx game at a single point in time. It also provides all of the methods
3836
/// necessary to manipulate such a snapshot.
@@ -171,7 +169,7 @@ impl PositionType for Position {
171169
let stm_pieces = self.color_bb(stm);
172170
let xtm_pieces = self.color_bb(!stm);
173171

174-
let captured = moves::single(m.target()) & xtm_pieces;
172+
let captured = BitBoard::single(m.target()) & xtm_pieces;
175173
let from_to = BitBoard::from(m.target()) | BitBoard::from(m.source());
176174

177175
// Move the captured pieces from xtm to stm.
@@ -219,14 +217,14 @@ impl PositionType for Position {
219217
// Pieces can only move to unoccupied Squares.
220218
let allowed = !(stm | xtm | gap);
221219

222-
for target in moves::singles(stm) & allowed {
220+
for target in BitBoard::singles(stm) & allowed {
223221
movelist.push(Move::new_single(target));
224222
}
225223

226224
for piece in stm {
227225
// There may be multiple jump moves to a single Square, so they need to be
228226
// verified (& allowed) and serialized into the movelist immediately.
229-
let double = moves::double(piece) & allowed;
227+
let double = BitBoard::double(piece) & allowed;
230228
for target in double {
231229
movelist.push(Move::new(piece, target));
232230
}
@@ -256,12 +254,12 @@ impl PositionType for Position {
256254
let allowed = !(stm | xtm | gap);
257255

258256
// Count the number single moves in the Position.
259-
let mut moves: usize = (moves::singles(stm) & allowed).cardinality();
257+
let mut moves: usize = (BitBoard::singles(stm) & allowed).cardinality();
260258

261259
for piece in stm {
262260
// There may be multiple jump moves to a single Square, so they need to be
263261
// verified (& allowed) and counted into the Position total immediately.
264-
let double = moves::double(piece) & allowed;
262+
let double = BitBoard::double(piece) & allowed;
265263
moves += double.cardinality();
266264
}
267265

‎games/src/ataxx/tests/perft.rs ‎games/src/ataxx/tests/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use ataxx::{perft, Position};
1+
use crate::ataxx::Position;
2+
use crate::perft;
23
use std::str::FromStr;
34

45
macro_rules! perft_test {
56
($name:ident $pos:literal $depth:literal $nodes:literal) => {
67
#[test]
78
fn $name() {
89
let position = Position::from_str($pos).unwrap();
9-
assert_eq!(perft::<true, true>(position, $depth), $nodes)
10+
assert_eq!(perft::<true, true, _>(position, $depth), $nodes)
1011
}
1112
};
1213
}

0 commit comments

Comments
 (0)
Please sign in to comment.