02e4f6d2a9fc2597a42d338bd286bd812cb2e4f9
1 import ChessRules
from "/base_rules.js";
2 import {Random
} from "/utils/alea.js";
4 export default class DiceRules
extends ChessRules
{
8 res
.select
["defaut"] = 2;
19 label: "Falling pawn",
41 let canMove
= (this.options
["biased"]
42 ? Array(8).fill('p').concat(Array(2).fill('n'))
44 toplay
= canMove
[Random
.randInt(canMove
.length
)];
47 { toplay: (o
.init
? toplay : this.getRandomPiece(this.turn
)) },
54 this.afterPlay
= (move_s
, newTurn
, ops
) => {
55 // Movestack contains only one move:
56 move_s
[0].toplay
= this.getRandomPiece(this.turn
);
58 this.message
, "To play: " + move_s
[0].toplay
.toUpperCase());
59 o
.afterPlay(move_s
, newTurn
, ops
);
63 setOtherVariables(fenParsed
) {
64 super.setOtherVariables(fenParsed
);
65 this.toplay
= fenParsed
.toplay
;
66 this.message
= document
.createElement("div");
67 C
.AddClass_es(this.message
, "piece-text");
68 this.message
.innerHTML
= "To play: " + this.toplay
.toUpperCase();
69 let container
= document
.getElementById(this.containerId
);
70 container
.appendChild(this.message
);
73 getRandomPiece(color
) {
74 // Find pieces which can move and roll a (biased) dice
76 for (let i
=0; i
<8; i
++) {
77 for (let j
=0; j
<8; j
++) {
78 if (this.board
[i
][j
] != "" && this.getColor(i
, j
) == color
) {
79 const piece
= this.getPiece(i
, j
);
80 if (this.findDestSquares([i
, j
], {one: true}))
85 if (!this.options
["biased"])
86 canMove
= [...new Set(canMove
)];
87 return canMove
[Random
.randInt(canMove
.length
)];
90 postProcessPotentialMoves(moves
) {
91 return super.postProcessPotentialMoves(moves
).filter(m
=> {
93 (m
.appear
.length
>= 1 && m
.appear
[0].p
== this.toplay
) ||
94 (m
.vanish
.length
>= 1 && m
.vanish
[0].p
== this.toplay
)
103 playReceivedMove(moves
, callback
) {
104 this.toplay
= moves
[0].toplay
; //only one move
105 super.displayMessage(
106 this.message
, "To play: " + this.toplay
.toUpperCase());
107 super.playReceivedMove(moves
, callback
);