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.
* Start conversion to TypeScript * Complete TypeScript rewrite * Use plain static members for game data * Update readme.md * Fix merge error * Use CommonJS import for test * Fix compile errors * Update index.ts * Cleanup * Export `points` * Simplify error * Remove getColour error * Remove check altogether Not the best option but I'm not sure how to supress this otherwise * Update type labels * Fix type errors * Version * No longer Node 13+ specific * Change browser script * Minor cleanup
- Loading branch information
Showing
30 changed files
with
364 additions
and
317 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,3 @@ | ||
if (typeof global === 'undefined') global = {}; | ||
import exports from './index.js'; | ||
if (typeof window !== "undefined") window.fenFuncs = exports; | ||
if (typeof window !== "undefined") { | ||
window.fenFuncs = require('./src/index.js'); | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gameData from '../variables'; | ||
import { Cell, Colour } from '../types'; | ||
|
||
export default function createBoardArray(fenString: string): void { | ||
const fenParts = fenString.split(' '); | ||
|
||
const currentBoard = fenParts[0].split('/'); | ||
gameData.currentTurn = fenParts[1] as Colour; | ||
|
||
gameData.castling = { w: { k: false, q: false }, b: { k: false, q: false } }; | ||
const castleString = fenParts[2]; | ||
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'); | ||
gameData.castling[colour][side] = true; | ||
} | ||
|
||
gameData.enpassantSquare = fenParts[3].toUpperCase() as Cell; | ||
gameData.halfMoveCount = +fenParts[4]; | ||
gameData.moveNumber = +fenParts[5]; | ||
|
||
gameData.boardArray = currentBoard.map(val => val.replace(/[0-9]/g, n => '-'.repeat(+n))); | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import gameData from '../variables'; | ||
import createBoardArray from './create-board'; | ||
|
||
export default function undoMove(): string | undefined { | ||
if (gameData.moveList.length === 0) return; | ||
gameData.moveList.pop(); | ||
gameData.logList.pop(); | ||
const lastMove = gameData.moveList[gameData.moveList.length - 1]; | ||
createBoardArray(lastMove); | ||
return lastMove; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Cell, Colour } from './types'; | ||
|
||
export function indexToLetter(n: number): string { | ||
// 1-indexed; 0x40=uppercase, 0x60=lowercase | ||
return String.fromCharCode(n + 0x40); | ||
} | ||
|
||
export function invertColour(colour: Colour): Colour { | ||
return colour === 'b' ? 'w' : 'b'; | ||
} | ||
|
||
export function coordsToCell(x: number, y: number): Cell { | ||
return indexToLetter(x) + y as Cell; | ||
} |
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,23 @@ | ||
import gameData from './variables'; | ||
import setupBoard from './board/setup-board'; | ||
import createBoard from './board/create-board'; | ||
import points from './points'; | ||
import * as validation from './validation/validation'; | ||
import makeMove from './validation/make-move'; | ||
import findAllMoves from './validation/all-moves'; | ||
import isCheck from './validation/is-check'; | ||
import gameEndingStatus from './validation/ending'; | ||
import undoMove from './board/undo'; | ||
|
||
export = { | ||
gameData, | ||
setupBoard, | ||
createBoard, | ||
points, | ||
makeMove, | ||
validation, | ||
findAllMoves, | ||
isCheck, | ||
gameEndingStatus, | ||
undoMove, | ||
} |
Oops, something went wrong.