forked from lichess-org/lila
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use yaneuraou for positions that could be reached from default starti…
…ng position
- Loading branch information
1 parent
3325bdb
commit 68083b2
Showing
6 changed files
with
55 additions
and
38 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
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,28 +1,48 @@ | ||
import { Rules } from 'shogiops'; | ||
import { isHandicap } from 'shogiops/handicaps'; | ||
import { initialSfen } from 'shogiops/sfen'; | ||
import { initialSfen, parseSfen } from 'shogiops/sfen'; | ||
|
||
const useJp = document.documentElement.lang === 'ja-JP'; | ||
|
||
export const enum EngineCode { | ||
YaneuraOu = 'yn', | ||
Fairy = 'fs', | ||
} | ||
|
||
// modules/game/src/main/EngineConfig.scala | ||
export function engineName( | ||
rules: Rules, | ||
sfen: Sfen | undefined, | ||
level?: number, | ||
withLevel?: boolean, | ||
trans?: Trans | ||
): string { | ||
const code: EngineCode = | ||
rules === 'standard' && | ||
export function engineCode(rules: Rules, sfen: Sfen | undefined, level?: number): EngineCode { | ||
return rules === 'standard' && | ||
(!level || level > 1) && | ||
(!sfen || initialSfen(rules) === sfen || isHandicap({ sfen, rules })) | ||
? 'yn' | ||
: 'fs'; | ||
return engineNameFromCode(code, withLevel ? level : undefined, trans); | ||
(!sfen || initialSfen(rules) === sfen || isHandicap({ sfen, rules }) || isStandardMaterial(sfen)) | ||
? EngineCode.YaneuraOu | ||
: EngineCode.Fairy; | ||
} | ||
|
||
export function engineName(rules: Rules, sfen: Sfen | undefined, level?: number, trans?: Trans): string { | ||
const code = engineCode(rules, sfen, level); | ||
return engineNameFromCode(code, level, trans); | ||
} | ||
|
||
export function engineNameFromCode(code?: EngineCode, level?: number, trans?: Trans): string { | ||
const name = code === 'fs' ? 'Fairy Stockfish' : useJp ? 'やねうら王' : 'YaneuraOu'; | ||
if (level && trans) return name + ' - ' + trans('levelX', level); | ||
else return name; | ||
} | ||
|
||
function isStandardMaterial(sfen: Sfen): boolean { | ||
const pos = parseSfen('standard', sfen); | ||
if (pos.isErr) return false; | ||
const board = pos.value.board, | ||
hands = pos.value.hands.color('sente').combine(pos.value.hands.color('gote')); | ||
return ( | ||
board.role('pawn').size() + board.role('tokin').size() + hands.get('pawn') <= 18 && | ||
board.role('lance').size() + board.role('promotedlance').size() + hands.get('lance') <= 4 && | ||
board.role('knight').size() + board.role('promotedknight').size() + hands.get('knight') <= 4 && | ||
board.role('silver').size() + board.role('promotedsilver').size() + hands.get('silver') <= 4 && | ||
board.role('gold').size() + hands.get('gold') <= 4 && | ||
board.role('rook').size() + board.role('dragon').size() + hands.get('rook') <= 2 && | ||
board.role('bishop').size() + board.role('horse').size() + hands.get('bishop') <= 2 && | ||
board.role('king').size() == 2 && | ||
board.role('king').intersect(board.color('sente')).size() === 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { EngineCode } from 'common/engineName'; | ||
|
||
export interface GameData { | ||
game: Game; | ||
player: Player; | ||
|
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