]> git.cworth.org Git - empires-server/blob - scribe.js
Add a game phase to perform judging
[empires-server] / scribe.js
1 const express = require("express");
2 const Game = require("./game.js");
3
4 class Scribe extends Game {
5   constructor(id) {
6     super(id);
7     this.teams = [{id:0, name:"+"}, {id:1, name:"o"}];
8     this.state = {
9       moves: [],
10       squares: Array(9).fill(null).map(() => Array(9).fill(null)),
11       team_to_play: this.teams[0],
12     };
13   }
14
15   /* Returns true if move was legal and added, false otherwise. */
16   add_move(player, move) {
17
18     const state = this.state;
19     const i = move[0];
20     const j = move[1];
21     const result = super.add_move(player, move);
22
23     /* If the generic Game class can reject this move, then we don't
24      * need to look at it any further. */
25     if (! result.legal)
26       return result;
27
28     /* TODO: Need to enforce super-square matching mini-square from
29      * previous move (if given super-square isn't full already). */
30
31     /* Cannot move to an occupied square. */
32     if (state.squares[i][j])
33     {
34       return { legal: false,
35                message: "Square is already occupied" };
36     }
37
38     state.squares[i][j] = state.team_to_play;
39     state.moves.push(move);
40
41     if (state.team_to_play.id === 0)
42       state.team_to_play = this.teams[1];
43     else
44       state.team_to_play = this.teams[0];
45
46     return { legal: true };
47   }
48 }
49
50 Scribe.router = express.Router();
51
52 Scribe.meta = {
53   name: "Scribe",
54   identifier: "scribe",
55   options: {
56     allow_guest: true
57   }
58 };
59
60 exports.Game = Scribe;