Skip to content

Instantly share code, notes, and snippets.

@morintd
Created March 11, 2024 19:52
Show Gist options
  • Save morintd/23d5d88f269f4343557a25fcb081d80b to your computer and use it in GitHub Desktop.
Save morintd/23d5d88f269f4343557a25fcb081d80b to your computer and use it in GitHub Desktop.
import { IGamePresenter, Input } from "../ports/game-presenter.port";
export class GamePresenter implements IGamePresenter {
format(input: Input) {
const moves = input.history.map((_, move: number) => {
return {
move,
description: move > 0 ? "Go to move #" + move : "Go to game start",
};
});
const status = input.winner
? input.winner === "draw"
? "Draw"
: "Winner: " + input.winner
: "Next player: " + (input.xIsNext ? "X" : "O");
return {
moves,
status,
squares: input.history[input.step],
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment