From 006c778a7d68e01f635d3d8faa74284512842356 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Thu, 30 Jun 2022 21:44:24 +0200
Subject: [PATCH] Complete Antiking, add Antimatter

---
 variants.js                    |  2 +-
 variants/Antimatter/class.js   | 29 +++++++++++++++++++++++++++++
 variants/Antimatter/rules.html |  3 +++
 variants/Antimatter/style.css  |  1 +
 variants/_Antiking/class.js    | 14 +++-----------
 variants/_Antiking/rules.html  | 26 +++++++++++++++++++++++++-
 6 files changed, 62 insertions(+), 13 deletions(-)
 create mode 100644 variants/Antimatter/class.js
 create mode 100644 variants/Antimatter/rules.html
 create mode 100644 variants/Antimatter/style.css

diff --git a/variants.js b/variants.js
index 3705c59..4108165 100644
--- a/variants.js
+++ b/variants.js
@@ -7,7 +7,7 @@ const variants = [
   {name: 'Ambiguous', desc: "Play opponent's pieces"},
   {name: 'Antiking1', desc: 'Keep antiking in check', disp: 'Anti-King I'},
   {name: 'Antiking2', desc: 'Keep antiking in check', disp: 'Anti-King II'},
-//  {name: 'Antimatter', desc: 'Dangerous collisions'},
+  {name: 'Antimatter', desc: 'Dangerous collisions'},
 //  {name: 'Apocalypse', desc: 'The end of the world'},
 //  {name: 'Arena', desc: 'Middle battle'},
 //  {name: 'Atarigo', desc: 'First capture wins', disp: 'Atari-Go'},
diff --git a/variants/Antimatter/class.js b/variants/Antimatter/class.js
new file mode 100644
index 0000000..b71abf7
--- /dev/null
+++ b/variants/Antimatter/class.js
@@ -0,0 +1,29 @@
+import ChessRules from "/base_rules.js";
+
+export default class AntimatterRules extends ChessRules {
+
+  static get Options() {
+    return {
+      select: C.Options.select,
+      input: C.Options.input,
+      styles: C.Options.styles.filter(s => !["atomic", "madrasi"].includes(s))
+    };
+  }
+
+  getPotentialMovesFrom([x, y]) {
+    let moves = super.getPotentialMovesFrom([x, y]);
+    // Handle "matter collisions"
+    moves.forEach(m => {
+      if (
+        m.vanish.length == 2 &&
+        m.appear.length == 1 &&
+        m.vanish[0].p == m.vanish[1].p &&
+        m.vanish[0].c != m.vanish[1].c //for Recycle & Teleport
+      ) {
+        m.appear.pop();
+      }
+    });
+    return moves;
+  }
+
+};
diff --git a/variants/Antimatter/rules.html b/variants/Antimatter/rules.html
new file mode 100644
index 0000000..78d8f29
--- /dev/null
+++ b/variants/Antimatter/rules.html
@@ -0,0 +1,3 @@
+<p>If a piece captures one of the same kind, both disappear.</p>
+
+<p class="author">Claudio Martins Jaguaribe (2010).</p>
diff --git a/variants/Antimatter/style.css b/variants/Antimatter/style.css
new file mode 100644
index 0000000..a3550bc
--- /dev/null
+++ b/variants/Antimatter/style.css
@@ -0,0 +1 @@
+@import url("/base_pieces.css");
diff --git a/variants/_Antiking/class.js b/variants/_Antiking/class.js
index e92edab..8e2173a 100644
--- a/variants/_Antiking/class.js
+++ b/variants/_Antiking/class.js
@@ -26,17 +26,9 @@ export default class AbstractAntikingRules extends ChessRules {
   }
 
   pieces(color, x, y) {
-    return Object.assign(
-      {
-        'a': {
-          // Move like a king, no attacks
-          "class": "antiking",
-          moves: super.pieces(color, x, y)['k'].moves,
-          attack: []
-        }
-      },
-      super.pieces(color, x, y)
-    );
+    let antikingSpec = super.pieces(color, x, y)['k'];
+    antikingSpec["class"] = "antiking";
+    return Object.assign({'a': antikingSpec}, super.pieces(color, x, y));
   }
 
   isKing(x, y, p) {
diff --git a/variants/_Antiking/rules.html b/variants/_Antiking/rules.html
index fee723a..e850c5e 100644
--- a/variants/_Antiking/rules.html
+++ b/variants/_Antiking/rules.html
@@ -1 +1,25 @@
-https://www.chessvariants.com/diffobjective.dir/anti-king-chess.html
+<p>
+  The antiking (represented by an upside-down king)
+  must always remain under attack.
+  It can capture pieces of its color.
+</p>
+
+<p>
+  Win by checkmating the king, or anti-mating the antiking &mdash; that is to
+  say, making it unable to move to an attacked square.
+</p>
+
+<p>In Anti-King I,</p>
+<ul>
+  <li>Pawns are Berolina: they move diagonally and capture vertically.</li>
+  <li>
+    King and Antiking can play one non-capturing knight move,
+    as long as they never moved earlier.
+  </li>
+</ul>
+
+<a href="https://www.chessvariants.com/diffobjective.dir/anti-king-chess.html">
+  chessvariants page.
+</a>
+
+<p class="author">Peter Aronson (2002).</p>
-- 
2.44.0