@fortemate/dicechess-engine-wasm 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,6 +75,11 @@ const turns = DiceChess.getLegalTurnTree(dfen);
75
75
  console.log("Continuations of e2e4:", Object.keys(turns["e2e4"]));
76
76
  // e.g. ["b1a3", "b1c3", "g1e2", "g1f3", "g1h3"]
77
77
 
78
+ // The dice a legal turn can still spend: pass the rolled DFEN and the moves played since, not the
79
+ // DFEN after them, because the turn is judged as a whole. A client can dim every other die.
80
+ console.log("Playable after e2e4:", DiceChess.getPlayableDice(dfen, ["e2e4"]));
81
+ // "N"
82
+
78
83
  // 3. Apply a micro-move. applyMove preserves the active color (White), since a Dice Chess turn
79
84
  // may consist of multiple micro-moves, and keeps the dice the move did not spend ("N" here).
80
85
  // Arguments: (dfen, fromSquare, toSquare, optionalPromotionPiece)
@@ -95,6 +95,29 @@ export interface DiceChessApi {
95
95
  */
96
96
  getLegalTurnTree(dfen: string): MoveTree;
97
97
 
98
+ /**
99
+ * Returns the dice that a legal turn can still spend once `moves` have been played: those that
100
+ * at least one legal turn beginning with `moves` spends after them. A client can dim the other
101
+ * dice, which no turn left can use.
102
+ *
103
+ * The turn is judged as a whole, so pass the rolled DFEN at the start of the turn, as for
104
+ * `getLegalTurnTree`, and the UCI micro-moves played since, not the DFEN after them. `moves`
105
+ * default to none. In the start position with `QRN` this returns `"NR"`: only a knight can
106
+ * move first, but the rook can follow it.
107
+ *
108
+ * The dice come as the DFEN dice field writes them: ascending by face, in the case of the side
109
+ * to move, and a face repeated as often as the most dice showing it that one legal turn spends.
110
+ * The result is `""` when no legal turn continues: after a complete turn, a king capture
111
+ * included, and for a roll with no legal move or a DFEN without dice. It is `undefined` for an
112
+ * invalid DFEN, when `moves` is not an array of UCI strings, and when it is not the beginning
113
+ * of a legal turn.
114
+ *
115
+ * A client holding the tree needs the call only when the current node has children but no path
116
+ * below it has as many actions as there are dice left: an empty node means no die is playable,
117
+ * and a path as long as the dice left means every one of them is.
118
+ */
119
+ getPlayableDice(dfen: string, moves?: string[]): string | undefined;
120
+
98
121
  /**
99
122
  * Executes perft (performance test) counting leaf nodes at given depth.
100
123
  * @param dfen The position in DFEN notation.