I'm trying to translate my JavaScript code to TypeScript. I don't know how to translate that code:
const COLOR_WHITE = 0;
const COLOR_BLACK = 1;
const CASTLE_TYPE_SHORT = 0;
const CASTLE_TYPE_LONG = 1;
class Game {
constructor() {
this.castling_possibilities = {
COLOR_WHITE: {
CASTLE_TYPE_SHORT: true,
CASTLE_TYPE_LONG: true
},
COLOR_BLACK: {
CASTLE_TYPE_SHORT: true,
CASTLE_TYPE_LONG: true
}
}
}
getCastlingPossibility(color, type) {
return this.castling_possibilities[color][type];
}
}
I got this code, but there are a lot of errors:
enum Color {
White,
Black
}
enum CastleType {
Short,
Long
}
class Game {
castling_possibilities: Object /* what member type is required? */
constructor() {
this.castling_possibilities = {
Color.White: {
CastleType.Short: true,
CastleType.Long: true
},
Color.Black: {
CastleType.Short: true,
CastleType.Long: true
}
}
}
getCastlingPossibility(color: Color, type: CastleType) : boolean {
return this.castling_possibilities[color][type];
}
}
I want something like an association array of Color and an association array of CastleType, but I don't know how to do that.
What type of castling_possibilities do I need?
Thanks in advance!