alexobviously / bishop

A chess logic package for Dart with flexible variant support
https://pub.dev/packages/bishop
Other
19 stars 8 forks source link

Castling in chess960 when King is on g1 #6

Closed malaschitz closed 1 year ago

malaschitz commented 1 year ago

When the king is on square g1, the move for castling (g1h1) is not generated.

import 'package:bishop/bishop.dart' as bishop;

void main() {
  String pos = 'BBQNRNKR';
  String fen = '${pos.toLowerCase()}/pppppppp/8/8/8/8/PPPPPPPP/$pos w';
  print(fen);

  bishop.Game game = bishop.Game(variant: bishop.Variant.chess960(), fen: fen);
  game.makeMoveString('f1g3');
  game.makeMoveString('f8g6');
  print(game.ascii());
  print(game.fen);
  var moves = game.generateLegalMoves();
  moves.forEach((m) {
    print(m.algebraic());
  });
}

Output

bbqnrnkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNRNKR w
   +------------------------+
 8 | b  b  q  n  r  .  k  r |
 7 | p  p  p  p  p  p  p  p |
 6 | .  .  .  .  .  .  n  . |
 5 | .  .  .  .  .  .  .  . |
 4 | .  .  .  .  .  .  .  . |
 3 | .  .  .  .  .  .  N  . |
 2 | P  P  P  P  P  P  P  P |
 1 | B  B  Q  N  R  .  K  R |
   +------------------------+
     a  b  c  d  e  f  g  h  
bbqnr1kr/pppppppp/6n1/8/8/6N1/PPPPPPPP/BBQNR1KR w HEhe - 2 2
g3e4
g3f5
g3h5
g3f1
a2a3
a2a4
b2b3
b2b4
c2c3
c2c4
d2d3
d2d4
e2e3
e2e4
f2f3
f2f4
h2h3
h2h4
d1c3
d1e3
e1f1
g1f1
malaschitz commented 1 year ago

I create pull request. Bug is on line 560:

https://github.com/alexobviously/bishop/pull/7/commits/275a50c3c45d7b239afb8d1db08455e04872d3b0

alexobviously commented 1 year ago

Thanks again! Also included in 0.6.1