Lines of Code | 34 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 57.14% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
5 | "use strict"; |
||
6 | |||
7 | /** |
||
8 | * Class with Bishop logic |
||
9 | */ |
||
10 | class Bishop { |
||
11 | /** |
||
12 | * init |
||
13 | */ |
||
14 | constructor(color) { |
||
15 | 8 | this.symbol = "B"; |
|
16 | 8 | this.moved = 0; |
|
17 | 8 | this.active = true; |
|
18 | 8 | this.color = color; |
|
19 | 8 | this.rows = [null, "A", "B", "C", "D", "E", "F", "G", "H"]; |
|
20 | 8 | this.img = this.color === "white" ? "w-bishop" : "b-bishop"; |
|
21 | } |
||
22 | |||
23 | legalMove(x, y, nx, ny) { |
||
24 | let xNum = this.rows.indexOf(x); |
||
25 | let nxNum = this.rows.indexOf(nx); |
||
26 | |||
27 | let xStep = Math.abs(xNum - nxNum); |
||
28 | let yStep = Math.abs(y - ny) |
||
29 | 2 | if (xStep === yStep) { |
|
30 | return true |
||
31 | } |
||
32 | |||
33 | return false; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | |||
38 | module.exports = Bishop; |
||
39 |