Fix bitwise block rotation for new stride format.

This commit is contained in:
yukirij 2024-09-03 17:35:29 -07:00
parent 24e5e9d609
commit bbeed407bb
2 changed files with 22 additions and 8 deletions

View File

@ -192,8 +192,8 @@ GAME.PieceMovement = class {
rotate() {
let copy = new GAME.PieceMovement();
copy.direction = BITWISE.rotate_blocks(this.direction);
copy.stride = BITWISE.rotate_blocks(this.stride);
copy.direction = BITWISE.rotate_blocks6(this.direction);
copy.stride = BITWISE.rotate_blocks12(this.stride);
copy.alt = this.alt;
return copy;
}
@ -425,7 +425,7 @@ GAME.Game = class {
let hex = this.board.tiles[tile].hex;
let directions = moves.direction;
let block_directions = piece.blocking | BITWISE.rotate_blocks(piece.blocking);
let block_directions = piece.blocking | BITWISE.rotate_blocks6(piece.blocking);
// Check directions of movement.
for(let mask = BITWISE.lsb(directions); directions > 0; mask = BITWISE.lsb(directions)) {
@ -565,7 +565,7 @@ GAME.Game = class {
return false;
}
mask = BITWISE.rotate_blocks(mask);
mask = BITWISE.rotate_blocks6(mask);
let moves = target.moves();
// King cannot swap onto tile that is threatened.
@ -582,7 +582,7 @@ GAME.Game = class {
if(piece.promoted) {
let hex = this.board.tiles[piece.tile].hex;
let block_directions = piece.blocking | BITWISE.rotate_blocks(piece.blocking);
let block_directions = piece.blocking | BITWISE.rotate_blocks6(piece.blocking);
switch(piece.piece) {
case GAME.Const.PieceId.Knight: {
@ -629,9 +629,9 @@ GAME.Game = class {
case GAME.Const.PieceId.Castle: {
let mask_back = 1 << 3;
if(piece.player == GAME.Const.Player.Dusk) {
mask_back = BITWISE.rotate_blocks(mask_back);
mask_back = BITWISE.rotate_blocks6(mask_back);
}
let mask_column = mask_back | BITWISE.rotate_blocks(mask_back);
let mask_column = mask_back | BITWISE.rotate_blocks6(mask_back);
let direction = GAME.Const.get_direction(BITWISE.ffs(mask_back));
let move_hex = hex.copy();

View File

@ -159,7 +159,7 @@ const BITWISE = {
return ((mask + (mask >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
},
rotate_blocks(mask)
rotate_blocks6(mask)
{
const r1 = 0x00003F; // first 6 bits
const r2 = 0x000FC0; // second 6 bits
@ -175,6 +175,20 @@ const BITWISE = {
return v1 | v2 | v3;
},
rotate_blocks12(mask)
{
const r1 = 0x00000FFF; // first 12 bits
const r2 = 0x00FFF000; // second 12 bits
let v1 = (r1 & mask) << 6;
let v2 = (r2 & mask) << 6;
v1 = (v1 & r1) | ((v1 & ~r1) >> 12);
v2 = (v2 & r2) | ((v2 & ~r2) >> 12);
return v1 | v2;
},
};
const MATH = {