From 7e60bf27cc025c820137d78c3edd1f8b93232836 Mon Sep 17 00:00:00 2001 From: Johnny Jazeix Date: Sat, 20 Jun 2020 20:36:36 +0200 Subject: [PATCH] chess, add en passant move --- src/activities/chess/Chess.qml | 16 ++++++++++++++++ src/activities/chess/chess.js | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/activities/chess/Chess.qml b/src/activities/chess/Chess.qml index e999a42a4..b80905006 100644 --- a/src/activities/chess/Chess.qml +++ b/src/activities/chess/Chess.qml @@ -507,6 +507,22 @@ ActivityBase { movesCount ++ var fromPiece = getPieceAt(from) var toPiece = getPieceAt(to) + + // Specific case for en passant move. It is a case where + // we capture without having the pawn to the "to" position. + // To know if we captured, we browse the whole board to look + // for missing pawn + var state = Activity.simplifiedState(Activity.state.board) + for(var i=0; i < state.length; ++i) { + var pos = state[i].pos + var pawnPiece = getPieceAt(pos) + if(pos != from && state[i].img === "" && + pawnPiece.img !== '') { + toPiece = pawnPiece + break + } + } + if(toPiece.img !== '') { items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/smudge.wav') if(toPiece.isWhite) { diff --git a/src/activities/chess/chess.js b/src/activities/chess/chess.js index 85b16dba0..6117d5e4a 100644 --- a/src/activities/chess/chess.js +++ b/src/activities/chess/chess.js @@ -57,7 +57,7 @@ function initLevel() { } function nextLevel() { - if(numberOfLevel <= ++currentLevel ) { + if(numberOfLevel <= ++currentLevel) { currentLevel = 0 } initLevel(); @@ -295,7 +295,7 @@ function randomMove() { return } // Get all possible moves - var moves = Engine.p4_parse(state, state.to_play, 0, 0) + var moves = Engine.p4_parse(state, state.to_play, state.enpassant, 0) moves = Core.shuffle(moves) var move = state.move(moves[0][1], moves[0][2]) if(move.ok) { @@ -315,7 +315,7 @@ function clearAcceptMove() { // Highlight the possible moves for the piece at position 'from' function showPossibleMoves(from) { - var result = Engine.p4_parse(state, state.to_play, 0, 0) + var result = Engine.p4_parse(state, state.to_play, state.enpassant, 0) clearAcceptMove() var fromEngine = viewPosToEngine(from) for(var i=0; i < result.length; ++i) { -- GitLab