Commit 7e60bf27 authored by Johnny Jazeix's avatar Johnny Jazeix

chess, add en passant move

parent 59f9857d
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment