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/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.updatePieces()
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
- return chalk`{whiteBright ${activeWhitePiece.piece}} `
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
- return chalk`{black ${activeBlackPiece.piece}} `
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
- updatePieces () {
67
- this.pieces = this.white.pieces.concat(this.black.pieces).filter((piece) => {
68
- return !piece.captured
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.opponentColor(side)
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.scoreBoard(this.utils.opponentColor(this.options.orientation))
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.print(renderRank)
204
+ this.printer.printLine(renderRank)
169
205
  this.printer.addSpace('y')
170
206
  }
171
207
  }
package/ui/Fen.js ADDED
@@ -0,0 +1,5 @@
1
+ export default {
2
+ currentPosition: null,
3
+ startPos: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
4
+ moves: []
5
+ }