export class Robot {
private static usedNames = new Set<string>();
private _name: string = '';
constructor() { this.resetName(); }
public get name(): string { return this._name; }
public resetName(): void {
let name;
do {
name = this.gen();
} while (Robot.usedNames.has(name));
this._name = name;
Robot.usedNames.add(name);
}
private gen(): string {
const L = () => String.fromCharCode(65 + Math.floor(Math.random() * 26));
const D = () => Math.floor(Math.random() * 10);
return L() + L() + D() + D() + D();
}
public static releaseNames(): void { Robot.usedNames.clear(); }
}