Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Education
GCompris
Commits
7e60bf27
Commit
7e60bf27
authored
Jun 20, 2020
by
Johnny Jazeix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chess, add en passant move
parent
59f9857d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
src/activities/chess/Chess.qml
src/activities/chess/Chess.qml
+16
-0
src/activities/chess/chess.js
src/activities/chess/chess.js
+3
-3
No files found.
src/activities/chess/Chess.qml
View file @
7e60bf27
...
@@ -507,6 +507,22 @@ ActivityBase {
...
@@ -507,6 +507,22 @@ ActivityBase {
movesCount
++
movesCount
++
var
fromPiece
=
getPieceAt
(
from
)
var
fromPiece
=
getPieceAt
(
from
)
var
toPiece
=
getPieceAt
(
to
)
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
!==
''
)
{
if
(
toPiece
.
img
!==
''
)
{
items
.
audioEffects
.
play
(
'
qrc:/gcompris/src/core/resource/sounds/smudge.wav
'
)
items
.
audioEffects
.
play
(
'
qrc:/gcompris/src/core/resource/sounds/smudge.wav
'
)
if
(
toPiece
.
isWhite
)
{
if
(
toPiece
.
isWhite
)
{
...
...
src/activities/chess/chess.js
View file @
7e60bf27
...
@@ -57,7 +57,7 @@ function initLevel() {
...
@@ -57,7 +57,7 @@ function initLevel() {
}
}
function
nextLevel
()
{
function
nextLevel
()
{
if
(
numberOfLevel
<=
++
currentLevel
)
{
if
(
numberOfLevel
<=
++
currentLevel
)
{
currentLevel
=
0
currentLevel
=
0
}
}
initLevel
();
initLevel
();
...
@@ -295,7 +295,7 @@ function randomMove() {
...
@@ -295,7 +295,7 @@ function randomMove() {
return
return
}
}
// Get all possible moves
// 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
)
moves
=
Core
.
shuffle
(
moves
)
var
move
=
state
.
move
(
moves
[
0
][
1
],
moves
[
0
][
2
])
var
move
=
state
.
move
(
moves
[
0
][
1
],
moves
[
0
][
2
])
if
(
move
.
ok
)
{
if
(
move
.
ok
)
{
...
@@ -315,7 +315,7 @@ function clearAcceptMove() {
...
@@ -315,7 +315,7 @@ function clearAcceptMove() {
// Highlight the possible moves for the piece at position 'from'
// Highlight the possible moves for the piece at position 'from'
function
showPossibleMoves
(
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
()
clearAcceptMove
()
var
fromEngine
=
viewPosToEngine
(
from
)
var
fromEngine
=
viewPosToEngine
(
from
)
for
(
var
i
=
0
;
i
<
result
.
length
;
++
i
)
{
for
(
var
i
=
0
;
i
<
result
.
length
;
++
i
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment