Skip to content

Commit bd2751f

Browse files
author
Ferdinand Schober
committed
formatting
1 parent 412e30c commit bd2751f

4 files changed

Lines changed: 33 additions & 21 deletions

File tree

solitaire-game/src/solver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ fn calculate_random_move_chances(
8585
let wake = wake.clone();
8686
let task = thread_pool.spawn(async move {
8787
let feasible = feasible;
88-
let p_random_chance = solitaire_solver::calculate_p_random_chance_success(feasible.into_iter());
88+
let p_random_chance =
89+
solitaire_solver::calculate_p_random_chance_success(feasible.into_iter());
8990

9091
let mut command_queue = CommandQueue::default();
9192
command_queue.push(move |world: &mut World| {

solitaire-solver/src/calc_success.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use super::{
66
};
77

88
/// calculate the chances of winning the game by chosing possible moves at random
9-
pub fn calculate_p_random_chance_success(feasible: impl Iterator<Item = Board>) -> HashMap<Board, f64> {
9+
pub fn calculate_p_random_chance_success(
10+
feasible: impl Iterator<Item = Board>,
11+
) -> HashMap<Board, f64> {
1012
let mut chances = HashMap::default();
1113
chances.insert(Board::solved(), 1.0);
1214

@@ -50,7 +52,10 @@ fn successors_of(board: Board, buffer: &mut [Board; MAX_MOVES]) -> &[Board] {
5052
let mut len = 0;
5153
for dir in Dir::enumerate() {
5254
for idx in board.mov_pattern_mask(dir) {
53-
debug_assert!(len < MAX_MOVES, "more than {MAX_MOVES} moves from one board");
55+
debug_assert!(
56+
len < MAX_MOVES,
57+
"more than {MAX_MOVES} moves from one board"
58+
);
5459
buffer[len] = Board::normalize_after_move(&syms, idx, dir);
5560
len += 1;
5661
}

solitaire-solver/src/unique_solutions.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::solution::SolutionMultiset;
1+
use crate::board::Idx;
22
use crate::dir::Dir;
33
use crate::par;
4-
use crate::board::Idx;
4+
use crate::solution::SolutionMultiset;
55
use crate::{Board, Move};
66
use crate::{HashMap, HashSet, Solution};
7+
use rustc_hash::FxHashSet;
78
use std::collections::BTreeMap;
89
use std::num::NonZero;
9-
use rustc_hash::FxHashSet;
1010

1111
/// Dense slot for a move, keyed by its starting bit and direction: 64 positions x 4
1212
/// directions. Sparse - only 76 of the 256 are reachable - but it makes the occurrence
@@ -248,7 +248,6 @@ impl ZobristTable {
248248
}
249249
}
250250

251-
252251
/// Upper bound on the moves available from one board.
253252
///
254253
/// The cross holds 38 collinear triples and each can be jumped from either end, so no
@@ -386,7 +385,10 @@ fn successors_of(board: Board, buffer: &mut [Board; MAX_MOVES], kind: PathKind)
386385
let mut len = 0;
387386
for dir in Dir::enumerate() {
388387
for idx in board.mov_pattern_mask(dir) {
389-
debug_assert!(len < MAX_MOVES, "more than {MAX_MOVES} moves from one board");
388+
debug_assert!(
389+
len < MAX_MOVES,
390+
"more than {MAX_MOVES} moves from one board"
391+
);
390392
buffer[len] = Board::normalize_after_move(&syms, idx, dir);
391393
len += 1;
392394
}
@@ -412,15 +414,16 @@ fn successors_of(board: Board, buffer: &mut [Board; MAX_MOVES], kind: PathKind)
412414
/// The search uses the former for every edge, so they had better agree.
413415
#[test]
414416
fn test_move_at_matches_get_legal_moves() {
415-
let boards = [
416-
Board::default(),
417-
Board(Board::full().0 & !Board::solved().0),
418-
Board::solved(),
419-
]
420-
.into_iter()
421-
.chain((0..500).map(|_| {
422-
Board::from_compressed_repr(rand::random::<u64>() & ((1 << Board::SLOTS) - 1))
423-
}));
417+
let boards =
418+
[
419+
Board::default(),
420+
Board(Board::full().0 & !Board::solved().0),
421+
Board::solved(),
422+
]
423+
.into_iter()
424+
.chain((0..500).map(|_| {
425+
Board::from_compressed_repr(rand::random::<u64>() & ((1 << Board::SLOTS) - 1))
426+
}));
424427

425428
let mut checked = 0usize;
426429
for board in boards {

src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ fn main() {
188188

189189
println!("took {:?}", start.elapsed());
190190
println!("success probability when chosing moves at random: {percentage}%");
191-
let (b, p) = success_probabilities.iter().map(|(b, p)| (*b, *p)).fold((Board::default(), f64::INFINITY), |(b1, p1), (b2, p2)| if p2 < p1 { (b2, p2) } else { (b1, p1) });
191+
let (b, p) = success_probabilities
192+
.iter()
193+
.map(|(b, p)| (*b, *p))
194+
.fold((Board::default(), f64::INFINITY), |(b1, p1), (b2, p2)| {
195+
if p2 < p1 { (b2, p2) } else { (b1, p1) }
196+
});
192197
let perc = p * 100.;
193198
println!("minimum success chance: \n{b} ({perc}%)");
194-
195199
}
196200
Command::CalculateSingle => {
197201
let solution = solitaire_solver::calculate_first_solution();
@@ -226,8 +230,7 @@ fn main() {
226230
"distinct move sequences: {}",
227231
moves.get(&Board::default()).unwrap()
228232
);
229-
let boards =
230-
solitaire_solver::all_unique_board_paths(feasible, args.threads);
233+
let boards = solitaire_solver::all_unique_board_paths(feasible, args.threads);
231234
log::info!(
232235
"distinct board sequences: {}",
233236
boards.get(&Board::default()).unwrap()

0 commit comments

Comments
 (0)