You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: gui/src/wormhole/board.rs
+70-4Lines changed: 70 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,8 @@ The numbering has been chosen such that the following symmetries are easier to c
60
60
- Flip along the xy-diagonal i.e. flip along the Top and Bottom along the nw-se diagonal and the flip the Hole left-right on the line connecting `y` to `Y` or equivalently the line connecting `w` to `W`.
61
61
*/
62
62
63
+
use std::collections::{BTreeSet,HashSet};
64
+
63
65
use glam::Vec3;
64
66
65
67
usecrate::wormhole::board_render::BoardParams;
@@ -73,7 +75,7 @@ pub enum PosType {
73
75
HolePent,// A number in the "Hole" part of the diagram between 128 and 143 inclusive.
74
76
}
75
77
76
-
#[derive(Debug,Clone,Copy,PartialEq,Eq)]
78
+
#[derive(Debug,Clone,Copy,PartialEq,Eq,Hash)]
77
79
pubstructPos{
78
80
n:u8,
79
81
}
@@ -661,13 +663,15 @@ pub struct MovesLookup {
661
663
diagonal_adjacent:[Vec<Pos>;144],
662
664
continuations:[[Vec<Pos>;144];144],
663
665
knight_moves:[Vec<Pos>;144],
666
+
white_forward_diagonal:[Vec<Pos>;144],
667
+
black_forward_diagonal:[Vec<Pos>;144],
664
668
cardinal_slides:[Vec<Slides>;144],
665
669
diagonal_slides:[Vec<Slides>;144],
666
670
}
667
671
668
672
implMovesLookup{
669
673
pubfnnew() -> Self{
670
-
let white_forward = std::array::from_fn(|i| {
674
+
let white_forward:[Vec<Pos>;144] = std::array::from_fn(|i| {
671
675
letmut pos = Pos::new(i asu8);
672
676
let flip_z = pos.full_symmetry_and_orbit().0.flip_z;
673
677
if flip_z {
@@ -724,7 +728,7 @@ impl MovesLookup {
724
728
forward
725
729
});
726
730
727
-
let black_forward = std::array::from_fn(|i| {
731
+
let black_forward:[Vec<Pos>;144] = std::array::from_fn(|i| {
728
732
white_forward[Pos::new(i asu8).flip_x().idx()]
729
733
.iter()
730
734
.map(|p| p.flip_x())
@@ -1072,13 +1076,67 @@ impl MovesLookup {
1072
1076
})
1073
1077
});
1074
1078
1079
+
let perp_cardinal_continuations:[[Vec<Pos>;144];144] = std::array::from_fn(|a_idx| {
1080
+
std::array::from_fn(|b_idx| {
1081
+
letmut perp = cardinal_adjacent[b_idx]
1082
+
.iter()
1083
+
.cloned()
1084
+
.collect::<HashSet<Pos>>();
1085
+
perp.remove(&Pos::new(a_idx asu8));
1086
+
for c_pos in&continuations[a_idx][b_idx]{
1087
+
perp.remove(c_pos);
1088
+
}
1089
+
perp.into_iter().collect::<Vec<_>>()
1090
+
})
1091
+
});
1092
+
1093
+
let knight_moves = std::array::from_fn(|idx| {
1094
+
let a = Pos::new(idx asu8);
1095
+
letmut mvs = HashSet::new();
1096
+
for b in&cardinal_adjacent[idx]{
1097
+
for c in&continuations[a.idx()][b.idx()]{
1098
+
for d in&perp_cardinal_continuations[b.idx()][c.idx()]{
1099
+
mvs.insert(*d);
1100
+
}
1101
+
}
1102
+
for c in&perp_cardinal_continuations[a.idx()][b.idx()]{
1103
+
for d in&continuations[b.idx()][c.idx()]{
1104
+
mvs.insert(*d);
1105
+
}
1106
+
}
1107
+
}
1108
+
mvs.into_iter().collect()
1109
+
});
1110
+
1111
+
let white_forward_diagonal = std::array::from_fn(|a_idx| {
1112
+
letmut mvs = HashSet::new();
1113
+
for b_pos in white_forward[a_idx].iter(){
1114
+
for c_pos in&perp_cardinal_continuations[a_idx][b_pos.idx()]{
1115
+
mvs.insert(*c_pos);
1116
+
}
1117
+
}
1118
+
mvs.into_iter().collect::<Vec<_>>()
1119
+
});
1120
+
1121
+
let black_forward_diagonal = std::array::from_fn(|a_idx| {
1122
+
letmut mvs = HashSet::new();
1123
+
for b_pos in black_forward[a_idx].iter(){
1124
+
for c_pos in&perp_cardinal_continuations[a_idx][b_pos.idx()]{
0 commit comments