generated from mehm8128/next-template
/
checkmate.test.ts
97 lines (93 loc) · 2.22 KB
/
checkmate.test.ts
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
import { Board } from '@/features/board/schema'
import { checkmate } from '@/features/game/checkmate'
import { arrayWith, nullBoard } from '@/lib/testUtils'
describe('checkmate', () => {
test('頭金の詰み判定ができる', () => {
const board1: Board['board'] = arrayWith(nullBoard, 0, 4, {
id: '0',
type: 'king',
own: 'white',
promoted: false
})
const board2 = arrayWith(board1, 1, 4, {
id: '1',
type: 'gold',
own: 'black',
promoted: false
})
const board3 = arrayWith(board2, 2, 4, {
id: '2',
type: 'gold',
own: 'black',
promoted: false
})
expect(checkmate({ board: board3 }, 'white')).toBe(true)
})
// TODO: 駒を取ったときに王手がかかるとき、詰みにならない
// test('一間竜の詰み判定ができる', () => {
// const board1: Board['board'] = arrayWith(nullBoard, 1, 8, {
// id: '0',
// type: 'king',
// own: 'white',
// promoted: false
// })
// const board2 = arrayWith(board1, 1, 7, {
// id: '1',
// type: 'gold',
// own: 'white',
// promoted: false
// })
// const board3 = arrayWith(board2, 1, 6, {
// id: '2',
// type: 'rook',
// own: 'black',
// promoted: true
// })
// const board4 = arrayWith(board3, 2, 7, {
// id: '3',
// type: 'gold',
// own: 'black',
// promoted: false
// })
// const board5: Board['board'] = arrayWith(board4, 0, 8, {
// id: '4',
// type: 'lance',
// own: 'white',
// promoted: false
// })
// expect(checkmate({ board: board5 }, 'white')).toBe(true)
// })
test('桂馬を使った詰み判定ができる', () => {
const board1: Board['board'] = arrayWith(nullBoard, 0, 8, {
id: '0',
type: 'king',
own: 'white',
promoted: false
})
const board2 = arrayWith(board1, 0, 7, {
id: '1',
type: 'gold',
own: 'white',
promoted: false
})
const board3 = arrayWith(board2, 1, 8, {
id: '2',
type: 'knight',
own: 'white',
promoted: false
})
const board4 = arrayWith(board3, 1, 7, {
id: '3',
type: 'knight',
own: 'white',
promoted: false
})
const board5 = arrayWith(board4, 2, 7, {
id: '4',
type: 'knight',
own: 'black',
promoted: false
})
expect(checkmate({ board: board5 }, 'white')).toBe(true)
})
})