-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jake Lauer <jakelauer@Jake-MacBook-M2-2.local>
- Loading branch information
Showing
25 changed files
with
1,754 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.examples/tic-tac-toe/src/game-ship/evolve/GameEvolverComplex.ts.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { EvolverComplex } from "theseus-js"; | ||
import type { GameState } from "../state/GameState"; | ||
import { GameTurnEvolver } from "./evolvers/GameTurnEvolver"; | ||
import { GameBoardEvolver } from "./evolvers/GameBoardEvolver"; | ||
import { GameMetaEvolver } from "./evolvers/GameMetaEvolver"; | ||
|
||
<<<<<<< HEAD | ||
export const GameEvolverComplex = EvolverComplex.create<GameState>().withEvolvers( | ||
GameTurnEvolver, | ||
GameBoardEvolver, | ||
GameMetaEvolver, | ||
); | ||
======= | ||
export const GameEvolverComplex = EvolverComplex.create<GameState>().withEvolvers({ | ||
GameTurnEvolver, | ||
GameBoardEvolver, | ||
GameMetaEvolver, | ||
}); | ||
>>>>>>> main |
2 changes: 1 addition & 1 deletion
2
.examples/tic-tac-toe/src/game-ship/evolve/evolvers/GameBoardEvolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.examples/tic-tac-toe/src/game-ship/evolve/evolvers/GameBoardEvolver.ts.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Evolver } from "theseus-js"; | ||
import type { GameState, MarkType } from "../../state/GameState"; | ||
|
||
<<<<<<< HEAD | ||
export const GameBoardEvolver = Evolver.create("GameBoard", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
======= | ||
export const { GameBoardEvolver } = Evolver.create("GameBoardEvolver", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
>>>>>>> main | ||
* Set the mark at the given coordinates. | ||
*/ | ||
setMark: ({ mutableGameState }, coords: [number, number], mark: MarkType): GameState => | ||
{ | ||
const [row, col] = coords; | ||
mutableGameState.board[row][col] = mark; | ||
return mutableGameState; | ||
}, | ||
}); |
2 changes: 1 addition & 1 deletion
2
.examples/tic-tac-toe/src/game-ship/evolve/evolvers/GameMetaEvolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.examples/tic-tac-toe/src/game-ship/evolve/evolvers/GameMetaEvolver.ts.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Evolver } from "theseus-js"; | ||
import type { GameState, MarkType } from "../../state/GameState"; | ||
|
||
<<<<<<< HEAD | ||
export const GameMetaEvolver = Evolver.create("GameMeta", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
======= | ||
export const { GameMetaEvolver } = Evolver.create("GameMetaEvolver", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
>>>>>>> main | ||
* Update the last player to make a move. | ||
*/ | ||
updateLastPlayer: ({ mutableGameState }, mark: MarkType): GameState => | ||
{ | ||
mutableGameState.lastPlayer = mark; | ||
return mutableGameState; | ||
}, | ||
/** | ||
* Update the last played coordinates. | ||
*/ | ||
updateLastPlayedCoords: ({ mutableGameState }, coords: [number, number]): GameState => | ||
{ | ||
mutableGameState.lastPlayedCoords = coords; | ||
return mutableGameState; | ||
}, | ||
/** | ||
* Iterate the turn count. | ||
*/ | ||
iterateTurnCount: ({ mutableGameState }): GameState => | ||
{ | ||
mutableGameState.turns++; | ||
return mutableGameState; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.examples/tic-tac-toe/src/game-ship/evolve/evolvers/GameTurnEvolver.ts.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Evolver, getTheseusLogger } from "theseus-js"; | ||
import type { GameState } from "../../state/GameState"; | ||
import { GameBoardRefinery } from "../../refine/refineries/GameBoardRefinery"; | ||
import { GameBoardEvolver } from "./GameBoardEvolver"; | ||
import { GameMetaEvolver } from "./GameMetaEvolver"; | ||
|
||
const log = getTheseusLogger("GameTurnEvolver"); | ||
|
||
<<<<<<< HEAD | ||
export const GameTurnEvolver = Evolver.create("GameTurn", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
======= | ||
export const { GameTurnEvolver } = Evolver.create("GameTurnEvolver", { noun: "gameState" }) | ||
.toEvolve<GameState>() | ||
.withMutators({ | ||
/** | ||
>>>>>>> main | ||
* Set the winner of the game. | ||
*/ | ||
setWinner: ({ mutableGameState }, reason: "stalemate" | "winner") => | ||
{ | ||
log.major(`Game over! ${reason}`); | ||
mutableGameState.winner = reason === "winner" ? mutableGameState.lastPlayer : "stalemate"; | ||
return mutableGameState; | ||
}, | ||
/** | ||
* Take the next turn at a random available square. | ||
*/ | ||
nextTurn: ({ mutableGameState }): GameState => | ||
{ | ||
const { turns, lastPlayer } = mutableGameState; | ||
log.major(`Taking turn #${turns}`); | ||
|
||
const { getRandomAvailableCoords, getSquare } = GameBoardRefinery(mutableGameState); | ||
|
||
// Determine the mark for the next player | ||
const mark = lastPlayer === "X" ? "O" : "X"; | ||
const coords = getRandomAvailableCoords(); | ||
if (!coords) | ||
{ | ||
return GameTurnEvolver.mutate(mutableGameState).via.setWinner("stalemate"); | ||
} | ||
|
||
// Check if the square is available | ||
const isAvailable = !getSquare(coords); | ||
if (!isAvailable) | ||
{ | ||
throw new Error(`Square at ${coords} is already taken`); | ||
} | ||
|
||
// Set the mark on the board | ||
GameBoardEvolver.mutate(mutableGameState) | ||
.via.setMark(coords, mark); | ||
|
||
// Update the game metadata | ||
GameMetaEvolver.evolve(mutableGameState) | ||
.via.iterateTurnCount() | ||
.and.updateLastPlayer(mark) | ||
.and.updateLastPlayedCoords(coords); | ||
|
||
return mutableGameState; | ||
}, | ||
}); |
Oops, something went wrong.