Skip to content

Commit

Permalink
feat: upgrade deps to latest (#58)
Browse files Browse the repository at this point in the history
* feat: upgrade deps to latest

* feat: upgrade infra
  • Loading branch information
kenrick95 authored Jun 27, 2024
1 parent e287baf commit a0ba44a
Show file tree
Hide file tree
Showing 29 changed files with 1,451 additions and 1,652 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

strategy:
matrix:
node-version: [18]
node-version: [18, 20]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.7
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Build
run: yarn workspace @kenrick95/c4-browser run build-gh-pages
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
branch: gh-pages
folder: browser/dist
Expand All @@ -42,6 +42,6 @@ jobs:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.7
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
893 changes: 0 additions & 893 deletions .yarn/releases/yarn-4.0.1.cjs

This file was deleted.

894 changes: 894 additions & 0 deletions .yarn/releases/yarn-4.3.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.1.cjs
yarnPath: .yarn/releases/yarn-4.3.1.cjs
3 changes: 2 additions & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kenrick95/c4-browser",
"private": true,
"version": "1.0.0",
"type": "module",
"description": "Connect Four game in browser",
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,6 +41,6 @@
"devDependencies": {
"prettier": "3.3.2",
"typescript": "~5.5.2",
"vite": "^4.5.3"
"vite": "^5.3.1"
}
}
2 changes: 1 addition & 1 deletion browser/public/demo/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down
4 changes: 2 additions & 2 deletions browser/src/board/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BoardBase, BoardPiece } from '@kenrick95/c4'
import { Player } from '@kenrick95/c4'
import { Player } from '@kenrick95/c4'
import { onresize, drawMask, drawCircle, clearCanvas } from './utils'
import { animationFrame } from '../utils/animate-frame'

Expand Down Expand Up @@ -63,7 +63,7 @@ export class Board extends BoardBase {
private async animateAction(
newRow: number,
column: number,
boardPiece: BoardPiece
boardPiece: BoardPiece,
): Promise<void> {
const fillStyle = this.getPlayerColor(boardPiece)
let currentY = 0
Expand Down
6 changes: 3 additions & 3 deletions browser/src/board/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function onresize(): { add: Function } {

export function drawCircle(
context: CanvasRenderingContext2D,
{ x = 0, y = 0, r = 0, fillStyle = '', strokeStyle = '' }
{ x = 0, y = 0, r = 0, fillStyle = '', strokeStyle = '' },
) {
context.save()
context.fillStyle = fillStyle
Expand Down Expand Up @@ -73,13 +73,13 @@ export function drawMask(board: Board) {
tripleRadius * y + Board.MASK_Y_BEGIN + doubleRadius,
Board.PIECE_RADIUS,
0,
2 * Math.PI
2 * Math.PI,
)
context.rect(
tripleRadius * x + Board.MASK_X_BEGIN + 2 * doubleRadius,
tripleRadius * y + Board.MASK_Y_BEGIN,
-2 * doubleRadius,
2 * doubleRadius
2 * doubleRadius,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion browser/src/game/game-ai-vs-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { animationFrame } from '../utils/animate-frame'
const statusbox = document.querySelector('.statusbox')
const statusboxBodyGame = document.querySelector('.statusbox-body-game')
const statusboxBodyConnection = document.querySelector(
'.statusbox-body-connection'
'.statusbox-body-connection',
)
const statusboxBodyPlayer = document.querySelector('.statusbox-body-player')

Expand Down
8 changes: 4 additions & 4 deletions browser/src/game/game-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export class GameLocal extends GameBase {
winnerBoardPiece === BoardPiece.DRAW
? `It's a draw`
: winnerPlayer
? `${winnerPlayer.label} ${winnerPlayer.boardPiece} won`
: `Player ${
winnerBoardPiece === BoardPiece.PLAYER_1 ? '1 🔴' : '2 🔵'
} won`
? `${winnerPlayer.label} ${winnerPlayer.boardPiece} won`
: `Player ${
winnerBoardPiece === BoardPiece.PLAYER_1 ? '1 🔴' : '2 🔵'
} won`
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions browser/src/game/game-online-2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ export class GameOnline2p extends GameBase {
winnerBoardPiece === BoardPiece.DRAW
? `It's a draw`
: winnerPlayer
? `${winnerPlayer.label} ${winnerPlayer.boardPiece} won`
: `Player ${
winnerBoardPiece === BoardPiece.PLAYER_1 ? '1 🔴' : '2 🔵'
} won`
? `${winnerPlayer.label} ${winnerPlayer.boardPiece} won`
: `Player ${
winnerBoardPiece === BoardPiece.PLAYER_1 ? '1 🔴' : '2 🔵'
} won`

showMessage(
`<h1>Thank you for playing</h1>` +
Expand Down
2 changes: 1 addition & 1 deletion browser/src/utils/animate-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export function animationFrame(): Promise<Function> {
let resolve: Function | null = null
const promise: Promise<Function> = new Promise(
(r: Function): Function => (resolve = r)
(r: Function): Function => (resolve = r),
)

if (resolve) window.requestAnimationFrame(resolve)
Expand Down
2 changes: 1 addition & 1 deletion browser/src/utils/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function showMessage(message: string = ''): void {
return
}
const messageContentDOM: HTMLDivElement | null = document.querySelector(
'.message-body-content'
'.message-body-content',
)
if (!messageContentDOM) {
console.error('.message-body-content not found')
Expand Down
7 changes: 4 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kenrick95/c4",
"version": "5.0.0",
"description": "Building blocks for a Connect Four game",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/kenrick95/c4.git"
Expand Down Expand Up @@ -53,9 +54,9 @@
"devDependencies": {
"prettier": "3.3.2",
"typescript": "~5.5.2",
"vite": "^4.5.3",
"vite": "^5.3.1",
"vite-dts": "^1.0.4",
"vite-plugin-dts": "^3.6.3",
"vitest": "^0.34.6"
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion core/src/__testHelpers/test-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TestGame extends GameBase {

renewAfterMovePromise() {
this.afterMovePromise = new Promise(
(resolve) => (this.afterMoveResolve = resolve)
(resolve) => (this.afterMoveResolve = resolve),
)
}
}
2 changes: 1 addition & 1 deletion core/src/__testHelpers/test-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TestPlayer extends Player {
}
renewPromise() {
this.getActionWaiting = new Promise(
(resolve) => (this.getActionWaitingResolver = resolve)
(resolve) => (this.getActionWaitingResolver = resolve),
)
}
async getAction() {
Expand Down
12 changes: 6 additions & 6 deletions core/src/board/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class BoardBase {
Math.max(
0,
BoardBase.CANVAS_WIDTH -
(3 * BoardBase.COLUMNS + 1) * BoardBase.PIECE_RADIUS
(3 * BoardBase.COLUMNS + 1) * BoardBase.PIECE_RADIUS,
) / 2
BoardBase.MASK_Y_BEGIN =
Math.max(
0,
BoardBase.CANVAS_HEIGHT -
(3 * BoardBase.ROWS + 1) * BoardBase.PIECE_RADIUS
(3 * BoardBase.ROWS + 1) * BoardBase.PIECE_RADIUS,
) / 2
BoardBase.MESSAGE_WIDTH = BoardBase.SCALE * 400
BoardBase.MESSAGE_X_BEGIN =
Expand All @@ -76,7 +76,7 @@ export class BoardBase {
const { success: actionSuccessful, map: nextState } = getMockPlayerAction(
this.map,
player.boardPiece,
column
column,
)

this.map = nextState
Expand Down Expand Up @@ -108,7 +108,7 @@ export class BoardBase {
j: number,
playerPiece: BoardPiece,
dir: Array<number>,
count: number
count: number,
): boolean => {
if (count >= 4) {
return true
Expand All @@ -127,7 +127,7 @@ export class BoardBase {
j + dir[1],
playerPiece,
dir,
count + 1
count + 1,
)
}
let countEmpty = 0
Expand All @@ -141,7 +141,7 @@ export class BoardBase {
j + direction[k][1],
playerPiece,
direction[k],
1
1,
)
if (isWon) {
return (this.winnerBoardPiece = playerPiece)
Expand Down
2 changes: 1 addition & 1 deletion core/src/game/game-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export abstract class GameBase<P extends Player = Player> {
this.beforeMoveApplied(action)
actionSuccesful = await this.board.applyPlayerAction(
currentPlayer,
action
action,
)
this.isMoveAllowed = true
if (!actionSuccesful) {
Expand Down
5 changes: 4 additions & 1 deletion core/src/game/game-online/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export type GameOnlineMessage =
}
| { type: 'NEW_MATCH_REQUEST'; payload: { playerId: PlayerId } }
| { type: 'NEW_MATCH_OK'; payload: { matchId: MatchId } }
| { type: 'GAME_READY'; payload: { matchId: MatchId; otherPlayerName: string } }
| {
type: 'GAME_READY'
payload: { matchId: MatchId; otherPlayerName: string }
}
| {
type: 'GAME_ENDED'
payload: {
Expand Down
22 changes: 11 additions & 11 deletions core/src/player/player-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class PlayerAi extends Player {
return boardPiece === BoardPiece.EMPTY
? 0
: boardPiece === this.boardPiece
? 1
: -1
? 1
: -1
}
private getStateValue(state: Array<Array<BoardPiece>>): {
winnerBoardPiece: BoardPiece
Expand Down Expand Up @@ -96,7 +96,7 @@ export class PlayerAi extends Player {
private transformValues(
returnValue: number,
winnerBoardPiece: BoardPiece,
depth: number
depth: number,
): number {
const isWon = winnerBoardPiece === this.boardPiece
const isLost = winnerBoardPiece === this.enemyBoardPiece
Expand All @@ -114,7 +114,7 @@ export class PlayerAi extends Player {
state: Array<Array<BoardPiece>>,
depth: number,
alpha: number,
beta: number
beta: number,
): {
value: number
move: number
Expand All @@ -129,7 +129,7 @@ export class PlayerAi extends Player {
this.transformValues(
stateValue.chain,
stateValue.winnerBoardPiece,
depth
depth,
) * this.ownBoardPieceValue,
move: -1, // leaf node
}
Expand All @@ -144,7 +144,7 @@ export class PlayerAi extends Player {
state: Array<Array<BoardPiece>>,
depth: number,
alpha: number,
beta: number
beta: number,
): {
value: number
move: number
Expand All @@ -155,7 +155,7 @@ export class PlayerAi extends Player {
const { success: actionSuccessful, map: nextState } = getMockPlayerAction(
state,
this.boardPiece,
column
column,
)
if (!actionSuccessful) {
continue
Expand Down Expand Up @@ -187,7 +187,7 @@ export class PlayerAi extends Player {
state: Array<Array<BoardPiece>>,
depth: number,
alpha: number,
beta: number
beta: number,
): {
value: number
move: number
Expand All @@ -198,7 +198,7 @@ export class PlayerAi extends Player {
const { success: actionSuccessful, map: nextState } = getMockPlayerAction(
state,
this.enemyBoardPiece,
column
column,
)
if (!actionSuccessful) {
continue
Expand Down Expand Up @@ -233,10 +233,10 @@ export class PlayerAi extends Player {
state,
0,
BIG_NEGATIVE_NUMBER,
BIG_POSITIVE_NUMBER
BIG_POSITIVE_NUMBER,
)
console.log(
`AI ${this.boardPiece} choose column ${action.move} with value of ${action.value}`
`AI ${this.boardPiece} choose column ${action.move} with value of ${action.value}`,
)
return action.move
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const BIG_NEGATIVE_NUMBER: number = -BIG_POSITIVE_NUMBER
export function isCoordOnColumn(
coord: { x: number; y: number },
columnXBegin: number,
radius: number
radius: number,
): boolean {
return (coord.x - columnXBegin) * (coord.x - columnXBegin) <= radius * radius
}
Expand All @@ -25,7 +25,7 @@ export function getColumnFromCoord(coord: { x: number; y: number }): number {
3 * BoardBase.PIECE_RADIUS * i +
BoardBase.MASK_X_BEGIN +
2 * BoardBase.PIECE_RADIUS,
BoardBase.PIECE_RADIUS
BoardBase.PIECE_RADIUS,
)
)
return i
Expand All @@ -52,7 +52,7 @@ export function clone<T>(array: Array<Array<T>>): Array<Array<T>> {
export function getMockPlayerAction(
map: Array<Array<BoardPiece>>,
boardPiece: BoardPiece,
column: number
column: number,
): {
success: boolean
map: Array<Array<BoardPiece>>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"url": "https://github.com/kenrick95/c4/issues"
},
"engines": {
"node": "18.x",
"node": "18.x || 20.x",
"yarn": "4.x"
},
"packageManager": "yarn@4.0.1",
"packageManager": "yarn@4.3.1",
"homepage": "https://github.com/kenrick95/c4",
"license": "MIT",
"keywords": [
Expand Down
Loading

0 comments on commit a0ba44a

Please sign in to comment.