forked from lichess-org/lila
-
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.
Merge pull request lichess-org#16512 from allanjoseph98/random-refact…
…oring Miscellaneous refactoring
- Loading branch information
Showing
20 changed files
with
102 additions
and
231 deletions.
There are no files selected for viewing
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
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,41 +1,30 @@ | ||
import { uciChar } from './uciChar'; | ||
|
||
export * from './sanWriter'; | ||
export const initialFen: FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'; | ||
|
||
export function fixCrazySan(san: San): San { | ||
return san[0] === 'P' ? san.slice(1) : san; | ||
} | ||
export const fixCrazySan = (san: San): San => (san[0] === 'P' ? san.slice(1) : san); | ||
|
||
export function destsToUcis(dests: Dests): Uci[] { | ||
const ucis: string[] = []; | ||
for (const [orig, d] of dests) { | ||
d.forEach(function (dest) { | ||
ucis.push(orig + dest); | ||
}); | ||
} | ||
return ucis; | ||
} | ||
export const destsToUcis = (destMap: Dests): Uci[] => | ||
Array.from(destMap).reduce<Uci[]>((acc, [orig, dests]) => acc.concat(dests.map(dest => orig + dest)), []); | ||
|
||
export function readDests(lines?: string): Dests | null { | ||
if (typeof lines === 'undefined') return null; | ||
const dests = new Map(); | ||
if (lines) | ||
for (const line of lines.split(' ')) { | ||
dests.set( | ||
uciChar[line[0]], | ||
line | ||
.slice(1) | ||
.split('') | ||
.map(c => uciChar[c]), | ||
); | ||
} | ||
return dests; | ||
} | ||
export const readDests = (lines?: string): Dests | null => | ||
lines | ||
? lines.split(' ').reduce<Dests>((dests, line) => { | ||
dests.set( | ||
uciChar[line[0]], | ||
line | ||
.slice(1) | ||
.split('') | ||
.map(c => uciChar[c]), | ||
); | ||
return dests; | ||
}, new Map()) | ||
: null; | ||
|
||
export function readDrops(line?: string | null): Key[] | null { | ||
if (typeof line === 'undefined' || line === null) return null; | ||
return (line.match(/.{2}/g) as Key[]) || []; | ||
} | ||
export const readDrops = (line?: string | null): Key[] | null => | ||
line ? (line.match(/.{2}/g) as Key[]) || [] : null; | ||
|
||
// Extended Position Description | ||
export const fenToEpd = (fen: FEN): string => fen.split(' ').slice(0, 4).join(' '); | ||
|
||
export const plyToTurn = (ply: number): number => Math.floor((ply - 1) / 2) + 1; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { "emitDeclarationOnly": true }, | ||
"references": [{ "path": "../common/tsconfig.json" }] | ||
"references": [{ "path": "../common/tsconfig.json" }, { "path": "../chess/tsconfig.json" }] | ||
} |
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.