Passed
Push — master ( bb6f81...12291e )
by Christofer
57s
created

src/chess/Game.js   A

Size

Lines of Code 78

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
nc 1
dl 0
loc 78
rs 10
c 2
b 0
f 0
ccs 29
cts 29
cp 1
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A Game.js ➔ ??? 0 7 1
1 1
const Player = require("./Player");
2 1
const Board = require("./Board");
3
4
5
/**
6
 * The game module
7
 * @module
8
 */
9 1
"use strict";
10
11
/**
12
 * The main module that executes the game
13
 */
14
class Game {
15
    /**
16
     * Init Game with board, peices, and players
17
     */
18
    constructor() {
19 1
        this.p1 = new Player("white", "player1");
20 1
        this.p2 = new Player("black", "player2");
21 1
        this.board = new Board();
22 1
        this.gameBoard = this.board.board;
23 1
        this.turn = this.p1;
24
    }
25
26
27
    /**
28
     * Init board with all player pieces
29
     */
30
    init(preset = null) {
0 ignored issues
show
Unused Code introduced by
The parameter preset is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
31
        //Pawns
32 2
        for (let i = 1; i <= 8; i++) {
33 16
            this.gameBoard["B"][i] = this.p1.pawns[i - 1];
34
        }
35
36 2
        for (let i = 1; i <= 8; i++) {
37 16
            this.gameBoard["G"][i] = this.p2.pawns[i - 1];
38
        }
39
40
        // Rooks
41 2
        this.gameBoard["A"][1] = this.p1.rooks[0];
42 2
        this.gameBoard["A"][8] = this.p1.rooks[1];
43 2
        this.gameBoard["H"][1] = this.p2.rooks[0];
44 2
        this.gameBoard["H"][8] = this.p2.rooks[1];
45
46
        // Knights
47 2
        this.gameBoard["A"][2] = this.p1.knights[0];
48 2
        this.gameBoard["A"][7] = this.p1.knights[1];
49 2
        this.gameBoard["H"][2] = this.p2.knights[0];
50 2
        this.gameBoard["H"][7] = this.p2.knights[1];
51
52
        // Bishops
53 2
        this.gameBoard["A"][3] = this.p1.bishops[0];
54 2
        this.gameBoard["A"][6] = this.p1.bishops[1];
55 2
        this.gameBoard["H"][3] = this.p2.bishops[0];
56 2
        this.gameBoard["H"][6] = this.p2.bishops[1];
57
58
        // King Queen
59 2
        this.gameBoard["A"][4] = this.p1.king;
60 2
        this.gameBoard["A"][5] = this.p1.queen;
61 2
        this.gameBoard["H"][4] = this.p2.king;
62 2
        this.gameBoard["H"][5] = this.p2.queen;
63
    }
64
65
    // start() {
66
    //     while (true) {
67
    //         checkTurn();
68
    //         board.move();
69
    //
70
    //         legalMove && checkDiagonal
71
    //
72
    //         game.turn = next;
73
    //
74
    //     }
75
    // }
76
}
77
78
module.exports = new Game();
79