| 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
49
50
51
52
53
54
55
56
57
58
59
60
61 |
1x
1x
1x
1x
1x
1x
1x
1x
6x
17x
28x
5x
10x
5x
1x
2x
2x
1x
12x
3x
1x
9x
2x
2x
3x
2x
1x
1x
1x
1x
1x
1x
| import { asMap, asSet, map, spreadKV, } from 'fenugreek-collections';
import { Components, Filter, Grid, Node, } from 'game_grid';
import { claim, id, player, } from './player';
import { genNodes, fromNodes as makeBoard, playerGraph as pGraph,
playerNodes as pNodes, winComp, } from './board';
import { samePlayer, } from './node';
const { colNodes: gCols, colNodes: cNodes } = Grid;
import * as Board from './board';
// const { sameCol, } = Node;
const { omniComps, splitComps } = Components;
const {
byAdj, byCol, byNVec, byPosition, byPVec, byRow, columns, colAdj,
generate, negAdj, posAdj, rIDs, rowAdj,
} = Filter;
import { byExcess, byPlayer, exceeds, hasFree, nextFree, } from './filter';
const dCol = 0;
const dPlr = [ player('player0', 0, 0), player('player1', 0, 1) ];
const dNodes = genNodes();
const init = ({ column: 0, nodes: genNodes(), players: dPlr, });
export const game = (players = dPlr, nodes = dNodes, column = 0) =>
({ players, nodes, column });
export const column = ({ column } = init) => column;
export const nodes = ({ nodes } = init) => nodes;
export const players = ({ players } = init) => players;
export const active = ({ players: [ active, passive ] } = init) => active;
export const passive = ({ players: [ active, passive ] } = init) => passive;
export const setNodes = nArr => g => game(players(g), nArr, column(g));
export const setColumn = col => g => game(players(g), nodes(g), col);
export const setPlayers = pArr => g => game(pArr, nodes(g), column(g));
export const board = g => makeBoard(...nodes(g));
export const colNodes = g => byCol(nodes(g))(column(g));
export const next = game => nextFree(colNodes(game));
export const togglePlayers = g => setPlayers([ passive(g), active(g) ])(g);
// export const playerMap = players => asMap(asSet(players));
export const playerNodes = g => p => byPlayer(nodes(g))(id(p));
export const actNodes = g => playerNodes(g)(active(g));
export const passNodes = g => playerNodes(g)(passive(g));
export const playerGraph = g => p => makeBoard(...playerNodes(g)(p));
export const actGraph = g => playerGraph(g)(active(g));
export const passGraph = g => playerGraph(g)(passive(g));
export const actComps = game => omniComps(actGraph(game));
export const passComps = game => omniComps(passGraph(game));
export const select = game => claim(active(game))(next(game)) && togglePlayers(game);
export const hasWinComp = brd => plr => winComp(pGraph(brd)(plr), 3);
export const winner = ({ players, nodes }) => players.find(hasWinComp(board({ nodes })));
|