summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/game.rs b/src/game.rs
index 4cb6fdd..99704b1 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -85,8 +85,8 @@ impl fmt::Display for Action {
Action::Place(_, pos, stone) => write!(f, "{}{}", stone, pos),
Action::Move(_, pos, direction, drops) => write!(
f,
- "{}{}{}{}",
- drops.iter().map(|&d| d as u32).sum::<u32>(),
+ "{}{}{}",
+ // drops.iter().map(|&d| d as u32).sum::<u32>(),
pos,
direction,
drops.into_iter().map(|q| q.to_string()).collect::<String>()
@@ -409,14 +409,15 @@ impl GameState {
let idx = copy.pos_to_idx(&pos);
let stack: &Stack = &self.board[self.pos_to_idx(pos)];
- let len = copy.board[idx].len();
+ let stack_height = copy.board[idx].len();
let mut offset = 0;
- if len > self.size as usize {
- for _i in 0..self.size {
+ let carry_capacity = self.size as usize;
+ if stack_height > carry_capacity {
+ for _i in 0..carry_capacity {
copy.board[idx].pop();
}
- offset = self.size - 1;
+ offset = stack_height - carry_capacity;
} else {
copy.board[idx].clear();
}
@@ -425,10 +426,19 @@ impl GameState {
for drop_idx in 0..num_drops {
let pos = pos_vec[pos_vec.len() - 1];
let idx = copy.pos_to_idx(&pos);
- let num = drops[drop_idx];
+ let num = drops[drop_idx] as usize;
for i in 0..num {
- copy.board[idx].push(stack[(offset + i) as usize]);
+ // Are we flattening?
+ if stack[offset + i].stone == Stone::Capstone {
+ if let Some(top_piece) = copy.board[idx].last() {
+ if top_piece.stone == Stone::Standing {
+ let top_stone_idx = copy.board[idx].len() - 1;
+ copy.board[idx][top_stone_idx].stone = Stone::Flat;
+ }
+ }
+ }
+ copy.board[idx].push(stack[offset + i]);
}
offset += num;