make marble creation a weak claim

This commit is contained in:
Crispy 2025-03-15 20:13:48 +01:00
parent e7f424aadc
commit fa10b38f99
2 changed files with 41 additions and 28 deletions

View file

@ -261,19 +261,14 @@ impl Machine {
let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else {
unreachable!()
};
*claim = match claim {
Claim::Free => {
claim_positions.push(pos);
Claim::Claimed
}
Claim::Claimed | Claim::Blocked => Claim::Blocked,
_ => unreachable!(),
if claim.claim_indirect() {
claim_positions.push(pos);
}
}
// create new marbles
// new marbles are past old_marbles index, so will not move this step
for (pos, value, dir) in new_marbles {
let Some(Tile::Open(OpenTile::Blank, Claim::Claimed)) = self.board.get_mut(pos) else {
let Some(Tile::Open(OpenTile::Blank, Claim::ClaimedIndirect)) = self.board.get_mut(pos) else {
continue;
};
self.board.set(pos, Tile::Marble { value, dir });
@ -291,16 +286,9 @@ impl Machine {
continue;
};
if let Tile::Open(_type, claim) = front_tile {
*claim = match claim {
Claim::Free => {
claim_positions.push(front_pos);
Claim::Claimed
}
Claim::ClaimedIndirect => Claim::Claimed,
Claim::BlockedIndirect => Claim::Claimed,
Claim::Claimed => Claim::Blocked,
Claim::Blocked => Claim::Blocked,
};
if claim.claim() {
claim_positions.push(front_pos);
}
} else {
let target_pos = match front_tile {
Tile::Arrow(d) => d.step(front_pos),
@ -312,16 +300,9 @@ impl Machine {
continue;
};
if let Tile::Open(_type, claim) = target_tile {
*claim = match claim {
Claim::Free => {
claim_positions.push(front_pos);
Claim::ClaimedIndirect
}
Claim::ClaimedIndirect => Claim::BlockedIndirect,
Claim::BlockedIndirect => Claim::BlockedIndirect,
Claim::Claimed => Claim::Claimed,
Claim::Blocked => Claim::Blocked,
};
if claim.claim_indirect() {
claim_positions.push(front_pos);
}
}
}
}

View file

@ -485,3 +485,35 @@ impl Comparison {
}
}
}
impl Claim {
#[must_use]
/// returns `was_free`
pub fn claim(&mut self) -> bool {
let mut was_free = false;
*self = match self {
Claim::Free => {
was_free = true;
Claim::Claimed
}
Claim::ClaimedIndirect | Claim::BlockedIndirect => Claim::Claimed,
Claim::Claimed | Claim::Blocked => Claim::Blocked,
};
was_free
}
#[must_use]
/// returns `was_free`
pub fn claim_indirect(&mut self) -> bool {
let mut was_free = false;
*self = match self {
Claim::Free => {
was_free = true;
Claim::ClaimedIndirect
}
Claim::ClaimedIndirect => Claim::BlockedIndirect,
_ => *self,
};
was_free
}
}