53836eb5f1c418323f7bf19fa821d63237c5dbf7
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 displayMessage(piece
, color
) {
66 const blackPieceToCode
= {
74 piece
= blackPieceToCode
[piece
];
76 super.displayMessage(this.message
,
77 '<span>to play:</span> ' +
78 '<span class="symb">' + piece
+ '</span>'
82 setOtherVariables(fenParsed
) {
83 super.setOtherVariables(fenParsed
);
84 this.toplay
= fenParsed
.toplay
;
85 this.message
= document
.createElement("div");
86 C
.AddClass_es(this.message
, "piece-text");
87 let container
= document
.getElementById(this.containerId
);
88 container
.appendChild(this.message
);
89 this.displayMessage(this.toplay
, fenParsed
.turn
);
92 getRandomPiece(color
) {
93 // Find pieces which can move and roll a (biased) dice
95 for (let i
=0; i
<8; i
++) {
96 for (let j
=0; j
<8; j
++) {
97 if (this.board
[i
][j
] != "" && this.getColor(i
, j
) == color
) {
98 const piece
= this.getPiece(i
, j
);
99 if (this.findDestSquares([i
, j
], {one: true}))
104 if (!this.options
["biased"])
105 canMove
= [...new Set(canMove
)];
106 return canMove
[Random
.randInt(canMove
.length
)];
109 postProcessPotentialMoves(moves
) {
110 return super.postProcessPotentialMoves(moves
).filter(m
=> {
112 (m
.appear
.length
>= 1 && m
.appear
[0].p
== this.toplay
) ||
113 (m
.vanish
.length
>= 1 && m
.vanish
[0].p
== this.toplay
)
122 playReceivedMove(moves
, callback
) {
123 this.toplay
= moves
[0].toplay
; //only one move
124 this.displayMessage(this.toplay
, C
.GetOppTurn(moves
[0].appear
[0].c
));
125 super.playReceivedMove(moves
, callback
);