forked from jana/hanoigame
Compare commits
No commits in common. "push-svpmwwzovlor" and "main" have entirely different histories.
push-svpmw
...
main
1 changed files with 21 additions and 34 deletions
55
src/main.rs
55
src/main.rs
|
|
@ -322,8 +322,22 @@ impl<const TOWER_HEIGHT: usize> Game<TOWER_HEIGHT> {
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
struct Ordf32(f32);
|
||||||
|
impl Eq for Ordf32 {}
|
||||||
|
impl PartialOrd for Ordf32 {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Ord for Ordf32 {
|
||||||
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
|
self.0.total_cmp(&other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut states = Vec::new();
|
let mut states = Vec::new();
|
||||||
let mut todo = BinaryHeap::<((i64, i64), i64, usize)>::new();
|
let mut todo = BinaryHeap::<(Ordf32, usize, usize)>::new();
|
||||||
let mut had = HashSet::new();
|
let mut had = HashSet::new();
|
||||||
let mut ctr = 0;
|
let mut ctr = 0;
|
||||||
|
|
||||||
|
|
@ -332,7 +346,7 @@ impl<const TOWER_HEIGHT: usize> Game<TOWER_HEIGHT> {
|
||||||
parent_index: 0,
|
parent_index: 0,
|
||||||
m: Move::new(0, 0),
|
m: Move::new(0, 0),
|
||||||
});
|
});
|
||||||
todo.push(((0, 0), 1000000000, 0));
|
todo.push((Ordf32(0.0), 1000000000, 0));
|
||||||
|
|
||||||
while let Some((score, depth, state_index)) = todo.pop() {
|
while let Some((score, depth, state_index)) = todo.pop() {
|
||||||
ctr += 1;
|
ctr += 1;
|
||||||
|
|
@ -373,36 +387,8 @@ impl<const TOWER_HEIGHT: usize> Game<TOWER_HEIGHT> {
|
||||||
working_instance.towers = state.towers.clone();
|
working_instance.towers = state.towers.clone();
|
||||||
working_instance.make_move(m).unwrap();
|
working_instance.make_move(m).unwrap();
|
||||||
|
|
||||||
let brs: i64 = {
|
let num_solved = working_instance.num_solved();
|
||||||
let this = &working_instance;
|
let brs = working_instance.burried_ring_score();
|
||||||
let mut seen_bottom_rings = HashSet::new();
|
|
||||||
this.towers
|
|
||||||
.iter()
|
|
||||||
.map(|i| {
|
|
||||||
let this = &i;
|
|
||||||
let mut ring_type = None;
|
|
||||||
let mut burried_score = 0;
|
|
||||||
|
|
||||||
for ring in this.rings.iter().rev().flatten() {
|
|
||||||
if let Some(existing_ring_type) = ring_type
|
|
||||||
&& existing_ring_type != *ring
|
|
||||||
{
|
|
||||||
burried_score += 1;
|
|
||||||
}
|
|
||||||
ring_type = Some(*ring);
|
|
||||||
}
|
|
||||||
if let Some(Some(ring)) = this.rings.last() {
|
|
||||||
if seen_bottom_rings.contains(ring) {
|
|
||||||
burried_score += 1;
|
|
||||||
} else {
|
|
||||||
seen_bottom_rings.insert(ring);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
burried_score
|
|
||||||
})
|
|
||||||
.sum()
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_state_hash = hash_state(&working_instance.towers);
|
let new_state_hash = hash_state(&working_instance.towers);
|
||||||
if had.contains(&new_state_hash) {
|
if had.contains(&new_state_hash) {
|
||||||
|
|
@ -416,8 +402,9 @@ impl<const TOWER_HEIGHT: usize> Game<TOWER_HEIGHT> {
|
||||||
m,
|
m,
|
||||||
});
|
});
|
||||||
|
|
||||||
let score = (depth) - (brs);
|
let score = (num_solved as f32 * 10.0) + (-(brs as f32) * 100.0);
|
||||||
todo.push(((score, -depth), depth - 1, new_state_index));
|
|
||||||
|
todo.push((Ordf32(score), depth - 1, new_state_index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue