From 156986e6b06dc5f0acd39860bd4fef6b030e263b Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Fri, 3 Apr 2020 15:02:04 +0200
Subject: [PATCH] Fix Dynamo FEN + computer play

---
 client/src/base_rules.js      |  2 +-
 client/src/variants/Dynamo.js | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/client/src/base_rules.js b/client/src/base_rules.js
index 1a4a32d9..167be91f 100644
--- a/client/src/base_rules.js
+++ b/client/src/base_rules.js
@@ -966,7 +966,7 @@ export const ChessRules = class ChessRules {
     let potentialMoves = [];
     for (let i = 0; i < V.size.x; i++) {
       for (let j = 0; j < V.size.y; j++) {
-        if (this.getColor(i, j) == color) {
+        if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == color) {
           Array.prototype.push.apply(
             potentialMoves,
             this.getPotentialMovesFrom([i, j])
diff --git a/client/src/variants/Dynamo.js b/client/src/variants/Dynamo.js
index f7d60240..91920e07 100644
--- a/client/src/variants/Dynamo.js
+++ b/client/src/variants/Dynamo.js
@@ -88,7 +88,7 @@ export class DynamoRules extends ChessRules {
     return (
       ["appear","vanish"].map(
         mpart => {
-          if (mpart.length == 0) return "-";
+          if (this.amoves[L-1][mpart].length == 0) return "-";
           return (
             this.amoves[L-1][mpart].map(
               av => {
@@ -479,6 +479,22 @@ export class DynamoRules extends ChessRules {
     return false;
   }
 
+  // No consideration of color: all pieces could be played
+  getAllPotentialMoves() {
+    let potentialMoves = [];
+    for (let i = 0; i < V.size.x; i++) {
+      for (let j = 0; j < V.size.y; j++) {
+        if (this.board[i][j] != V.EMPTY) {
+          Array.prototype.push.apply(
+            potentialMoves,
+            this.getPotentialMovesFrom([i, j])
+          );
+        }
+      }
+    }
+    return potentialMoves;
+  }
+
   getCurrentScore() {
     if (this.subTurn == 2)
       // Move not over
-- 
2.44.0