From 80190168e96054cce8cfdce942e289d2c5675dfc Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:40:42 +0530 Subject: [PATCH 1/7] Solved Default queen promotion --- activities/Chess.activity/css/activity.css | 39 +++++ activities/Chess.activity/js/chessGame.js | 185 ++++++++++++++++----- 2 files changed, 183 insertions(+), 41 deletions(-) diff --git a/activities/Chess.activity/css/activity.css b/activities/Chess.activity/css/activity.css index 2cff62e2d0..9f6c52b6fc 100644 --- a/activities/Chess.activity/css/activity.css +++ b/activities/Chess.activity/css/activity.css @@ -470,4 +470,43 @@ body { -webkit-box-shadow: 0 0 0 0rem rgba(158, 158, 158, .5); box-shadow: 0 0 0 0rem rgba(158, 158, 158, .5); border: 0px; +} +.promotion-dialog { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.5); + display: flex; + justify-content: center; + align-items: center; + z-index: 1000; +} + +.promotion-content { + background: white; + padding: 20px; + border-radius: 8px; + text-align: center; + box-shadow: 0 2px 10px rgba(0,0,0,0.1); +} + +.promotion-pieces { + display: flex; + justify-content: center; + gap: 20px; + margin-top: 15px; +} + +.piece { + font-size: 48px; + cursor: pointer; + padding: 10px; + border-radius: 4px; + transition: background-color 0.2s; +} + +.piece:hover { + background: #eee; } \ No newline at end of file diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 6781850dec..60887eb036 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -12,39 +12,45 @@ var ChessGame = { template: `
- -
- - -
-
-
- -
-
PC
-
_:_
-
{{parsedOpponentClockTime}}
-
- -
-
-
{{infotext}}
-
-
- -
-
_:_
-
{{parsedClockTime}}
+
+
+ +
+
+

Choose Promotion Piece

+
+
+
+
+
+
+
-
-
-
-
    - +
+
+
-
+
`, props: ['currentuser', 'opponentuser', 'presence', 'ishost', 'humane'], data: function() { @@ -94,6 +99,13 @@ var ChessGame = { clockTime: 30, opponentClockTime: 30, clockTotalTime: 30, + showPromotionDialog: false, + pendingMove: { + source: null, + target: null, + piece: null, + turn: null, + }, l10n: { stringYouWon: '', stringYouCheck: '', @@ -445,7 +457,22 @@ var ChessGame = { var turn = this.playercolor ? this.state.moveno % 2 != 0 : this.state.moveno % 2 == 0; if (!this.opponentuser || (this.opponentuser && turn)) { this.removeGreySquares(); - + const piece = this.board.position()[source]; + const isWhitePawn = piece === 'wP'; + const isBlackPawn = piece === 'bP'; + const isLastRank = target[1] === '8'; + const isFirstRank = target[1] === '1'; + + if ((isWhitePawn && isLastRank) || (isBlackPawn && isFirstRank)) { + this.pendingMove = { + source: source, + target: target, + piece: piece, + turn: turn + }; + this.showPromotionDialog = true; + return; // Wait for promotion choice + } var move = this.state.move(source, target); // illegal move @@ -718,8 +745,84 @@ var ChessGame = { } this.opponentClockTime = this.clockTotalTime; - } - + }, + handlePromotion: function(pieceType) { + if (!this.pendingMove.source || !this.pendingMove.target) { + this.showPromotionDialog = false; + return; + } + + this.showPromotionDialog = false; + const { source, target } = this.pendingMove; + + var move = this.state.move(source, target, P4_PIECE_LUT[pieceType]); + + // illegal move + if (move.flags === 0) { + this.board.position(p4_state2fen(this.state, true)); + return; + } + + if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) { + this.game_won = true; + this.board.position(p4_state2fen(this.state, true)); + return; + } else if (!(move.flags & 1<<1) && (((move.flags & 1<<0) && move.flags & 1<<2) || move.flags & (1<<6))) { + this.game_draw = true; + this.board.position(p4_state2fen(this.state, true)); + return; + } else { + this.game_check = false; + } + + if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) { + this.other_check = true; + } else { + this.other_check = false; + } + + this.board.position(p4_state2fen(this.state, true)); + + if (this.opponentuser) { + if (this.ishost) { + this.stopClock = true; + this.stopOpponentClock = false; + } + } else { + this.stopClock = true; + this.stopOpponentClock = false; + } + + $('#player-clock').css('border-style', 'none'); + $('#opponent-clock').css('border-style', 'solid'); + + if (this.opponentuser) { + this.$emit('sendmove', { + data: { + chessColor: this.playercolor, + state: this.state, + game_won: this.game_lost, + game_lost: this.game_won, + game_draw: this.game_draw, + game_check: this.other_check, + } + }); + } + + this.updateMoves(); + + // Reset pending move + this.pendingMove = { + source: null, + target: null, + piece: null, + turn: null + }; + + if (!this.opponentuser) { + window.setTimeout(this.makeRandomMove, 250); + } + }, } } From 17733be51db9c1768f730e63fcaaf583b4b72767 Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Thu, 16 Jan 2025 10:25:38 +0530 Subject: [PATCH 2/7] UI Improved Original Indentation of file is restored along with that improved ui of promotion box Added translation of promotion Title --- activities/Chess.activity/css/activity.css | 50 +++++++---- activities/Chess.activity/js/chessGame.js | 96 ++++++++++++---------- activities/Chess.activity/locales/en.json | 1 + activities/Chess.activity/locales/es.json | 1 + activities/Chess.activity/locales/fr.json | 1 + 5 files changed, 91 insertions(+), 58 deletions(-) diff --git a/activities/Chess.activity/css/activity.css b/activities/Chess.activity/css/activity.css index 9f6c52b6fc..4ae46675d1 100644 --- a/activities/Chess.activity/css/activity.css +++ b/activities/Chess.activity/css/activity.css @@ -471,6 +471,7 @@ body { box-shadow: 0 0 0 0rem rgba(158, 158, 158, .5); border: 0px; } + .promotion-dialog { position: fixed; top: 0; @@ -486,27 +487,46 @@ body { .promotion-content { background: white; - padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 10px rgba(0,0,0,0.1); + min-width: 300px; } -.promotion-pieces { +.dialog-header { + background:#9e9e9e; + padding: 10px 15px; display: flex; - justify-content: center; - gap: 20px; - margin-top: 15px; + justify-content: space-between; + align-items: center; + border-bottom: 1px solid #ddd; + border-radius: 8px 8px 0 0; } -.piece { - font-size: 48px; - cursor: pointer; - padding: 10px; - border-radius: 4px; - transition: background-color 0.2s; -} +.dialog-header h3 { + margin: 0; + font-size: 16px; + color: #ffffff; + font-weight: 500; + font-family: "Helvetica Neue", Inter, ui-sans-serif, "Apple Color Emoji", Helvetica, Arial, sans-serif; + } -.piece:hover { - background: #eee; -} \ No newline at end of file + .promotion-pieces { + display: flex; + justify-content: center; + gap: 20px; + margin: 15px; + padding: 10px; + } + + .piece { + font-size: 96px; + cursor: pointer; + padding: 10px; + border-radius: 4px; + transition: background-color 0.2s; + } + + .piece:hover { + background: #eee; + } \ No newline at end of file diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 60887eb036..f68e0d3fe8 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -12,45 +12,53 @@ var ChessGame = { template: `
-
-
- -
-
-

Choose Promotion Piece

-
-
-
-
-
-
-
+ +
+ + +
+
+
+
+

Choose Promotion Piece

+
+
+
+
+
+
+
+
+ +
+
+ +
+
PC
+
_:_
+
{{parsedOpponentClockTime}}
+
-
-
- -
-
PC
-
_:_
-
{{parsedOpponentClockTime}}
-
-
-
-
{{infotext}}
-
-
- -
-
_:_
-
{{parsedClockTime}}
-
-
+
+
+
{{infotext}}
+
+
+ +
+
_:_
+
{{parsedClockTime}}
-
-
    - +
+
+
-
- `, +
+ ` + , props: ['currentuser', 'opponentuser', 'presence', 'ishost', 'humane'], data: function() { return { diff --git a/activities/Chess.activity/locales/en.json b/activities/Chess.activity/locales/en.json index aa41433040..c8e821aabb 100644 --- a/activities/Chess.activity/locales/en.json +++ b/activities/Chess.activity/locales/en.json @@ -21,6 +21,7 @@ "PrevShort": "Prev", "NextShort": "Next", "EndShort": "End", + "PromotionTitle":"Choose Promotion Piece", "TutoWelcomeTitle": "Chess Activity", "TutoWelcomeContent": "Chess activity is a fun way to learn and challenge your friends to a game of Chess.", "TutoBoardTitle": "Chess Board", diff --git a/activities/Chess.activity/locales/es.json b/activities/Chess.activity/locales/es.json index 05bcc79174..ac97ad79ea 100644 --- a/activities/Chess.activity/locales/es.json +++ b/activities/Chess.activity/locales/es.json @@ -21,6 +21,7 @@ "PrevShort": "Ant", "NextShort": "Sig", "EndShort": "Fin", + "PromotionTitle":"Elegir pieza de promoción", "TutoWelcomeTitle": "Actividad \"Ajedrez\"", "TutoWelcomeContent": "La actividad \"Ajedrez\" es una manera divertida de aprender a jugar y retar a tus amigos a una partida de ajedrez.", "TutoBoardTitle": "Tablero de ajedrez", diff --git a/activities/Chess.activity/locales/fr.json b/activities/Chess.activity/locales/fr.json index 50d1796ec5..1f050f1250 100644 --- a/activities/Chess.activity/locales/fr.json +++ b/activities/Chess.activity/locales/fr.json @@ -21,6 +21,7 @@ "PrevShort": "Préc", "NextShort": "Suiv", "EndShort": "Fin", + "PromotionTitle":"Choisissez l'élément promotionnel", "TutoWelcomeTitle": "Activité Chess", "TutoWelcomeContent": "L'activité Chess vous permet d'apprendre ou défier vos amis au célèbre jeu d'échecs", "TutoBoardTitle": "Plateau de jeu", From 67d3b159047255121587251e8d9c958df1aed6fb Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:52:47 +0530 Subject: [PATCH 3/7] Localisation of text --- activities/Chess.activity/js/chessGame.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index f68e0d3fe8..77bda7aeba 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -20,7 +20,7 @@ var ChessGame = {
-

Choose Promotion Piece

+

{{ l10n.stringPromotionTitle }}

@@ -123,6 +123,7 @@ var ChessGame = { stringMatchDraw: '', stringVs: '', stringTimeExpired: '', + stringPromotionTitle: '', } } }, From 81813095fd4354a4c8768f634961bba00c5b998c Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Fri, 17 Jan 2025 10:29:51 +0530 Subject: [PATCH 4/7] Promotion Icon Updated --- activities/Chess.activity/js/chessGame.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 77bda7aeba..ca7054b0a2 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -22,11 +22,15 @@ var ChessGame = {

{{ l10n.stringPromotionTitle }}

-
-
-
-
-
+
+
Queen
+
Rook
+
Bishop
+
Knight
+
Queen
+
Rook
+
Bishop
+
Knight
From 875369ca1d00e84f51ae469b536057980cf150ed Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Wed, 22 Jan 2025 06:28:35 +0530 Subject: [PATCH 5/7] Indentation fixed --- activities/Chess.activity/js/chessGame.js | 48 +++++++++++------------ activities/Chess.activity/locales/fr.json | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index ca7054b0a2..52b48d00db 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -17,23 +17,23 @@ var ChessGame = {
-
-
-
-

{{ l10n.stringPromotionTitle }}

-
-
-
Queen
-
Rook
-
Bishop
-
Knight
-
Queen
-
Rook
-
Bishop
-
Knight
-
-
-
+
+
+
+

{{ l10n.stringPromotionTitle }}

+
+
+
Queen
+
Rook
+
Bishop
+
Knight
+
Queen
+
Rook
+
Bishop
+
Knight
+
+
+
@@ -114,12 +114,12 @@ var ChessGame = { opponentClockTime: 30, clockTotalTime: 30, showPromotionDialog: false, - pendingMove: { - source: null, - target: null, - piece: null, - turn: null, - }, + pendingMove: { + source: null, + target: null, + piece: null, + turn: null, + }, l10n: { stringYouWon: '', stringYouCheck: '', @@ -472,7 +472,7 @@ var ChessGame = { var turn = this.playercolor ? this.state.moveno % 2 != 0 : this.state.moveno % 2 == 0; if (!this.opponentuser || (this.opponentuser && turn)) { this.removeGreySquares(); - const piece = this.board.position()[source]; + const piece = this.board.position()[source]; const isWhitePawn = piece === 'wP'; const isBlackPawn = piece === 'bP'; const isLastRank = target[1] === '8'; diff --git a/activities/Chess.activity/locales/fr.json b/activities/Chess.activity/locales/fr.json index 1f050f1250..55f0cc1723 100644 --- a/activities/Chess.activity/locales/fr.json +++ b/activities/Chess.activity/locales/fr.json @@ -21,7 +21,7 @@ "PrevShort": "Préc", "NextShort": "Suiv", "EndShort": "Fin", - "PromotionTitle":"Choisissez l'élément promotionnel", + "PromotionTitle":"Choix de la promotion", "TutoWelcomeTitle": "Activité Chess", "TutoWelcomeContent": "L'activité Chess vous permet d'apprendre ou défier vos amis au célèbre jeu d'échecs", "TutoBoardTitle": "Plateau de jeu", From 80b3dc088aeaa8a903bc840af7c173add20e9ff7 Mon Sep 17 00:00:00 2001 From: Snehal Srivastava <118104081+SnehalSrivastava27@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:41:27 +0530 Subject: [PATCH 6/7] Indentation fixed --- activities/Chess.activity/js/chessGame.js | 59 +++++++++++------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 52b48d00db..ebd0311fdc 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -17,23 +17,23 @@ var ChessGame = {
-
-
-
-

{{ l10n.stringPromotionTitle }}

-
-
-
Queen
-
Rook
-
Bishop
-
Knight
-
Queen
-
Rook
-
Bishop
-
Knight
-
-
-
+
+
+
+

{{ l10n.stringPromotionTitle }}

+
+
+
Queen
+
Rook
+
Bishop
+
Knight
+
Queen
+
Rook
+
Bishop
+
Knight
+
+
+
@@ -83,8 +83,7 @@ var ChessGame = {
- ` - , + `, props: ['currentuser', 'opponentuser', 'presence', 'ishost', 'humane'], data: function() { return { @@ -472,22 +471,22 @@ var ChessGame = { var turn = this.playercolor ? this.state.moveno % 2 != 0 : this.state.moveno % 2 == 0; if (!this.opponentuser || (this.opponentuser && turn)) { this.removeGreySquares(); - const piece = this.board.position()[source]; - const isWhitePawn = piece === 'wP'; - const isBlackPawn = piece === 'bP'; - const isLastRank = target[1] === '8'; - const isFirstRank = target[1] === '1'; + const piece = this.board.position()[source]; + const isWhitePawn = piece === 'wP'; + const isBlackPawn = piece === 'bP'; + const isLastRank = target[1] === '8'; + const isFirstRank = target[1] === '1'; - if ((isWhitePawn && isLastRank) || (isBlackPawn && isFirstRank)) { + if ((isWhitePawn && isLastRank) || (isBlackPawn && isFirstRank)) { this.pendingMove = { - source: source, - target: target, - piece: piece, - turn: turn + source: source, + target: target, + piece: piece, + turn: turn }; this.showPromotionDialog = true; return; // Wait for promotion choice - } + } var move = this.state.move(source, target); // illegal move From f9a5f07b6a1e1df8500306c8651f2cabdbba275d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lionel=20Lask=C3=A9?= Date: Sat, 25 Jan 2025 21:49:13 +0100 Subject: [PATCH 7/7] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e0f98d38..8be5a54adc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - No Move Hint for "En passant" in Chess Activity #1707 - Info Update : Planet Activity #1709 - Minute numbers still visible in clock activity even after switching to Nice Clock #1713 +- Default Promotion to Queen in Chess Activity #1704 ## [1.8.0] - 2024-04-10 ### Added