Skip to content

Commit

Permalink
feat: upgrade deps to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick95 committed Jun 27, 2024
1 parent e287baf commit bed7e54
Show file tree
Hide file tree
Showing 24 changed files with 297 additions and 499 deletions.
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
16 changes: 8 additions & 8 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
"test": "echo 'OK'"
},
"devDependencies": {
"@types/node": "^20.8.10",
"@types/uuid": "^9.0.6",
"@types/ws": "^8.5.8",
"@types/node": "^20.14.9",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.10",
"prettier": "3.3.2",
"typescript": "~5.5.2",
"vite": "^4.5.3",
"vite-node": "0.34.6"
"vite": "^5.3.1",
"vite-node": "1.6.0"
},
"dependencies": {
"@kenrick95/c4": "workspace:^",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"uuid": "^9.0.1",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
"uuid": "^10.0.0",
"ws": "^8.17.1"
}
}
7 changes: 5 additions & 2 deletions server/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export enum ACTION_TYPE {
END_GAME = 'END_GAME',
RESET_GAME = 'RESET_GAME',
}
export function newPlayerConnection(ws: WebSocket, playerName: string): AppThunk<PlayerId> {
export function newPlayerConnection(
ws: WebSocket,
playerName: string,
): AppThunk<PlayerId> {
return (dispatch) => {
const playerId = uuidV4()
dispatch({
Expand Down Expand Up @@ -126,7 +129,7 @@ export function connectMatch(
const match = state.matches[matchId]
const playerIds = match.players.filter((p): p is string => !!p)

for (let i = 0; i < playerIds.length; i++) {
for (let i = 0; i < playerIds.length; i++) {
const player = state.players[playerIds[i]]
const otherPlayer = state.players[i === 0 ? playerIds[1] : playerIds[0]]
player.ws.send(
Expand Down
Loading

0 comments on commit bed7e54

Please sign in to comment.