-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoveTable.vue
97 lines (84 loc) · 1.67 KB
/
MoveTable.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
<template>
<table class="table-striped">
<thead>
<tr>
<th class="toolbar"></th>
<th class="toolbar"><h1 class="title">White</h1></th>
<th class="toolbar"><h1 class="title">Black</h1></th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in doubleMoves" :key="row.id">
<th>{{ index + 1 }}</th>
<td>{{ row.white }}</td>
<td>{{ row.black }}</td>
</tr>
</tbody>
</table>
</template>
<script>
function pieceMapping() {
return {
w: {
p: '',
n: '♘',
b: '♗',
r: '♖',
q: '♕',
k: '♔',
},
b: {
p: '',
n: '♞',
b: '♝',
r: '♜',
q: '♛',
k: '♚',
},
};
}
function formatMove(move, long) {
if (!long || 'O' === move.san.charAt(0)) return move.san;
const mapping = pieceMapping()[move.color];
let retval = '';
if (move.piece !== 'p') retval += mapping[move.piece];
retval += move.from;
if (move.captured === undefined) {
retval += '-';
} else {
retval += 'x';
}
retval += move.to;
if (move.promotion) {
retval += mapping[move.promotion];
}
// Steal all other signs from the SAN variant.
const info = move.san.replace(/.*[1-8](?:=[QRBN])?/, '');
retval += info;
return retval;
}
export default {
name: 'MoveTable',
props: {
},
computed: {
doubleMoves: function doubleMoves() {
const { history } = this.$store.state.game;
const rows = [];
const longFormat = true;
for (let i = 0; i < history.length; i += 2) {
const row = {
id: i,
white: formatMove(history[i], longFormat),
black: '',
};
if (i + 1 < history.length) {
row.black = formatMove(history[i + 1], longFormat);
}
rows.push(row);
}
return rows;
},
},
};
</script>