|
1 | 1 | use crate::solution::SolutionMultiset; |
2 | | -use crate::{Board, Move}; |
| 2 | +use crate::{Board, Move, normalize}; |
3 | 3 | use crate::{HashSet, Solution}; |
| 4 | +use std::array; |
4 | 5 | use std::collections::BTreeMap; |
5 | 6 |
|
6 | 7 | /// we define two solutions as "equal" when the |
@@ -137,4 +138,31 @@ impl ZobristTable { |
137 | 138 | type MultisetHash = u64; |
138 | 139 |
|
139 | 140 | #[allow(unused)] |
140 | | -pub fn all_unique_paths(feasible: &HashSet<Board>) {} |
| 141 | +pub fn all_unique_paths(feasible: impl IntoIterator<Item = Board>) -> HashMap<Board, usize> { |
| 142 | + let mut number_of_combinations: HashMap<Board, usize, _> = HashMap::new(); |
| 143 | + let mut boards: [Vec<Board>; 33] = array::from_fn(|_| Default::default()); |
| 144 | + let mut feasible_set: HashSet<Board> = HashSet::default(); |
| 145 | + for board in feasible.into_iter() { |
| 146 | + feasible_set.insert(board); |
| 147 | + boards[board.count_pegs()].push(board); |
| 148 | + } |
| 149 | + number_of_combinations.insert(Board::solved(), 1); |
| 150 | + for i in 2..=32 { |
| 151 | + for board in &boards[i] { |
| 152 | + let mut next = Board::possible_moves(&[*board]); |
| 153 | + normalize(&mut next); |
| 154 | + next.dedup(); |
| 155 | + |
| 156 | + let count = next |
| 157 | + .into_iter() |
| 158 | + .filter(|b| feasible_set.contains(b)) |
| 159 | + .map(|b| number_of_combinations[&b]) |
| 160 | + .sum(); |
| 161 | + let entry = number_of_combinations |
| 162 | + .entry(*board) |
| 163 | + .or_insert(Default::default()); |
| 164 | + *entry = count; |
| 165 | + } |
| 166 | + } |
| 167 | + number_of_combinations |
| 168 | +} |
0 commit comments