schachnovelle 1.0.0-beta-6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +8 -4
- package/index.js +1 -39
- package/package.json +19 -3
- package/server/api.js +132 -0
- package/server/index.js +436 -11
- package/ui/Board.js +52 -16
- package/ui/Fen.js +5 -0
- package/ui/Game.js +648 -176
- package/ui/LichessGame.js +11 -0
- package/ui/Printer.js +27 -2
- package/ui/Side.js +91 -0
- package/ui/Utils.js +12 -2
- package/ui/index.js +91 -35
- package/ui/moves.js +0 -0
- package/views/error.pug +6 -0
- package/views/index.pug +6 -0
- package/views/layout.pug +6 -0
- package/views/welcome.pug +6 -0
- package/.env +0 -4
- package/lichess/index.js +0 -6
- package/tests/consoletest.js +0 -53
- package/tests/controller/index.js +0 -16
- package/tests/processes.js +0 -57
- package/yarn-error.log +0 -367
package/ui/Board.js
CHANGED
|
@@ -11,7 +11,6 @@ class Board {
|
|
|
11
11
|
this.white = white
|
|
12
12
|
this.black = black
|
|
13
13
|
this.options = options
|
|
14
|
-
this.updatePieces()
|
|
15
14
|
|
|
16
15
|
if (this.options.orientation === 'white') {
|
|
17
16
|
this.files = files
|
|
@@ -25,19 +24,24 @@ class Board {
|
|
|
25
24
|
this.utils = new Utils()
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
clear () {
|
|
28
|
+
this.printer.clearView()
|
|
29
|
+
}
|
|
30
|
+
|
|
28
31
|
render () {
|
|
29
|
-
this.
|
|
32
|
+
// this.topCheck()
|
|
30
33
|
this.topRank()
|
|
31
34
|
this.board()
|
|
32
35
|
this.bottomRank()
|
|
36
|
+
// this.bottomCheck()
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
getPiece (file, rank) {
|
|
36
40
|
const activeWhitePiece = this.white.pieces.find((piece) => {
|
|
37
|
-
return piece.pos[0] === file && piece.pos[1] === rank
|
|
41
|
+
return piece.pos[0] === file && piece.pos[1] === rank && !piece.captured
|
|
38
42
|
})
|
|
39
43
|
const activeBlackPiece = this.black.pieces.find((piece) => {
|
|
40
|
-
return piece.pos[0] === file && piece.pos[1] === rank
|
|
44
|
+
return piece.pos[0] === file && piece.pos[1] === rank && !piece.captured
|
|
41
45
|
})
|
|
42
46
|
if (this.options.mode === 'color') {
|
|
43
47
|
if (activeWhitePiece) {
|
|
@@ -47,11 +51,25 @@ class Board {
|
|
|
47
51
|
}
|
|
48
52
|
return ` `
|
|
49
53
|
} else if (this.options.mode === 'bare') {
|
|
54
|
+
/**
|
|
55
|
+
* Pieces
|
|
56
|
+
*/
|
|
50
57
|
if (activeWhitePiece) {
|
|
51
|
-
|
|
58
|
+
if (activeWhitePiece.type === 'King' && this.white.inCheck) {
|
|
59
|
+
return chalk`{red ${activeWhitePiece.piece}} `
|
|
60
|
+
} else {
|
|
61
|
+
return chalk`{black ${activeWhitePiece.piece}} `
|
|
62
|
+
}
|
|
52
63
|
} else if (activeBlackPiece) {
|
|
53
|
-
|
|
64
|
+
if (activeBlackPiece.type === 'King' && this.black.inCheck) {
|
|
65
|
+
return chalk`{red ${activeBlackPiece.piece}} `
|
|
66
|
+
} else {
|
|
67
|
+
return chalk`{black ${activeBlackPiece.piece}} `
|
|
68
|
+
}
|
|
54
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Empty squares
|
|
72
|
+
*/
|
|
55
73
|
// If it's an odd rank it will start with black, so if you have an odd index in that rank, it will be black
|
|
56
74
|
const rankParity = this.ranks.indexOf(rank) % 2 === 0 // the rank is odd
|
|
57
75
|
const fileParity = this.files.indexOf(file) % 2 === 0 // the file is odd
|
|
@@ -63,12 +81,9 @@ class Board {
|
|
|
63
81
|
}
|
|
64
82
|
}
|
|
65
83
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Returns all captured pieces from a color
|
|
86
|
+
*/
|
|
72
87
|
capturedPieces (color) {
|
|
73
88
|
return this[color].pieces.filter((piece) => { return piece.captured })
|
|
74
89
|
}
|
|
@@ -79,7 +94,7 @@ class Board {
|
|
|
79
94
|
scoreBoard (side) {
|
|
80
95
|
let scoreBoard = ''
|
|
81
96
|
let score = 0
|
|
82
|
-
const opponent = this.utils.
|
|
97
|
+
const opponent = this.utils.opposingColor(side)
|
|
83
98
|
const pieces = this.capturedPieces(opponent)
|
|
84
99
|
|
|
85
100
|
if (pieces.length > 0) {
|
|
@@ -90,16 +105,37 @@ class Board {
|
|
|
90
105
|
scoreBoard += this.printer.addSpace('x', `(${score})`)
|
|
91
106
|
}
|
|
92
107
|
})
|
|
108
|
+
|
|
93
109
|
this.printer.print(scoreBoard)
|
|
94
|
-
this.printer.addSpace('y')
|
|
95
110
|
}
|
|
111
|
+
|
|
112
|
+
this.printer.addSpace('y')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* For development only. Display if the king is in check
|
|
117
|
+
*/
|
|
118
|
+
topCheck () {
|
|
119
|
+
const side = this.utils.opposingColor(this.options.orientation)
|
|
120
|
+
this.printer.print(side + ' king in check: ' + this[side].inCheck)
|
|
121
|
+
this.printer.addSpace('y')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* For development only. Display if the king is in check
|
|
126
|
+
*/
|
|
127
|
+
bottomCheck () {
|
|
128
|
+
const side = this.options.orientation
|
|
129
|
+
this.printer.print(side + ' king in check: ' + this[side].inCheck)
|
|
130
|
+
this.printer.addSpace('y')
|
|
96
131
|
}
|
|
97
132
|
|
|
98
133
|
/**
|
|
99
134
|
* Top signage
|
|
100
135
|
*/
|
|
101
136
|
topRank () {
|
|
102
|
-
this.
|
|
137
|
+
const side = this.utils.opposingColor(this.options.orientation)
|
|
138
|
+
this.scoreBoard(side)
|
|
103
139
|
let renderTopRank = this.printer.tab
|
|
104
140
|
renderTopRank = this.printer.addSpace('x', renderTopRank)
|
|
105
141
|
for (let file in this.files) {
|
|
@@ -165,7 +201,7 @@ class Board {
|
|
|
165
201
|
renderRank = this.printer.addSpace('x', renderRank)
|
|
166
202
|
}
|
|
167
203
|
renderRank += ` ${this.ranks[rank]}`
|
|
168
|
-
this.printer.
|
|
204
|
+
this.printer.printLine(renderRank)
|
|
169
205
|
this.printer.addSpace('y')
|
|
170
206
|
}
|
|
171
207
|
}
|