Skip to content

Commit d6206c7

Browse files
author
Ferdinand Schober
committed
formatting
1 parent 2f92881 commit d6206c7

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

solitaire-game/src/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,9 @@ fn log_edge_lengths(graph: &ConstellationGraph) {
754754
/// full graph, 8.58M edges at this size come out as ~7.5k edge chunks, i.e. ~7.5k draw
755755
/// calls a frame - and the viewpoint that actually hurts is the one where culling rejects
756756
/// almost nothing, so there the draw calls are pure loss. Sweep it with `[` and `]`.
757-
#[cfg(not(target_arch="wasm32"))]
757+
#[cfg(not(target_arch = "wasm32"))]
758758
const DEFAULT_CHUNK_SIZE: f32 = 1024.0;
759-
#[cfg(target_arch="wasm32")]
759+
#[cfg(target_arch = "wasm32")]
760760
const DEFAULT_CHUNK_SIZE: f32 = 8192.0;
761761

762762
/// Default [`BuildSettings::edge_budget`] - the edge count above which a chunk gets

solitaire-game/src/solver.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use futures_lite::future::{self, block_on};
22
use solitaire_solver::dominators::{ForcedJump, forced_jumps};
33
use solitaire_solver::{HashMap, HashSet, SolutionMultiset};
44

5+
use crate::CurrentBoard;
56
use bevy::{
67
ecs::world::CommandQueue,
78
prelude::*,
89
tasks::{AsyncComputeTaskPool, Task},
910
window::RequestRedraw,
1011
winit::{EventLoopProxyWrapper, WinitUserEvent::WakeUp},
1112
};
12-
use crate::CurrentBoard;
1313
use solitaire_solver::Board;
1414

1515
pub struct Solver;
@@ -32,8 +32,9 @@ impl Plugin for Solver {
3232
);
3333
app.add_systems(
3434
Update,
35-
schedule_forced_jumps
36-
.run_if(resource_exists::<UniquePaths>.and_then(not(resource_exists::<ForcedJumpsPending>))),
35+
schedule_forced_jumps.run_if(
36+
resource_exists::<UniquePaths>.and_then(not(resource_exists::<ForcedJumpsPending>)),
37+
),
3738
);
3839
app.add_systems(Update, poll_task);
3940
}

solitaire-solver/src/dominators.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ pub struct ForcedJump {
237237
/// widest at the opening and collapses quickly as pegs come off. Returns empty when `from` is
238238
/// already lost - nothing is forced when nothing wins.
239239
pub fn forced_jumps(from: Board, counts: &HashMap<Board, u64>) -> Vec<ForcedJump> {
240-
let winnable =
241-
|board: &Board| counts.get(&board.normalize()).copied().unwrap_or(0) > 0;
240+
let winnable = |board: &Board| counts.get(&board.normalize()).copied().unwrap_or(0) > 0;
242241
if !winnable(&from) {
243242
return Vec::new();
244243
}
@@ -256,7 +255,11 @@ pub fn forced_jumps(from: Board, counts: &HashMap<Board, u64>) -> Vec<ForcedJump
256255
// only a layer that has narrowed to one board can host a forced jump, and then only
257256
// if that board has exactly one winning move - but the sweep has to continue either
258257
// way, since a later layer may still collapse
259-
let sole = if layer.len() == 1 { layer.first() } else { None };
258+
let sole = if layer.len() == 1 {
259+
layer.first()
260+
} else {
261+
None
262+
};
260263
let mut only: Option<ForcedJump> = None;
261264
let mut candidates = 0usize;
262265

@@ -344,7 +347,8 @@ mod tests {
344347
let lines = winning_lines(board, &set);
345348
assert!(!lines.is_empty(), "counts claim {board:?} is winnable");
346349
assert_eq!(
347-
lines.len() as u64, counts[&board],
350+
lines.len() as u64,
351+
counts[&board],
348352
"brute force and the DP disagree on the line count for {board:?}"
349353
);
350354

@@ -366,7 +370,10 @@ mod tests {
366370
}
367371
}
368372
assert!(checked > 50, "only {checked} boards exercised");
369-
assert!(with_forced > 0, "no board had any forced move - test proves nothing");
373+
assert!(
374+
with_forced > 0,
375+
"no board had any forced move - test proves nothing"
376+
);
370377
}
371378

372379
/// Every winning line from `board` in the un-normalized game, as its list of jumps.
@@ -413,7 +420,8 @@ mod tests {
413420
for board in boards {
414421
let lines = winning_jumps(board, &set);
415422
assert_eq!(
416-
lines.len() as u64, counts[&board],
423+
lines.len() as u64,
424+
counts[&board],
417425
"the move-sequence count must be the un-normalized line count for {board:?}"
418426
);
419427

@@ -433,7 +441,10 @@ mod tests {
433441
}
434442
}
435443
assert!(checked > 50, "only {checked} boards exercised");
436-
assert!(with_forced > 0, "no board had any forced jump - test proves nothing");
444+
assert!(
445+
with_forced > 0,
446+
"no board had any forced jump - test proves nothing"
447+
);
437448
}
438449

439450
/// The opening's four first moves are symmetric images of each other, so the player really
@@ -473,8 +484,14 @@ mod tests {
473484
.expect("a winnable two-peg board must exist");
474485

475486
let verdicts = classify_moves(two_pegs, &set, &counts);
476-
let required = verdicts.iter().filter(|(_, v)| *v == Verdict::Required).count();
477-
assert_eq!(required, 1, "exactly one move can finish a won two-peg board");
487+
let required = verdicts
488+
.iter()
489+
.filter(|(_, v)| *v == Verdict::Required)
490+
.count();
491+
assert_eq!(
492+
required, 1,
493+
"exactly one move can finish a won two-peg board"
494+
);
478495
assert_eq!(forced_moves(two_pegs, &set, &counts).len(), 1);
479496
}
480497
}

0 commit comments

Comments
 (0)