forked from jana/hanoigame
fix bugs
This commit is contained in:
parent
4f7790d1d5
commit
1e3fca6f51
3 changed files with 38 additions and 1752 deletions
1754
Cargo.lock
generated
1754
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,7 +4,6 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
palette = {path="./palette", default-features = false, features=["libm"]}
|
||||
palette = "0.7"
|
||||
|
||||
[workspace]
|
||||
members = ["palette", "palette_derive"]
|
||||
|
|
|
|||
33
src/main.rs
33
src/main.rs
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
fmt::Display,
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
io::{self, Write, stdin, stdout},
|
||||
iter,
|
||||
num::{self, NonZero},
|
||||
ops::ControlFlow,
|
||||
};
|
||||
|
|
@ -643,6 +644,7 @@ enum Input {
|
|||
Undo,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct GameGenerator {
|
||||
pub num_extra_towers: usize,
|
||||
pub num_ring_types: usize,
|
||||
|
|
@ -671,6 +673,14 @@ impl GameGenerator {
|
|||
|
||||
Game::new(towers)
|
||||
}
|
||||
|
||||
pub fn highest_burried_score<const TOWER_HEIGHT: usize>(self) -> Game<TOWER_HEIGHT> {
|
||||
iter::repeat(self)
|
||||
.map(|i| i.generate())
|
||||
.take(100)
|
||||
.max_by_key(|i| i.burried_ring_score())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<const TOWER_HEIGHT: usize> Display for Game<TOWER_HEIGHT> {
|
||||
|
|
@ -702,11 +712,11 @@ impl<const TOWER_HEIGHT: usize> Display for Game<TOWER_HEIGHT> {
|
|||
let num = format!(" {} ", t + 1);
|
||||
write!(f, "{num:━^13}")?;
|
||||
}
|
||||
writeln!(f)?;
|
||||
for t in 0..self.towers.len() {
|
||||
let num = format!(" {} ", self.towers[t].burried_score());
|
||||
write!(f, "{num:^13}")?;
|
||||
}
|
||||
// writeln!(f)?;
|
||||
// for t in 0..self.towers.len() {
|
||||
// let num = format!(" {} ", self.towers[t].burried_score());
|
||||
// write!(f, "{num:^13}")?;
|
||||
// }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -742,9 +752,9 @@ impl<const TOWER_HEIGHT: usize> UndoStack<TOWER_HEIGHT> {
|
|||
fn main() -> io::Result<()> {
|
||||
let mut g = GameGenerator {
|
||||
num_extra_towers: 2,
|
||||
num_ring_types: 12,
|
||||
num_ring_types: 13,
|
||||
}
|
||||
.generate::<4>();
|
||||
.highest_burried_score::<4>();
|
||||
|
||||
if let Some(solution) = g.solve() {
|
||||
let mut g = Game {
|
||||
|
|
@ -758,11 +768,14 @@ fn main() -> io::Result<()> {
|
|||
stdout().flush().unwrap();
|
||||
stdin().read_line(&mut String::new()).unwrap();
|
||||
}
|
||||
} else {
|
||||
println!("no solution");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// println!("{CLEAR_SCREEN}");
|
||||
// let mut u = UndoStack::new();
|
||||
// while let ControlFlow::Continue(()) = g.cli_move(&mut u)? {}
|
||||
println!("{CLEAR_SCREEN}");
|
||||
let mut u = UndoStack::new();
|
||||
while let ControlFlow::Continue(()) = g.cli_move(&mut u)? {}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue