Skip to content

Impasse Rule + History. - #3

Merged
WandererXII merged 20 commits into
WandererXII:mainfrom
deniskhodyrev1990:workbranch
May 18, 2026
Merged

WandererXII merged 20 commits into
WandererXII:mainfrom
deniskhodyrev1990:workbranch

Conversation

@deniskhodyrev1990

Copy link
Copy Markdown
Contributor

Implemented the Impasse Rule from Issue #1 and History from issue #2. All tests pass.

Comment thread lib/src/position/position.dart Outdated
}

if (isImpasse(this)){
return Outcome(result: GameResult.tryRule, winner: turn);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need a new GameResult 'Impasse27'. 'TryRule' is for dobutsu only.

Comment thread lib/src/history.dart
return copyWith(initialSfen: sfen);
}

History copyWith({

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fields that are nullable will need 'uniqueObjectInstance,' like it's here for example:

Object? lastDest = uniqueObjectInstance,

Comment thread lib/src/history.dart
return ConsecutiveAttacks(sente, 0);
}

int call(Side side) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better name like 'side' to be consistent (

Hand side(Side side) => side == Side.sente ? sente : gote;
)

Comment thread lib/src/impasse.dart Outdated
const int necessaryGoteScore = 27;

bool isImpasse(Position position) {
if ((position.rule != Rule.shogi && position.rule != Rule.annanshogi && position.rule != Rule.checkshogi) || position.isCheck()) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More readable would be having the impassable variants elsewhere:

final impassableRules = {
Rule.shogi,
Rule.annanshogi,
Rule.checkshogi,
};

And then
impassableRules.contains(position.rule)

Comment thread lib/src/sfen.dart Outdated
final board = parseBoardSfen(rule, boardPart);
if (board.isError()) return Failure(board.exceptionOrNull()!);

//History

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scalashogi we only look for last lion dest - https://github.com/WandererXII/scalashogi/blob/9a1c2c3ae9167da60f47366e922b2f84c8bcda4e/src/main/scala/format/forsyth/Sfen.scala#L39

We are not necessarily parsing the initial position.

Comment thread lib/src/core/setup.dart
required this.turn,
required this.history,
this.lastDest,
this.lastLionCapture,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.lastDest and this.lastLionCapture are now essentially covered by History right? So we should probably remove these. Same in position.

@WandererXII

Copy link
Copy Markdown
Owner

Also could you please add '@useResult' to methods in History.dart returning History?

@WandererXII
WandererXII merged commit d07f1b9 into WandererXII:main May 18, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants