Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): add project deps instead of per chapter
- Loading branch information
1 parent
f17f482
commit eaeacb1
Showing
15 changed files
with
354 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
root: true | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +0,0 @@ | ||
type Color = 'Black' | 'White'; | ||
|
||
/** | ||
* Represent a Chess game | ||
*/ | ||
class Game { | ||
private pieces = Game.makePieces(); | ||
|
||
private static makePieces() { | ||
return [ | ||
// Kings | ||
new King('White', 'E', 1), | ||
new King('Black', 'F', 8), | ||
|
||
// Queens | ||
// new Queen('White', 'D', 1), | ||
// new Queen('Black', 'D', 8), | ||
|
||
// Bishops | ||
// new Bishop('White', 'C', 1), | ||
// new Bishop('White', 'F', 1), | ||
// new Bishop('Black', 'C', 8), | ||
// new Bishop('Black', 'F', 8), | ||
|
||
// ... | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* A set of coordinates for a piece | ||
*/ | ||
type ChessFile = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H'; | ||
type ChessRank = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; | ||
|
||
class Position { | ||
constructor(private file: ChessFile, private rank: ChessRank) {} | ||
distanceFrom(position: Position) { | ||
return { | ||
rank: Math.abs(position.rank - this.rank), | ||
file: Math.abs(position.file.charCodeAt(0) - this.file.charCodeAt(0)), | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Represent a Chess piece | ||
*/ | ||
abstract class Piece { | ||
protected position: Position; | ||
constructor(private readonly color: Color, file: ChessFile, rank: ChessRank) { | ||
this.position = new Position(file, rank); | ||
} | ||
moveTo(position: Position) { | ||
this.position = position; | ||
} | ||
abstract canMoveTo(position: Position): boolean; | ||
} | ||
|
||
/** | ||
* The six types of pieces | ||
*/ | ||
class King extends Piece { | ||
canMoveTo(position: Position) { | ||
let distance = this.position.distanceFrom(position); | ||
return distance.rank < 2 && distance.file < 2; | ||
} | ||
} | ||
// class Queen extends Piece {} | ||
// class Bishop extends Piece {} | ||
// class Knight extends Piece {} | ||
// class Rook extends Piece {} | ||
// class Pawn extends Piece {} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,83 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/** | ||
* Implementation of a Chess Engine | ||
*/ | ||
type Color = 'Black' | 'White'; | ||
|
||
/** | ||
* Represent a Chess game | ||
*/ | ||
class Game { | ||
private pieces = Game.makePieces(); | ||
|
||
private static makePieces() { | ||
return [ | ||
// Kings | ||
new King('White', 'E', 1), | ||
new King('Black', 'F', 8) | ||
|
||
// Queens | ||
// new Queen('White', 'D', 1), | ||
// new Queen('Black', 'D', 8), | ||
|
||
// Bishops | ||
// new Bishop('White', 'C', 1), | ||
// new Bishop('White', 'F', 1), | ||
// new Bishop('Black', 'C', 8), | ||
// new Bishop('Black', 'F', 8), | ||
|
||
// ... | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* A set of coordinates for a piece | ||
*/ | ||
type ChessFile = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H'; | ||
type ChessRank = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; | ||
|
||
class Position { | ||
constructor(private file: ChessFile, private rank: ChessRank) {} | ||
distanceFrom(position: Position) { | ||
return { | ||
rank: Math.abs(position.rank - this.rank), | ||
file: Math.abs( | ||
position.file.charCodeAt(0) - this.file.charCodeAt(0) | ||
) | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Represent a Chess piece | ||
*/ | ||
abstract class Piece { | ||
protected position: Position; | ||
constructor( | ||
private readonly color: Color, | ||
file: ChessFile, | ||
rank: ChessRank | ||
) { | ||
this.position = new Position(file, rank); | ||
} | ||
moveTo(position: Position) { | ||
this.position = position; | ||
} | ||
abstract canMoveTo(position: Position): boolean; | ||
} | ||
|
||
/** | ||
* The six types of pieces | ||
*/ | ||
class King extends Piece { | ||
canMoveTo(position: Position) { | ||
const distance = this.position.distanceFrom(position); | ||
return distance.rank < 2 && distance.file < 2; | ||
} | ||
} | ||
// class Queen extends Piece {} | ||
// class Bishop extends Piece {} | ||
// class Knight extends Piece {} | ||
// class Rook extends Piece {} | ||
// class Pawn extends Piece {} |
Oops, something went wrong.