Skip to content

Commit

Permalink
refactor (#99)
Browse files Browse the repository at this point in the history
* Feature/save game (#65)

* feat: add saving game

* refactor

* fix

* fix: some bug

* feat: better ai

* fix: tests en passant

* fix: isValidMove returns true for en passant capture

* fix: isValidMove returns true for en passant capture

* fix: add true

* Create CODE_OF_CONDUCT.md

Signed-off-by: Antoine Greuzard <[email protected]>

* Update issue templates

* refactor ai

* refactor board

* refactor piece

* refactor pieces

* refactor utils

* refactor canvas

* refactor timer

* fix: drag impossible on ai pieces

* fix: remove save game

---------

Signed-off-by: Antoine Greuzard <[email protected]>
Co-authored-by: Antoine GREUZARD <[email protected]>

* fix: remove saveGameToFile

* Update pull_request_template.md

Signed-off-by: Antoine Greuzard <[email protected]>

* fix: remove saveGameToFile

* refactor: add ai folder

* Create dependabot.yml

Signed-off-by: Antoine Greuzard <[email protected]>

* feat: add some jobs

* fix: add token

* fix: rename token to github_token

* feat: add letters and x,y on canvas

* remove dependabot

* feat: add @size-limit

* remove size-limit

* remove size-limit

* remove size-limit job

* feat: better sort

* feat: better quiescence

* feat: better board evaluation

* feat: better opening move

* feat: add tests

* feat: add tests

* feat: add tests

* feat: add tests

* feat: add tests

* feat: add tests

* refactor

* refactor

* refactor: console.log deleted

* refactor

* restore handlePromotion

* fix: add static

* fix: bug with build

* refactor

* Feature/ai json (#93)

* feat: add games.json

* refactor

* refactor

* fix: getAnalyzedMove

* fix: rework endgame and openinggame

* fxi: rework getAnalyzedMove

* fix: working positionKey with FEN string

* feat: better minimax

* feat: add Multi-Cut Pruning

* feat: add determineGamePhase

* feat: better killermoves

* feat: better evaluator

* feat: increase to 5

* feat: use ProbCut

* feat: use Aspiration Windows

* feat: add Contextual Move Ordering

* feat: increase maxTime

* fix maxtime

* feat: increase maxtime

* refactor

* feat: use a random

* feat: diffrent maxtime at each turn

* feat: better usage of maxTime

* feat: use node 20

* refactor

---------

Signed-off-by: Antoine Greuzard <[email protected]>
Co-authored-by: Antoine GREUZARD <[email protected]>
  • Loading branch information
antoinegreuzard and Antoine GREUZARD authored Nov 4, 2024
1 parent ceee892 commit 70e120f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"preview": "vite preview",
"prettier": "prettier --write 'src/**/*.{js,ts,html,css}'",
"prettier-check": "prettier --check 'src/**/*.{js,ts,html,css}'",
"lint": "eslint 'src/**/*.{js,ts}' --config ./eslint.config.js",
"lint": "eslint src/**/*.{js,ts} --config ./eslint.config.js",
"test-server": "npm run start & sleep 5 && pkill -f vite",
"test": "jest",
"check-node-version": "node -e \"if (parseInt(process.versions.node.split('.')[0]) !== 20) throw new Error('This project requires Node.js v20. Please install it.');\"",
Expand Down
19 changes: 1 addition & 18 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,14 @@ export class Game {
toX: number;
toY: number;
} | null = null;
private readonly moveHistory: {
fromX: number;
fromY: number;
toX: number;
toY: number;
pieceType: PieceType;
}[][];

constructor(
playerColor: PieceColor,
moveHistory: {
fromX: number;
fromY: number;
toX: number;
toY: number;
pieceType: PieceType;
}[][],
) {
constructor(playerColor: PieceColor) {
this.board = new Board();
this.aiWorker = new Worker(new URL('./ai.worker.ts', import.meta.url), {
type: 'module',
});
this.aiColor =
playerColor === PieceColor.WHITE ? PieceColor.BLACK : PieceColor.WHITE;
this.moveHistory = moveHistory;
}

public async getBoard(): Promise<Board> {
Expand Down
36 changes: 22 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Game } from './game';
import { CanvasRenderer } from './canvas-renderer';
import { Timer } from './timer';
import { PieceColor, PieceType } from './piece';
import { BoardInterface, PieceColor, PieceType } from './piece';
import {
getPieceSymbol,
showMessage,
Expand All @@ -18,7 +18,7 @@ export async function initializeGame(playerColor: PieceColor) {
toY: number;
pieceType: PieceType;
}[][] = [[]];
const game = new Game(playerColor, moveHistory);
const game = new Game(playerColor);
const board = await game.getBoard();
board.setPlayerColor(playerColor);

Expand Down Expand Up @@ -105,18 +105,26 @@ export async function initializeGame(playerColor: PieceColor) {

function showPromotionDialog(x: number, y: number, board: BoardInterface) {
const promotionDialog = document.getElementById('promotionDialog');
promotionDialog.style.display = 'block';

// Définir le callback de promotion pour gérer la sélection de pièce
window.promote = (pieceType: string) => {
board.promotePawn(x, y, pieceType); // Promouvoir le pion
promotionDialog.style.display = 'none'; // Masquer la boîte de dialogue

// Met à jour l'affichage de l'historique et du plateau après la promotion
addMoveToHistory(x, y, x, y, PieceType[pieceType.toUpperCase()]);
renderer.drawBoard();
updateTurn();
};
if (promotionDialog) {
promotionDialog.style.display = 'block';

// Définir le callback de promotion pour gérer la sélection de pièce
window.promote = (pieceType: string) => {
board.promotePawn(x, y, pieceType); // Promouvoir le pion
promotionDialog.style.display = 'none'; // Masquer la boîte de dialogue

// Met à jour l'affichage de l'historique et du plateau après la promotion
addMoveToHistory(
x,
y,
x,
y,
PieceType[pieceType.toUpperCase() as keyof typeof PieceType],
);
renderer.drawBoard();
updateTurn();
};
}
}

async function updateTurn() {
Expand Down
6 changes: 5 additions & 1 deletion src/piece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export interface BoardInterface {
toY: number,
): boolean;

promotePawn(x: number, y: number, pieceType: PieceType): Promise<void>;
promotePawn(
x: number,
y: number,
pieceType: PieceType | string,
): Promise<void>;

isSquareUnderAttack(x: number, y: number, color: PieceColor): boolean;

Expand Down

0 comments on commit 70e120f

Please sign in to comment.