Fix practice reset button; update knight moves.

This commit is contained in:
yukirij 2024-08-18 01:39:14 -07:00
parent e3def36694
commit 83b996e01c
2 changed files with 21 additions and 24 deletions

View File

@ -133,7 +133,7 @@ GAME.Play = class {
}; };
GAME.GamePiece = class { GAME.GamePiece = class {
constructor(name, moves, promote_moves) { constructor(name, moves, promote_moves=null) {
this.name = name; this.name = name;
this.moves = moves; this.moves = moves;
this.pmoves = promote_moves; this.pmoves = promote_moves;
@ -176,9 +176,10 @@ GAME.Piece = class {
} }
moves() { moves() {
let def = GAME.Const.Piece[this.piece];
let moves = null; let moves = null;
if(this.promoted) { moves = GAME.Const.Piece[this.piece].pmoves; } if(this.promoted && def.pmoves !== null) { moves = def.pmoves; }
else { moves = GAME.Const.Piece[this.piece].moves; } else { moves = def.moves; }
if(this.player == GAME.Const.Player.Dusk) { moves = moves.rotate(); } if(this.player == GAME.Const.Player.Dusk) { moves = moves.rotate(); }
return moves; return moves;
} }
@ -627,6 +628,16 @@ GAME.Const = {
new GAME.GamePiece( new GAME.GamePiece(
"Knight", "Knight",
new GAME.PieceMovement() new GAME.PieceMovement()
.add(17)
.add(12)
.add(17)
.add(18)
.add(23)
.add(25)
.add(26)
.add(28)
.add(29),
/*new GAME.PieceMovement()
.add(12) .add(12)
.add(13) .add(13)
.add(14) .add(14)
@ -638,23 +649,7 @@ GAME.Const = {
.add(20) .add(20)
.add(21) .add(21)
.add(22) .add(22)
.add(23), .add(23),*/
new GAME.PieceMovement()
.add(1)
.add(3)
.add(5)
.add(12)
.add(13)
.add(14)
.add(15)
.add(16)
.add(17)
.add(18)
.add(19)
.add(20)
.add(21)
.add(22)
.add(23),
), ),
new GAME.GamePiece( new GAME.GamePiece(
"Tower", "Tower",

View File

@ -589,14 +589,15 @@ const INTERFACE = {
hints(piece) { hints(piece) {
let descriptor = GAME.Const.Piece[piece.piece]; let descriptor = GAME.Const.Piece[piece.piece];
let moves = descriptor.moves; let moves = piece.moves();
if(piece.promoted) { moves = descriptor.pmoves; } //if(((piece.player ^ INTERFACE_DATA.player ^ INTERFACE_DATA.rotate) & 1) != 0) { moves = moves.rotate(); }
if(((piece.player ^ INTERFACE_DATA.player ^ INTERFACE_DATA.rotate) & 1) != 0) { moves = moves.rotate(); }
moves = moves.direction; moves = moves.direction;
for(let mask = BITWISE.lsb(moves); moves > 0; mask = BITWISE.lsb(moves)) { for(let mask = BITWISE.lsb(moves); moves > 0; mask = BITWISE.lsb(moves)) {
let move = BITWISE.ffs(mask); let move = BITWISE.ffs(mask);
if(move >= 12) { if(move >= 24) {
move -= 24;
} else if(move >= 12) {
move = Math.floor((move - 12) / 2) + 6; move = Math.floor((move - 12) / 2) + 6;
} }
@ -763,6 +764,7 @@ const INTERFACE = {
GAME.init(); GAME.init();
INTERFACE_DATA.player = 0; INTERFACE_DATA.player = 0;
INTERFACE_DATA.rotate = 0; INTERFACE_DATA.rotate = 0;
INTERFACE.draw();
}, },
message(code, data) { message(code, data) {