make marble creation a weak claim
This commit is contained in:
parent
e7f424aadc
commit
fa10b38f99
2 changed files with 41 additions and 28 deletions
|
@ -261,19 +261,14 @@ impl Machine {
|
||||||
let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else {
|
let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
*claim = match claim {
|
if claim.claim_indirect() {
|
||||||
Claim::Free => {
|
claim_positions.push(pos);
|
||||||
claim_positions.push(pos);
|
|
||||||
Claim::Claimed
|
|
||||||
}
|
|
||||||
Claim::Claimed | Claim::Blocked => Claim::Blocked,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create new marbles
|
// create new marbles
|
||||||
// new marbles are past old_marbles index, so will not move this step
|
// new marbles are past old_marbles index, so will not move this step
|
||||||
for (pos, value, dir) in new_marbles {
|
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;
|
continue;
|
||||||
};
|
};
|
||||||
self.board.set(pos, Tile::Marble { value, dir });
|
self.board.set(pos, Tile::Marble { value, dir });
|
||||||
|
@ -291,16 +286,9 @@ impl Machine {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Tile::Open(_type, claim) = front_tile {
|
if let Tile::Open(_type, claim) = front_tile {
|
||||||
*claim = match claim {
|
if claim.claim() {
|
||||||
Claim::Free => {
|
claim_positions.push(front_pos);
|
||||||
claim_positions.push(front_pos);
|
}
|
||||||
Claim::Claimed
|
|
||||||
}
|
|
||||||
Claim::ClaimedIndirect => Claim::Claimed,
|
|
||||||
Claim::BlockedIndirect => Claim::Claimed,
|
|
||||||
Claim::Claimed => Claim::Blocked,
|
|
||||||
Claim::Blocked => Claim::Blocked,
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
let target_pos = match front_tile {
|
let target_pos = match front_tile {
|
||||||
Tile::Arrow(d) => d.step(front_pos),
|
Tile::Arrow(d) => d.step(front_pos),
|
||||||
|
@ -312,16 +300,9 @@ impl Machine {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Tile::Open(_type, claim) = target_tile {
|
if let Tile::Open(_type, claim) = target_tile {
|
||||||
*claim = match claim {
|
if claim.claim_indirect() {
|
||||||
Claim::Free => {
|
claim_positions.push(front_pos);
|
||||||
claim_positions.push(front_pos);
|
}
|
||||||
Claim::ClaimedIndirect
|
|
||||||
}
|
|
||||||
Claim::ClaimedIndirect => Claim::BlockedIndirect,
|
|
||||||
Claim::BlockedIndirect => Claim::BlockedIndirect,
|
|
||||||
Claim::Claimed => Claim::Claimed,
|
|
||||||
Claim::Blocked => Claim::Blocked,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue