8c3eed4699dc0c6e9f890c084ba490d4987b13d4
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
);
57 super.displayMessage(this.message
, move_s
[0].toplay
);
58 o
.afterPlay(move_s
, newTurn
, ops
);
62 setOtherVariables(fenParsed
) {
63 super.setOtherVariables(fenParsed
);
64 this.toplay
= fenParsed
.toplay
;
65 this.message
= document
.createElement("div");
66 C
.AddClass_es(this.message
, "piece-text");
67 this.message
.innerHTML
= this.toplay
;
68 let container
= document
.getElementById(this.containerId
);
69 container
.appendChild(this.message
);
72 getRandomPiece(color
) {
73 // Find pieces which can move and roll a (biased) dice
75 for (let i
=0; i
<8; i
++) {
76 for (let j
=0; j
<8; j
++) {
77 if (this.board
[i
][j
] != "" && this.getColor(i
, j
) == color
) {
78 const piece
= this.getPiece(i
, j
);
79 if (this.findDestSquares([i
, j
], {one: true}))
84 if (!this.options
["biased"])
85 canMove
= [...new Set(canMove
)];
86 return canMove
[Random
.randInt(canMove
.length
)];
89 postProcessPotentialMoves(moves
) {
90 return super.postProcessPotentialMoves(moves
).filter(m
=> {
92 (m
.appear
.length
>= 1 && m
.appear
[0].p
== this.toplay
) ||
93 (m
.vanish
.length
>= 1 && m
.vanish
[0].p
== this.toplay
)
102 playReceivedMove(moves
, callback
) {
103 this.toplay
= moves
[0].toplay
; //only one move
104 super.displayMessage(this.message
, this.toplay
);
105 super.playReceivedMove(moves
, callback
);