diff --git a/game/src/game/mod.rs b/game/src/game/mod.rs index 4cbca3f..0011a13 100644 --- a/game/src/game/mod.rs +++ b/game/src/game/mod.rs @@ -2,7 +2,7 @@ use crate::{ //consts::*, board::Board, history::Play, - piece::Piece, + piece::Piece, util::Hex, }; pub type Pool = [u8; 7]; @@ -91,6 +91,13 @@ impl Game { piece.tile = play.to; self.board.pieces[pid as usize] = Some(piece); + + // Check if piece is promoted. + let hex = Hex::from_tile(play.from); + let offset = (piece.player as i8 * 2) - 1; + if !piece.promoted && !Hex::is_valid(hex.x() as i8, hex.y() as i8 + offset) { + piece.promoted = true; + } true } else { false } } else { false } diff --git a/game/src/util/hex.rs b/game/src/util/hex.rs index 8b5503d..fda692f 100644 --- a/game/src/util/hex.rs +++ b/game/src/util/hex.rs @@ -41,6 +41,27 @@ impl Hex { } } + pub fn is_valid(x:i8, y:i8) -> bool + { + const COLUMNS :[(i8, i8); 9] = [ + (0, 4), + (0, 5), + (0, 6), + (0, 7), + (0, 8), + (1, 8), + (2, 8), + (3, 8), + (4, 8), + ]; + + let valid = x >= 0 && x < 9; + if valid { + let (min, max) = COLUMNS[x as usize]; + y >= min && y <= max + } else { false } + } + pub fn x(&self) -> u8 { self.x } pub fn y(&self) -> u8 { self.y } pub fn tile(&self) -> u8 { self.tile } diff --git a/www/js/scene.js b/www/js/scene.js index 1006392..754425e 100644 --- a/www/js/scene.js +++ b/www/js/scene.js @@ -15,6 +15,9 @@ const SCENES = { ], []); return true; }, + reconnect() { + LOAD(CONTEXT.Scene); + } }, Register:{ diff --git a/www/js/system.js b/www/js/system.js index 54e7bcf..6f54c73 100644 --- a/www/js/system.js +++ b/www/js/system.js @@ -35,7 +35,7 @@ function RESUME() { CONTEXT.Auth.secret, ]); } else { - LOAD(CONTEXT.Scene); + if(SCENE.reconnect !== undefined) { SCENE.reconnect(); } } }