sunflowerseastar / merels

nine men's morris using APL in TS

Home Page:https://merels.sunflowerseastar.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merels

Quick Start

Yarn, Vite, Cypress.

yarn
yarn start # localhost:5137
yarn cy:run

yarn build
yarn preview # localhost:4137 to check build

Auto-prettier with simple-git-hooks + lint-staged.

Dependencies

APL

Nick Nickolov’s APL is copied into lib/apl, with a few helper functions in lib/aplLibraryHelpers.ts. See lib/apl/license and lib/apl/readme.md. The merels application calls the APL library and helpers from src/aplGameFunctions.ts to translate between the “grid index” and “apl index” (see diagrams below), and update the pieces on the boards.

XState

XState manages the game’s context (what is often thought of as application state), as well as the game’s states (ex. Placing, Moving) and actions (ex. place, move). A visualization can be seen in Stately Studio here.

Umbrella

Once the XState actor is created by interpreting the machine, Umbrella’s rstream subscribes to the ongoing changes of the actor’s context. rdom is used to compile a hiccup tree, along with the streaming state, into the DOM.

Rules

  • White starts, white & black alternate turns.
  • Phase 1: place one piece on the board in an open point.
  • If a mill is formed (three of your pieces in a row), remove an opponent piece. An opponent’s piece that is locked in a mill cannot be removed unless no others are available.
  • After all pieces have been placed, phase 2 begins: move one piece to an adjacent unoccupied point. Same form-a-mill-and-remove-an-opponent-piece rule applies.
  • When a player has only 3 pieces remaining, their pieces are now “flying” and can move to any open point instead of only adjacent points.
  • The player reduced to two pieces or trapped with no legal moves loses.

Board

Possible piece positions:

1  0  0  1  0  0  1
0  1  0  1  0  1  0
0  0  1  1  1  0  0
1  1  1  0  1  1  1
0  0  1  1  1  0  0
0  1  0  1  0  1  0
1  0  0  1  0  0  1
1        1        1
   1     1     1
      1  1  1
1  1  1     1  1  1
      1  1  1
   1     1     1
1        1        1

Grid index:

0  1  2  3  4  5  6
7  8  9  10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34
35 36 37 38 39 40 41
42 43 44 45 46 47 48

Grid index with non-positions omitted:

0        3        6
   8     10    12
      16 17 18
21 22 23    25 26 27
      30 31 32
   36    38    40
42       45       48

Apl index shown on the board:

0       1        2
  9     10    11
     18 19 20
3 12 21    23 14 5
     24 25 26
  15    16    17
6       7        8
0     1     2    -       -       -    -      -       -
  -   -   -        9     10   11        -    -     -
    - - -             -  -  -             18 19 20
3 - -   - - 5    - 12 -     - 14 -    - - 21    23 - -
    - - -             -  -  -             24 25 26
  -   -   -        15    16   17        -    -     -
6     7     8    -       -       -    -      -       -

Apl index:

0 1 2    9 10 11   18 19 20
3   5   12    14   21    23
6 7 8   15 16 17   24 25 26

Apl positions using the grid indices (translation with utility.ts gridIndexToAplIndex):

 0  3  6    8 10 12   16 17 18
21    27   22    26   23    25
42 45 48   36 38 40   30 31 32

About

nine men's morris using APL in TS

https://merels.sunflowerseastar.com

License:GNU Affero General Public License v3.0


Languages

Language:JavaScript 65.7%Language:TypeScript 25.8%Language:CSS 8.2%Language:HTML 0.3%