-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParallelGoBoard.vue
114 lines (104 loc) · 2.57 KB
/
ParallelGoBoard.vue
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<script lang="ts">
import type { MovesType } from "@ogfcommunity/variants-shared";
type Stone = { colors: string[]; annotation?: "CR" };
function forEachMoveModifyStone(
moves: MovesType,
board: Grid<Stone>,
fn: (stone: Stone, player: number) => void
) {
Object.keys(moves).forEach((player_str) => {
const player = Number(player_str);
const move = Coordinate.fromSgfRepr(moves[player]);
const stone = board.at(move);
if (stone) {
fn(stone, player);
}
});
}
</script>
<script setup lang="ts">
import MulticolorGridBoard from "./MulticolorGridBoard.vue";
import {
Coordinate,
type ParallelGoConfig,
type ParallelGoState,
} from "@ogfcommunity/variants-shared";
import { Grid } from "@ogfcommunity/variants-shared";
import { computed } from "vue";
const props = defineProps<{
config: ParallelGoConfig;
gamestate: ParallelGoState;
}>();
function isKoStone(colors: number[]) {
return colors.length === 1 && colors[0] === -1;
}
// https://sashamaps.net/docs/resources/20-colors/
const distinct_colors =
props.config.num_players === 2
? ["black", "white"]
: [
"#e6194B",
"#3cb44b",
"#ffe119",
"#4363d8",
"#f58231",
"#911eb4",
"#42d4f4",
"#f032e6",
"#bfef45",
"#fabed4",
"#469990",
"#dcbeff",
"#9A6324",
"#fffac8",
"#800000",
"#aaffc3",
"#808000",
"#ffd8b1",
"#000075",
"#a9a9a9",
"#ffffff",
"#000000",
];
const emit = defineEmits<{
(e: "move", pos: string): void;
}>();
function positionClicked(pos: Coordinate) {
emit("move", pos.toSgfRepr());
}
const board = computed(() => {
const gboard = Grid.from2DArray(props.gamestate.board);
const gboard_with_ko_stones = gboard.map((players): Stone => {
if (isKoStone(players)) {
return { colors: ["gray"] };
}
return { colors: players.map((player) => distinct_colors[player]) };
});
if (Object.keys(props.gamestate.staged).length) {
forEachMoveModifyStone(
props.gamestate.staged,
gboard_with_ko_stones,
(stone, player) => {
stone.colors.push(distinct_colors[player]);
stone.annotation = "CR";
}
);
} else {
forEachMoveModifyStone(
props.gamestate.last_round,
gboard_with_ko_stones,
(stone) => {
stone.annotation = "CR";
}
);
}
return gboard_with_ko_stones.to2DArray();
});
</script>
<template>
<MulticolorGridBoard
:board="board"
:config="props.config"
@click="(pos) => positionClicked(pos)"
/>
</template>