xchess
Version:
Chess Engine
101 lines (77 loc) • 1.41 kB
JavaScript
export {File, files}
import {INVALID_FILE} from './errors.js'
import {ConstNumberObject} from './ansi-style.js'
import {inspect} from './inspect.js'
const size = 8;
const files = [];
const map = new Map();
function nameAt(x){
return String.fromCharCode(x + 97);
}
function iccfAt(x){
return (x + 1) * 10;
}
function file(value){
const file = map.get(value);
if(file)
return file;
throw INVALID_FILE(value);
}
class File {
static from(value){
return file(value);
}
static is(value){
return map.has(value);
}
static all(){
return files;
}
static reverse(){
return ReverseFiles;
}
constructor(x){
this.
this.
this.
}
get x(){
return this.
}
get name(){
return this.
}
get iccf(){
return this.
}
get squares(){
return this.
}
toString(){
return this.name;
}
valueOf(){
return this.x;
}
[](depth, opts){
return ConstNumberObject(`[File ${this.name.toUpperCase()}]`);
}
}
// generate all
while(files.length < size){
const x = files.length;
const file = new File(x);
files.push(file);
map.set(file, file);
map.set(file.x, file);
map.set(file.name, file);
map.set(file.name.toUpperCase(), file);
}
const ReverseFiles = [... files];
ReverseFiles.reverse();
Object.freeze(files);
Object.freeze(ReverseFiles);