]> git.cworth.org Git - empires-server/commitdiff
Initial implementation of Scribe
authorCarl Worth <cworth@cworth.org>
Sat, 6 Jun 2020 15:51:59 +0000 (08:51 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 6 Jun 2020 15:51:59 +0000 (08:51 -0700)
This is not at all sophisticated yet. The biggest shortcoming is that
it doesn't yet reject moves that don't follow the movement
restrictions (where a player must play in the super-grid corresponding
to their last moves mini-grid).

lmno.js
scribe.js [new file with mode: 0644]
templates/scribe-game.html [new file with mode: 0644]

diff --git a/lmno.js b/lmno.js
index ef76cb06918cce8a7f8b1318075aa908e701cf23..688c7a74e9800e51fde3a1375dcc28239e0862f3 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -81,7 +81,8 @@ nunjucks.configure("templates", {
  */
 const engines = {
   empires: require("./empires").Game,
-  tictactoe: require("./tictactoe").Game
+  tictactoe: require("./tictactoe").Game,
+  scribe: require("./scribe").Game
 };
 
 class LMNO {
diff --git a/scribe.js b/scribe.js
new file mode 100644 (file)
index 0000000..46be6a4
--- /dev/null
+++ b/scribe.js
@@ -0,0 +1,60 @@
+const express = require("express");
+const Game = require("./game.js");
+
+class Scribe extends Game {
+  constructor(id) {
+    super(id);
+    this.teams = [{id:0, name:"+"}, {id:1, name:"o"}];
+    this.state = {
+      moves: [],
+      squares: Array(9).fill(null).map(() => Array(9).fill(null)),
+      team_to_play: this.teams[0],
+    };
+  }
+
+  /* Returns true if move was legal and added, false otherwise. */
+  add_move(player, move) {
+
+    const state = this.state;
+    const i = move[0];
+    const j = move[1];
+    const result = super.add_move(player, move);
+
+    /* If the generic Game class can reject this move, then we don't
+     * need to look at it any further. */
+    if (! result.legal)
+      return result;
+
+    /* TODO: Need to enforce super-square matching mini-square from
+     * previous move (if given super-square isn't full already). */
+
+    /* Cannot move to an occupied square. */
+    if (state.squares[i][j])
+    {
+      return { legal: false,
+               message: "Square is already occupied" };
+    }
+
+    state.squares[i][j] = state.team_to_play;
+    state.moves.push(move);
+
+    if (state.team_to_play.id === 0)
+      state.team_to_play = this.teams[1];
+    else
+      state.team_to_play = this.teams[0];
+
+    return { legal: true };
+  }
+}
+
+Scribe.router = express.Router();
+
+Scribe.meta = {
+  name: "Scribe",
+  identifier: "scribe",
+  options: {
+    allow_guest: true
+  }
+};
+
+exports.Game = Scribe;
diff --git a/templates/scribe-game.html b/templates/scribe-game.html
new file mode 100644 (file)
index 0000000..b2a4385
--- /dev/null
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+
+{% block head %}
+<link rel="stylesheet" href="/scribe/scribe.css" type="text/css" />
+
+<script src="/react.js"></script>
+<script src="/react-dom.js"></script>
+<script type="module" src="/scribe/scribe.js"></script>
+{% endblock %}
+
+{% block page %}
+<h1>Scribe</h1>
+
+<p>
+  A game
+  by <a href="http://www.marksteeregames.com/Scribe_rules.html">Mark
+  Steere</a>, implemented by permission.
+</p>
+
+<div id="scribe"></div>
+
+{% endblock %}