Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Update to FenFurnace 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jul 4, 2021
1 parent 1c5b90c commit fa888ca
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
},
"dependencies": {
"faunadb": "^4.3.0",
"fenfurnace": "^0.2.6",
"novasheets": "^1.0.0"
"fenfurnace": "^0.3.0",
"novasheets": "^1.0.1"
},
"devDependencies": {
"@11ty/eleventy": "^0.12.1",
"webpack": "^5.41.1",
"webpack": "^5.42.0",
"webpack-cli": "^4.7.2"
}
}
2 changes: 1 addition & 1 deletion scripts/play/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function flipBoard() {

function alignBoard() {
const classes = document.body.classList;
if (global.currentTurn === 'b') {
if (gameData.currentTurn === 'b') {
classes.add('rotate');
classes.remove('norotate');
} else {
Expand Down
6 changes: 3 additions & 3 deletions scripts/play/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function botMove(botColour) {
// Generate list of good moves for later use
validSquares.forEach(obj => obj.moves.forEach(cell => {
const start = obj.cell, end = cell;
const march = botIntelligence === 1 && (global.currentTurn === 'w' ? start[1] < end[1] : start[1] > end[1]);
const march = botIntelligence === 1 && (gameData.currentTurn === 'w' ? start[1] < end[1] : start[1] > end[1]);
const charge = botIntelligence === 2 && pieceInCell(cell);
const attack = botIntelligence === 3 && pieceInCell(cell) && getPointsEquivalent(getPieceClasses(start)[1]) <= getPointsEquivalent(getPieceClasses(end)[1]);
validMoves.push({ start, end });
Expand Down Expand Up @@ -59,14 +59,14 @@ function forceBotMove() {
let curFen = createFen();
failedMoveCount = 0;
do {
botMove(global.currentTurn === 'w' ? 'white' : 'black');
botMove(gameData.currentTurn === 'w' ? 'white' : 'black');
if (createFen() === curFen) failedMoveCount++;
}
while (createFen() === curFen && ingame);
}

setInterval(function () {
if (window.gameOptions && window.gameOptions.bot && window.ingame && global.currentTurn === window.gameOptions.botColour[0]) {
if (window.gameOptions && window.gameOptions.bot && window.ingame && gameData.currentTurn === window.gameOptions.botColour[0]) {
forceBotMove();
}
}, 650);
7 changes: 3 additions & 4 deletions scripts/play/fen.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const defaultFen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0';

function createFen() {
return global.moveList.slice(-1)[0];
return gameData.moveList[gameData.moveList.length - 1];
}

function getTakenPiecesFromFen() {
const fenString = global.moveList.slice(-1)[0];
const fenString = createFen();
let pieces = { b: 'pppppppprnbqkbnr', w: 'PPPPPPPPRNBQKBNR' };
for (let i in fenString.split(' ')[0]) {
const c = fenString[i];
for (const c of fenString.split(' ')[0]) {
const col = c.toLowerCase() === c ? 'b' : 'w';
pieces[col] = pieces[col].replace(c, '');
}
Expand Down
30 changes: 15 additions & 15 deletions scripts/play/game-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ function hasClicked(cell) {
if (
!window.ingame
|| gameOptions.spectating
|| gameOptions.multiplayer && global.currentTurn !== window.playerTurn[0]
|| gameOptions.multiplayer && gameData.currentTurn !== window.playerTurn[0]
) return;

cell = cell.toUpperCase();
const $cell = $.id('piece' + cell);
const cellClasses = $cell ? Array.from($cell.classList) : [];
const cellClasses = Array.from($cell?.classList ?? []);

// Cancel a move //
if (cell === selectedCell) {
Expand Down Expand Up @@ -39,17 +39,17 @@ function hasClicked(cell) {

// promotion
const canPromote = piece === 'pawn' && ['1', '8'].includes(endCell[1]);
if (canPromote && !global.promotionPiece) {
global.promotionPiece = getPieceID(window.promotionPiece) || 'q';
if (canPromote && !gameData.promotionPiece) {
gameData.promotionPiece = getPieceID(window.promotionPiece) || 'q';
}

// move the piece
const moveOutput = validation.makeMove(startCell, endCell);
const moveOutput = makeMove(startCell, endCell);
if (window.hasRules) {
if (!moveOutput) {
console.log('I', startCell, '->', endCell);
if (getPieceClasses(endCell)[0] === colour) selectPiece(endCell);
else selectPiece(startCell);
const pieceToSelect = getPieceClasses(endCell)[0] === colour ? endCell : startCell;
selectPiece(pieceToSelect);
return;
}
createBoardFromFen(moveOutput);
Expand Down Expand Up @@ -78,7 +78,7 @@ function hasClicked(cell) {
checkGameEnding();

// check if correct puzzle move has been made
if (window.gameOptions.puzzles && puzzleColour === global.currentTurn && window.movesToMake) {
if (window.gameOptions.puzzles && puzzleColour === gameData.currentTurn && window.movesToMake) {
puzzleMoveOutput(startCell, endCell);
}

Expand All @@ -88,13 +88,13 @@ function hasClicked(cell) {
}

// Select piece //
else if ($cell && (!window.hasRules || cellClasses.includes(global.currentTurn === 'w' ? 'white' : 'black'))) {
else if ($cell && (!window.hasRules || cellClasses.includes(gameData.currentTurn === 'w' ? 'white' : 'black'))) {
// the piece is selectable
// mark this piece as being in process of moving

const isPawn = cellClasses.includes('pawn');
const whiteRow2 = cellClasses.includes('white') && +cell[1] === 7;
const blackRow2 = cellClasses.includes('black') && +cell[1] === 2;
const whiteRow2 = cellClasses.includes('white') && cell[1] === '7';
const blackRow2 = cellClasses.includes('black') && cell[1] === '2';
if (isPawn && (!window.hasRules || whiteRow2 || blackRow2)) {
$.id('promotion').classList.remove('hide');
}
Expand Down Expand Up @@ -125,17 +125,17 @@ function checkHighlight() {
}

function checkGameEnding() {
const endingStatus = gameEndingStatus(global.currentTurn);
const endingStatus = gameEndingStatus(gameData.currentTurn);
if (!endingStatus) return;
const winner = global.currentTurn !== 'w' ? 'white' : 'black';
const winner = gameData.currentTurn !== 'w' ? 'white' : 'black';
const winText = winner + ' wins';
const statusMsg = endingStatus === 'stalemate' ? 'Stalemate' : winText;
$('#winner').innerText = statusMsg;
window.ingame = false;
}

function undoLastMove() {
if (window.totalMoves === 0 || global.moveList.length === 0) return;
if (window.totalMoves === 0 || gameData.moveList.length === 0) return;
createBoardFromFen(undoMove());
window.ingame = true;
window.totalMoves--;
Expand All @@ -146,7 +146,7 @@ function undoLastMove() {
$('#log').removeChild($('#log').lastChild);
$('#winner').innerText = '';
if (window.autoPing) sendDB();
if (gameOptions.bot && global.currentTurn === gameOptions.botColour[0]) undoLastMove();
if (gameOptions.bot && gameData.currentTurn === gameOptions.botColour[0]) undoLastMove();
}

function threefoldRepetition() {
Expand Down
4 changes: 2 additions & 2 deletions scripts/play/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function readDB() {
checkHighlight();
}
if (moves) {
global.logList = moves.split(',');
gameData.logList = moves.split(',');
updateMoves();
}
if (points) {
Expand Down Expand Up @@ -57,7 +57,7 @@ async function sendDB(soft) {
'type=send',
`gameId=${encodeURIComponent(window.gameId)}`,
!soft && `fen=${encodeURIComponent(fen)}`,
!soft && `moves=${global.logList.join(',')}`,
!soft && `moves=${gameData.logList.join(',')}`,
!soft && `lastMove=${window.lastMove.start},${window.lastMove.end}`,
!soft && `points=${window.points.w},${window.points.b}`,
window.playerTurn && `${window.playerTurn}=${window.username}[]${window.userElo}`,
Expand Down
2 changes: 1 addition & 1 deletion scripts/play/pagelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function log({ startCell, endCell, startClasses, endClasses, taken, promoted })

function updateMoves() {
let moveHtml = '';
for (let [n, move] of Object.entries(global.logList)) {
for (let [n, move] of Object.entries(gameData.logList)) {
moveHtml += ' <span class="move">';
let isWhite = n % 2 === 0;
if (isWhite) moveHtml += `<br class="desktoponly">` + (n / 2 + 1) + '. ';
Expand Down
4 changes: 2 additions & 2 deletions scripts/play/puzzles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function getPuzzles(start) {

function puzzleMove() {
const [, start, end, promotion] = movesToMake[0].toUpperCase().match(/^(..)(..)(.?)/);
if (promotion) global.promotionPiece = promotion;
if (promotion) gameData.promotionPiece = promotion;
hasClicked(start);
hasClicked(end);
movesToMake.shift();
Expand All @@ -67,7 +67,7 @@ function setBoard(item) {
movesToMake = savedPuzzles[item].Moves.split(' ');
alignBoard();
flipBoard();
puzzleColour = global.currentTurn;
puzzleColour = gameData.currentTurn;
setTimeout(puzzleMove, 1000);
}

Expand Down
1 change: 0 additions & 1 deletion styles/common.nvss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300&family=Source+Sans+Pro:wght@300&display=swap');
{}
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300&display=swap');

* {
Expand Down

0 comments on commit fa888ca

Please sign in to comment.