Implement blocking.
This commit is contained in:
parent
dc4827c982
commit
fd1d99dd77
@ -76,6 +76,7 @@ GAME.Board = class {
|
|||||||
reset() {
|
reset() {
|
||||||
for(let i = 0; i < this.tiles.length; ++i) { this.tiles[i].reset(); }
|
for(let i = 0; i < this.tiles.length; ++i) { this.tiles[i].reset(); }
|
||||||
for(let i = 0; i < this.columns.length; ++i) { this.columns[i].reset(); }
|
for(let i = 0; i < this.columns.length; ++i) { this.columns[i].reset(); }
|
||||||
|
for(let i = 0; i < this.pieces.length; ++i) { if(this.pieces[i] !== null) { this.pieces[i].reset(); } }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,11 +115,12 @@ GAME.Tile = class {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GAME.MovementTile = class {
|
GAME.MovementTile = class {
|
||||||
constructor(tile, valid, threat, check) {
|
constructor(tile, valid, threat, check, block) {
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
this.valid = valid;
|
this.valid = valid;
|
||||||
this.threat = threat;
|
this.threat = threat;
|
||||||
this.check = check;
|
this.check = check;
|
||||||
|
this.block = block;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -235,6 +237,9 @@ GAME.Game = class {
|
|||||||
this.board.tiles[movement.tile].checking = true;
|
this.board.tiles[movement.tile].checking = true;
|
||||||
this.state.check = true;
|
this.state.check = true;
|
||||||
}
|
}
|
||||||
|
if(movement.block != 0) {
|
||||||
|
this.board.pieces[this.board.tiles[movement.tile].piece].blocking = movement.block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,12 +348,12 @@ GAME.Game = class {
|
|||||||
|
|
||||||
let directions = moves.direction;
|
let directions = moves.direction;
|
||||||
let permitted_moves = directions;
|
let permitted_moves = directions;
|
||||||
if(piece.blocking != 0) {
|
let block_directions = piece.blocking;
|
||||||
if(piece.piece == GAME.Const.PieceId.Omen) {
|
if(block_directions != 0) {
|
||||||
permitted_moves &= ~piece.blocking;
|
block_directions |= BITWISE.rotate_blocks(piece.blocking);
|
||||||
} else {
|
//if(piece.piece != GAME.Const.PieceId.Omen) {
|
||||||
permitted_moves &= piece.blocking;
|
// permitted_moves &= piece.blocking;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check directions of movement.
|
// Check directions of movement.
|
||||||
@ -359,6 +364,7 @@ GAME.Game = class {
|
|||||||
|
|
||||||
// Get initial status in direction.
|
// Get initial status in direction.
|
||||||
let valid = (permitted_moves & mask) != 0;
|
let valid = (permitted_moves & mask) != 0;
|
||||||
|
let pieces_blocking = 0;
|
||||||
|
|
||||||
let move_hex = hex.copy();
|
let move_hex = hex.copy();
|
||||||
|
|
||||||
@ -369,6 +375,9 @@ GAME.Game = class {
|
|||||||
|
|
||||||
let threat = valid;
|
let threat = valid;
|
||||||
let check = false;
|
let check = false;
|
||||||
|
let block = 0;
|
||||||
|
let swap = false;
|
||||||
|
let tile_occupied = false;
|
||||||
|
|
||||||
if(HEX.is_valid(move_hex)) {
|
if(HEX.is_valid(move_hex)) {
|
||||||
let tile_id = HEX.hex_to_tile(move_hex);
|
let tile_id = HEX.hex_to_tile(move_hex);
|
||||||
@ -376,6 +385,7 @@ GAME.Game = class {
|
|||||||
|
|
||||||
let result = valid;
|
let result = valid;
|
||||||
|
|
||||||
|
// Prevent moves that do not uncheck the King.
|
||||||
if(piece.player == (this.turn & 1)
|
if(piece.player == (this.turn & 1)
|
||||||
&& this.state.check && !tile_data.checking
|
&& this.state.check && !tile_data.checking
|
||||||
&& piece.piece != GAME.Const.PieceId.Omen) {
|
&& piece.piece != GAME.Const.PieceId.Omen) {
|
||||||
@ -390,12 +400,15 @@ GAME.Game = class {
|
|||||||
// Handle occupied tile.
|
// Handle occupied tile.
|
||||||
if(tile_data.piece !== null) {
|
if(tile_data.piece !== null) {
|
||||||
let target = this.board.pieces[tile_data.piece];
|
let target = this.board.pieces[tile_data.piece];
|
||||||
|
tile_occupied = true;
|
||||||
|
|
||||||
// Target piece is ally.
|
// Target piece is ally.
|
||||||
if(target.player == piece.player) {
|
if(target.player == piece.player) {
|
||||||
|
|
||||||
// Move is only valid if pieces are swappable.
|
// Move is only valid if pieces are swappable.
|
||||||
if(!this.movement_swappable(piece, target, mask, dist, tile)) {
|
if(this.movement_swappable(piece, target, mask, dist, tile)) {
|
||||||
|
swap = true;
|
||||||
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
valid = false;
|
valid = false;
|
||||||
@ -407,18 +420,39 @@ GAME.Game = class {
|
|||||||
if(target.piece == GAME.Const.PieceId.Omen) {
|
if(target.piece == GAME.Const.PieceId.Omen) {
|
||||||
if(valid) {
|
if(valid) {
|
||||||
check = true;
|
check = true;
|
||||||
|
block = mask;
|
||||||
|
|
||||||
// Apply check to previous moves.
|
// Apply check to previous moves.
|
||||||
for(let idist = 1; idist < dist; idist++) {
|
for(let idist = 1; idist < dist; idist++) {
|
||||||
tiles[tiles.length - idist].check = true;
|
tiles[tiles.length - idist].check = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pieces_blocking == 1) {
|
||||||
|
// Apply blocking to last .
|
||||||
|
for(let idist = 1; idist < dist; idist++) {
|
||||||
|
if(GAME_DATA.board.tiles[tiles[tiles.length - idist].tile].piece !== null) {
|
||||||
|
tiles[tiles.length - idist].block = mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pieces_blocking += 1;
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles.push(new GAME.MovementTile(tile_id, result, threat, check));
|
// Handle blocking restrictions.
|
||||||
|
if(block_directions != 0) {
|
||||||
|
if(piece.piece == GAME.Const.PieceId.Omen) {
|
||||||
|
result = result && ((mask & block_directions) == 0 || tile_occupied);
|
||||||
|
} else {
|
||||||
|
result = result && ((mask & block_directions) != 0 || swap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles.push(new GAME.MovementTile(tile_id, result, threat, check, block));
|
||||||
} else { break; }
|
} else { break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +472,8 @@ GAME.Game = class {
|
|||||||
|
|
||||||
// King cannot swap onto tile that is threatened.
|
// King cannot swap onto tile that is threatened.
|
||||||
// This case should also cover blocking.
|
// This case should also cover blocking.
|
||||||
if(target.piece == GAME.Const.PieceId.Omen && this.board.tiles[tile].threaten[+(!target.player)]) {
|
if(target.piece == GAME.Const.PieceId.Omen
|
||||||
|
&& (this.board.tiles[tile].threaten[+(!target.player)] || piece.blocking != 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ((moves.direction & mask) != 0 && (range == 1 || (moves.stride & mask) != 0));
|
return ((moves.direction & mask) != 0 && (range == 1 || (moves.stride & mask) != 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user