This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update package-lock.json * Document browser output * Delete package-lock.json Lockfile not needed * Type cleanup * Document `makeMove` param 3 `completeMove?` * Minor cleanup * Return undefined colour when cell is empty Empty cells were being classified as black, leading to incorrect movement. Fixes #15 * Restore package-lock.json * Fix unchecked types * Use nonnull assertion instead Already checked for existence in the line above * Improve board typing * Add fen type * Fix move list checking * Version 0.4.3
- Loading branch information
Showing
17 changed files
with
107 additions
and
73 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 |
---|---|---|
@@ -1,3 +1 @@ | ||
* text=auto | ||
|
||
package-lock.json -diff |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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 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,23 +1,34 @@ | ||
import gameData from '../variables'; | ||
import { Cell, Colour } from '../types'; | ||
import { toLowerCase, toUpperCase } from '../helpers'; | ||
import { Cell, Colour, PieceID, FenParts, CastleString, Fen } from '../types'; | ||
import { isWhite } from '../pieces'; | ||
|
||
export default function createBoardArray(fenString: string): void { | ||
const fenParts = fenString.split(' '); | ||
|
||
const currentBoard = fenParts[0].split('/'); | ||
gameData.currentTurn = fenParts[1] as Colour; | ||
const { fen, currentTurn, castling, enpassantSquare, halfMoveCount, moveNumber } = getFenParts(fenString); | ||
|
||
gameData.castling = { w: { k: false, q: false }, b: { k: false, q: false } }; | ||
const castleString = fenParts[2]; | ||
const castleString = castling; | ||
for (let i = 0; i < castleString.length; i++) { | ||
const colour = castleString[i] === castleString[i].toUpperCase() ? 'w' : 'b' as Colour; | ||
const side = castleString[i].toLowerCase() as ('k' | 'q'); | ||
const colour = isWhite(castleString[i] as PieceID) ? 'w' : 'b'; | ||
const side = toLowerCase(<'k' | 'q'>castleString[i]); | ||
gameData.castling[colour][side] = true; | ||
} | ||
|
||
gameData.enpassantSquare = fenParts[3].toUpperCase() as Cell; | ||
gameData.halfMoveCount = +fenParts[4]; | ||
gameData.moveNumber = +fenParts[5]; | ||
gameData.currentTurn = currentTurn; | ||
gameData.enpassantSquare = enpassantSquare; | ||
gameData.halfMoveCount = halfMoveCount; | ||
gameData.moveNumber = moveNumber; | ||
|
||
gameData.boardArray = currentBoard.map(val => val.replace(/[0-9]/g, n => '-'.repeat(+n))); | ||
gameData.boardArray = fen.split('/').map(val => val.replace(/[0-9]/g, n => '-'.repeat(+n))); | ||
} | ||
|
||
function getFenParts(fenString: string): FenParts { | ||
const fenParts = fenString.split(' '); | ||
const fen = <Fen>fenParts[0]; | ||
const currentTurn = <Colour>fenParts[1]; | ||
const castling = <CastleString>fenParts[2]; | ||
const enpassantSquare = toUpperCase(<Cell>fenParts[3]); | ||
const halfMoveCount = +fenParts[4]; | ||
const moveNumber = +fenParts[5]; | ||
return { fen, currentTurn, castling, enpassantSquare, halfMoveCount, moveNumber }; | ||
} |
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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.