Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chushogi: Fix bug with non-lion double movers capturing lion #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for shogiops

## v0.16.2

- Fixed `chushogi` bug where non-Lion double movers making a mid-step Lion capture was not preventing Lion counterstrike.

## v0.16.1

- Fixed `annanshogi` move generation.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shogiops",
"version": "0.16.1",
"version": "0.16.2",
"description": "Shogi rules and operations",
"keywords": [
"shogi",
Expand Down
10 changes: 8 additions & 2 deletions src/variant/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,19 @@ export abstract class Position {
piece.role = promote(this.rules)(role) || role;

const capture = this.board.set(md.to, piece),
secondCapture = defined(md.midStep) ? this.board.take(md.midStep) : undefined;
midCapture = defined(md.midStep) ? this.board.take(md.midStep) : undefined;

// process midCapture (if exists) before final destination capture
if (defined(midCapture)) {
if (!lionRoles.includes(role) && midCapture.color === this.turn && lionRoles.includes(midCapture.role))
this.lastLionCapture = md.midStep;
this.storeCapture(midCapture);
}
if (capture) {
if (!lionRoles.includes(role) && capture.color === this.turn && lionRoles.includes(capture.role))
this.lastLionCapture = md.to;
this.storeCapture(capture);
}
if (defined(secondCapture)) this.storeCapture(secondCapture);
}
}
}
Loading