1bb6f1fad7611d71cccf6dceffcef4868e6453eb
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 this.toplay
= move_s
[0].toplay
;
58 this.displayMessage(move_s
[0].toplay
,
59 C
.GetOppTurn(move_s
[0].appear
[0].c
));
60 o
.afterPlay(move_s
, newTurn
, ops
);
64 static get PieceToUnicode() {
81 displayMessage(piece
, color
) {
83 piece
= piece
.toUpperCase();
84 super.displayMessage(this.message
,
85 '<span>to play:</span> ' +
86 '<span class="symb">' + V
.PieceToUnicode
[piece
] + '</span>'
90 setOtherVariables(fenParsed
) {
91 super.setOtherVariables(fenParsed
);
92 this.toplay
= fenParsed
.toplay
;
93 this.message
= document
.createElement("div");
94 C
.AddClass_es(this.message
, "piece-text");
95 let container
= document
.getElementById(this.containerId
);
96 container
.appendChild(this.message
);
97 this.displayMessage(this.toplay
, fenParsed
.turn
);
100 getRandomPiece(color
) {
101 // Find pieces which can move and roll a (biased) dice
103 for (let i
=0; i
<8; i
++) {
104 for (let j
=0; j
<8; j
++) {
105 if (this.board
[i
][j
] != "" && this.getColor(i
, j
) == color
) {
106 const piece
= this.getPiece(i
, j
);
107 if (this.findDestSquares([i
, j
], {one: true}))
112 if (!this.options
["biased"])
113 canMove
= [...new Set(canMove
)];
114 return canMove
[Random
.randInt(canMove
.length
)];
117 postProcessPotentialMoves(moves
) {
118 return super.postProcessPotentialMoves(moves
).filter(m
=> {
120 (m
.appear
.length
>= 1 && m
.appear
[0].p
== this.toplay
) ||
121 (m
.vanish
.length
>= 1 && m
.vanish
[0].p
== this.toplay
)
130 playReceivedMove(moves
, callback
) {
131 this.toplay
= moves
[0].toplay
; //only one move
132 this.displayMessage(this.toplay
, C
.GetOppTurn(moves
[0].appear
[0].c
));
133 super.playReceivedMove(moves
, callback
);