From 82706fc10e5a4fc572f798fca29e9741300fb0cc Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 6 Jun 2020 08:51:59 -0700 Subject: [PATCH] Initial implementation of Scribe 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 | 3 +- scribe.js | 60 ++++++++++++++++++++++++++++++++++++++ templates/scribe-game.html | 22 ++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 scribe.js create mode 100644 templates/scribe-game.html diff --git a/lmno.js b/lmno.js index ef76cb0..688c7a7 100644 --- 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 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 index 0000000..b2a4385 --- /dev/null +++ b/templates/scribe-game.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block head %} + + + + + +{% endblock %} + +{% block page %} +

Scribe

+ +

+ A game + by Mark + Steere, implemented by permission. +

+ +
+ +{% endblock %} -- 2.43.0