Skip to content

Instantly share code, notes, and snippets.

@FermiDirak
Last active January 16, 2022 07:22
Show Gist options
  • Save FermiDirak/d8dd49f34b877dc2652f45e586e24f59 to your computer and use it in GitHub Desktop.
Save FermiDirak/d8dd49f34b877dc2652f45e586e24f59 to your computer and use it in GitHub Desktop.
enum PlayerSide { /* ... */ }
type Move = { /* ... */ }
type Board = { /* ... */ }
type Chess = { board: Board; turn: PlayerSide }
namespace ChessService {
// functions for interacting with the game chess
function applyMove(chess: Chess, move: Move): Chess { /* ... */ }
function starting_state(): Chess { /* ... */ }
function listValidMoves(board: Chess, playerTurn: PlayerSide): Move[] { /* ... */ }
// ...
}
// usage
const moves: Move[] = readInput("input.json");
let chess: Chess = ChessService.starting_state();
display(chess.board);
moves.forEach(move => {
chess = ChessService.applyMove(chess, move);
display(chess.board);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment