Since no firstrank constant has been stored for this game, one will be calculated by analyzing the moves in the game. This will work only if the game lasted long enough to put enough pieces into play.

mv is b2-b3, p is #p, o is b2

space b2 is P

0 P b2-b3 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

mv is d7-d6, p is #p, o is d7

space d7 is p

1 p d7-d6 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

mv is c2-c4, p is #p, o is c2

space c2 is P

2 P c2-c4 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

mv is e7-e5, p is #p, o is e7

space e7 is p

3 p e7-e5 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

mv is d1-c2, p is #p, o is d1

space d1 is d1

4 d1 d1-c2 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

5 one bits in var d1

11011 111101 111011 110100 111011 111101 111011 11101

q end d1-c2 27 61 59 52 59 61 59 29

bb end d1-c2 27 61 59 52 59 61 59 29

bw end d1-c2 27 61 59 52 59 61 59 29

firstr is a1, and lastr is h1

r d1-c2 27 61 59 52 59 61 59 29

first 27 61 59 52 59 61 59 29

mv is b8-d7, p is #p, o is b8

space b8 is b1

5 b1 b8-d7 27 61 59 52 59 61 59 29

11011 111101 111011 110100 111011 111101 111011 11101

5 one bits in var b1

11011 1 111011 110100 111011 111101 111011 11101

q end b8-d7 27 1 59 52 59 61 59 29

bb end b8-d7 27 1 59 52 59 61 59 29

bw end b8-d7 27 1 59 52 59 61 59 29

firstr is a1, and lastr is h1

r b8-d7 27 1 59 52 59 61 59 29

first 27 1 59 52 59 61 59 29

mv is f1-e3, p is #p, o is f1

space f1 is f1

6 f1 f1-e3 27 1 59 52 59 61 59 29

11011 1 111011 110100 111011 111101 111011 11101

5 one bits in var f1

11011 1 111011 110100 111011 1 111011 11101

q end f1-e3 27 1 59 52 59 1 59 29

bb end f1-e3 27 1 59 52 59 1 59 29

bw end f1-e3 27 1 59 52 59 1 59 29

firstr is a1, and lastr is h1

r f1-e3 27 1 59 52 59 1 59 29

first 27 1 59 52 59 1 59 29

11010 1 111010 110100 111010 1 111010 11100

q end f1-e3 26 1 58 52 58 1 58 28

bb end f1-e3 26 1 58 52 58 1 58 28

bw end f1-e3 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r f1-e3 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is f8-g6, p is #p, o is f8

space f8 is f1

7 f1 f8-g6 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 110100 111010 1 111010 11100

q end f8-g6 26 1 58 52 58 1 58 28

bb end f8-g6 26 1 58 52 58 1 58 28

bw end f8-g6 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r f8-g6 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is b1-c3, p is #p, o is b1

space b1 is b1

8 b1 b1-c3 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

1 one bits in var b1

11010 1 111010 110100 111010 1 111010 11100

q end b1-c3 26 1 58 52 58 1 58 28

bb end b1-c3 26 1 58 52 58 1 58 28

bw end b1-c3 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r b1-c3 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is b7-b6, p is #p, o is b7

space b7 is p

9 p b7-b6 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

mv is c3-d5, p is #p, o is c3

space c3 is b1

10 b1 c3-d5 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

1 one bits in var b1

11010 1 111010 110100 111010 1 111010 11100

q end c3-d5 26 1 58 52 58 1 58 28

bb end c3-d5 26 1 58 52 58 1 58 28

bw end c3-d5 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r c3-d5 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is d7-f6, p is #p, o is d7

space d7 is b1

11 b1 d7-f6 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

1 one bits in var b1

11010 1 111010 110100 111010 1 111010 11100

q end d7-f6 26 1 58 52 58 1 58 28

bb end d7-f6 26 1 58 52 58 1 58 28

bw end d7-f6 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r d7-f6 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is d5-f6, p is #p, o is d5

space d5 is b1

12 b1 d5-f6 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

1 one bits in var b1

11010 1 111010 110100 111010 1 111010 11100

q end d5-f6 26 1 58 52 58 1 58 28

bb end d5-f6 26 1 58 52 58 1 58 28

bw end d5-f6 26 1 58 52 58 1 58 28

firstr is a1, and lastr is h1

r d5-f6 26 1 58 52 58 1 58 28

first 26 1 58 52 58 1 58 28

mv is d8-f6, p is #p, o is d8

space d8 is d1

13 d1 d8-f6 26 1 58 52 58 1 58 28

11010 1 111010 110100 111010 1 111010 11100

3 one bits in var d1

11010 1 111010 10100 111010 1 111010 11100

q end d8-f6 26 1 58 20 58 1 58 28

bb end d8-f6 26 1 58 20 58 1 58 28

bw end d8-f6 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r d8-f6 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is e3-d5, p is #p, o is e3

space e3 is f1

14 f1 e3-d5 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 10100 111010 1 111010 11100

q end e3-d5 26 1 58 20 58 1 58 28

bb end e3-d5 26 1 58 20 58 1 58 28

bw end e3-d5 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r e3-d5 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is f6-g5, p is #p, o is f6

space f6 is d1

15 d1 f6-g5 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

2 one bits in var d1

11010 1 111010 10100 111010 1 111010 11100

q end f6-g5 26 1 58 20 58 1 58 28

bb end f6-g5 26 1 58 20 58 1 58 28

bw end f6-g5 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r f6-g5 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is h1-f1, p is #p, o is h1

space h1 is h1

16 h1 h1-f1 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

3 one bits in var h1

rook hopping king to castle

11010 1 111010 10100 111010 1 111010 11100

q end h1-f1 26 1 58 20 58 1 58 28

bb end h1-f1 26 1 58 20 58 1 58 28

bw end h1-f1 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r h1-f1 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is c7-c6, p is #p, o is c7

space c7 is p

17 p c7-c6 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

mv is d5-b4, p is #p, o is d5

space d5 is f1

18 f1 d5-b4 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 10100 111010 1 111010 11100

q end d5-b4 26 1 58 20 58 1 58 28

bb end d5-b4 26 1 58 20 58 1 58 28

bw end d5-b4 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r d5-b4 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is c6-c5, p is #p, o is c6

space c6 is p

19 p c6-c5 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

mv is b4-d5, p is #p, o is b4

space b4 is f1

20 f1 b4-d5 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 10100 111010 1 111010 11100

q end b4-d5 26 1 58 20 58 1 58 28

bb end b4-d5 26 1 58 20 58 1 58 28

bw end b4-d5 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r b4-d5 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is g6-e7, p is #p, o is g6

space g6 is f1

21 f1 g6-e7 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 10100 111010 1 111010 11100

q end g6-e7 26 1 58 20 58 1 58 28

bb end g6-e7 26 1 58 20 58 1 58 28

bw end g6-e7 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r g6-e7 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is d5-e7, p is #p, o is d5

space d5 is f1

22 f1 d5-e7 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

1 one bits in var f1

11010 1 111010 10100 111010 1 111010 11100

q end d5-e7 26 1 58 20 58 1 58 28

bb end d5-e7 26 1 58 20 58 1 58 28

bw end d5-e7 26 1 58 20 58 1 58 28

firstr is a1, and lastr is h1

r d5-e7 26 1 58 20 58 1 58 28

first 26 1 58 20 58 1 58 28

mv is e8-e7, p is #p, o is e8

space e8 is e1

23 e1 e8-e7 26 1 58 20 58 1 58 28

11010 1 111010 10100 111010 1 111010 11100

4 one bits in var e1

11010 1 111010 10100 111000 1 111010 11100

q end e8-e7 26 1 58 20 56 1 58 28

bb end e8-e7 26 1 58 20 56 1 58 28

bw end e8-e7 26 1 58 20 56 1 58 28

firstr is a1, and lastr is h1

r e8-e7 26 1 58 20 56 1 58 28

first 26 1 58 20 56 1 58 28

mv is c2-f5, p is #p, o is c2

space c2 is d1

24 d1 c2-f5 26 1 58 20 56 1 58 28

11010 1 111010 10100 111000 1 111010 11100

2 one bits in var d1

11010 1 111010 10100 111000 1 111010 11100

q end c2-f5 26 1 58 20 56 1 58 28

bb end c2-f5 26 1 58 20 56 1 58 28

bw end c2-f5 26 1 58 20 56 1 58 28

firstr is a1, and lastr is h1

r c2-f5 26 1 58 20 56 1 58 28

first 26 1 58 20 56 1 58 28

mv is c8-e8, p is #p, o is c8

space c8 is c1

25 c1 c8-e8 26 1 58 20 56 1 58 28

11010 1 111010 10100 111000 1 111010 11100

4 one bits in var c1

rook ride

Rook or Queen move

11010 1 11000 10100 111000 1 111010 11100

q end c8-e8 26 1 24 20 56 1 58 28

bb end c8-e8 26 1 24 20 56 1 58 28

bw end c8-e8 26 1 24 20 56 1 58 28

firstr is a1, and lastr is h1

r c8-e8 26 1 24 20 56 1 58 28

first 26 1 24 20 56 1 58 28

mv is c1-d1, p is #p, o is c1

space c1 is c1

26 c1 c1-d1 26 1 24 20 56 1 58 28

11010 1 11000 10100 111000 1 111010 11100

2 one bits in var c1

11010 1 11000 10100 111000 1 111010 11100

q end c1-d1 26 1 24 20 56 1 58 28

bb end c1-d1 26 1 24 20 56 1 58 28

bw end c1-d1 26 1 24 20 56 1 58 28

firstr is a1, and lastr is h1

r c1-d1 26 1 24 20 56 1 58 28

first 26 1 24 20 56 1 58 28

mv is e7-f6, p is #p, o is e7

space e7 is e1

27 e1 e7-f6 26 1 24 20 56 1 58 28

11010 1 11000 10100 111000 1 111010 11100

3 one bits in var e1

11010 1 11000 10100 110000 1 111010 11100

q end e7-f6 26 1 24 20 48 1 58 28

bb end e7-f6 26 1 24 20 48 1 58 28

bw end e7-f6 26 1 24 20 48 1 58 28

firstr is a1, and lastr is h1

r e7-f6 26 1 24 20 48 1 58 28

first 26 1 24 20 48 1 58 28

mv is e2-e4, p is #p, o is e2

space e2 is P

28 P e2-e4 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

mv is g7-g6, p is #p, o is g7

space g7 is p

29 p g7-g6 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

mv is f5-g4, p is #p, o is f5

space f5 is d1

30 d1 f5-g4 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

2 one bits in var d1

11010 1 11000 10100 110000 1 111010 11100

q end f5-g4 26 1 24 20 48 1 58 28

bb end f5-g4 26 1 24 20 48 1 58 28

bw end f5-g4 26 1 24 20 48 1 58 28

firstr is a1, and lastr is h1

r f5-g4 26 1 24 20 48 1 58 28

first 26 1 24 20 48 1 58 28

mv is h7-h5, p is #p, o is h7

space h7 is p

31 p h7-h5 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

mv is g4-h3, p is #p, o is g4

space g4 is d1

32 d1 g4-h3 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

2 one bits in var d1

11010 1 11000 10100 110000 1 111010 11100

q end g4-h3 26 1 24 20 48 1 58 28

bb end g4-h3 26 1 24 20 48 1 58 28

bw end g4-h3 26 1 24 20 48 1 58 28

firstr is a1, and lastr is h1

r g4-h3 26 1 24 20 48 1 58 28

first 26 1 24 20 48 1 58 28

mv is a8-b7, p is #p, o is a8

space a8 is a1

33 a1 a8-b7 26 1 24 20 48 1 58 28

11010 1 11000 10100 110000 1 111010 11100

3 one bits in var a1

10010 1 11000 10100 110000 1 111010 11100

q end a8-b7 18 1 24 20 48 1 58 28

bb end a8-b7 18 1 24 20 48 1 58 28

bw end a8-b7 18 1 24 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r a8-b7 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is a2-a4, p is #p, o is a2

space a2 is P

34 P a2-a4 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is b7-c8, p is #p, o is b7

space b7 is a1

35 a1 b7-c8 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var a1

10010 1 1000 10100 110000 1 111010 11100

q end b7-c8 18 1 8 20 48 1 58 28

bb end b7-c8 18 1 8 20 48 1 58 28

bw end b7-c8 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r b7-c8 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is h3-c8, p is #p, o is h3

space h3 is d1

36 d1 h3-c8 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var d1

10010 1 1000 10100 110000 1 111010 11100

q end h3-c8 18 1 8 20 48 1 58 28

bb end h3-c8 18 1 8 20 48 1 58 28

bw end h3-c8 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r h3-c8 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is e8-c8, p is #p, o is e8

space e8 is c1

37 c1 e8-c8 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

1 one bits in var c1

10010 1 1000 10100 110000 1 111010 11100

q end e8-c8 18 1 8 20 48 1 58 28

bb end e8-c8 18 1 8 20 48 1 58 28

bw end e8-c8 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r e8-c8 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is d2-d3, p is #p, o is d2

space d2 is P

38 P d2-d3 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is g5-f4, p is #p, o is g5

space g5 is d1

39 d1 g5-f4 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var d1

10010 1 1000 10100 110000 1 111010 11100

q end g5-f4 18 1 8 20 48 1 58 28

bb end g5-f4 18 1 8 20 48 1 58 28

bw end g5-f4 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r g5-f4 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is f2-f3, p is #p, o is f2

space f2 is P

40 P f2-f3 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is f6-g5, p is #p, o is f6

space f6 is e1

41 e1 f6-g5 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var e1

10010 1 1000 10100 110000 1 111010 11100

q end f6-g5 18 1 8 20 48 1 58 28

bb end f6-g5 18 1 8 20 48 1 58 28

bw end f6-g5 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r f6-g5 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is a1-c3, p is #p, o is a1

space a1 is a1

42 a1 a1-c3 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var a1

10010 1 1000 10100 110000 1 111010 11100

q end a1-c3 18 1 8 20 48 1 58 28

bb end a1-c3 18 1 8 20 48 1 58 28

bw end a1-c3 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r a1-c3 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is h5-h4, p is #p, o is h5

space h5 is p

43 p h5-h4 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is h2-h3, p is #p, o is h2

space h2 is P

44 P h2-h3 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is f7-f5, p is #p, o is f7

space f7 is p

45 p f7-f5 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

mv is c3-d2, p is #p, o is c3

space c3 is a1

46 a1 c3-d2 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

2 one bits in var a1

10010 1 1000 10100 110000 1 111010 11100

q end c3-d2 18 1 8 20 48 1 58 28

bb end c3-d2 18 1 8 20 48 1 58 28

bw end c3-d2 18 1 8 20 48 1 58 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r c3-d2 18 1 8 20 48 1 58 28

first 18 1 8 20 48 1 58 28

mv is g8-g7, p is #p, o is g8

space g8 is g1

47 g1 g8-g7 18 1 8 20 48 1 58 28

10010 1 1000 10100 110000 1 111010 11100

4 one bits in var g1

10010 1 1000 10100 110000 1 111000 11100

q end g8-g7 18 1 8 20 48 1 56 28

bb end g8-g7 2 1 8 20 48 1 56 28

bw end g8-g7 2 1 8 20 48 1 56 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r g8-g7 2 1 8 20 48 1 56 28

first 2 1 8 20 48 1 56 28

10 1 1000 10100 110000 1 111000 11100

q end g8-g7 2 1 8 20 48 1 56 28

bb end g8-g7 2 1 8 20 48 1 56 28

bw end g8-g7 2 1 8 20 48 1 56 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r g8-g7 2 1 8 20 48 1 56 28

first 2 1 8 20 48 1 56 28

mv is d2-f4, p is #p, o is d2

space d2 is a1

48 a1 d2-f4 2 1 8 20 48 1 56 28

10 1 1000 10100 110000 1 111000 11100

1 one bits in var a1

10 1 1000 10100 110000 1 111000 11100

q end d2-f4 2 1 8 20 48 1 56 28

bb end d2-f4 2 1 8 20 48 1 56 28

bw end d2-f4 2 1 8 20 48 1 56 28

firstr is c1, and lastr is h1

One Rook found

d1 20

e1 48

r d2-f4 2 1 8 20 48 1 56 28

first 2 1 8 20 48 1 56 28

mv is e5-f4, p is #p, o is e5

space e5 is p

49 p e5-f4 2 1 8 20 48 1 56 28

10 1 1000 10100 110000 1 111000 11100

mv is f1-f2, p is #p, o is f1

space f1 is h1

50 h1 f1-f2 2 1 8 20 48 1 56 28

10 1 1000 10100 110000 1 111000 11100

3 one bits in var h1

10 1 1000 10100 110000 1 111000 11000

q end f1-f2 2 1 8 20 48 1 56 24

bb end f1-f2 2 1 8 20 48 1 56 24

bw end f1-f2 2 1 8 4 48 1 56 24

firstr is c1, and lastr is h1

One Rook found

d1 4

e1 48

r f1-f2 2 1 8 4 48 1 56 24

first 2 1 8 4 48 1 56 24

10 1 1000 100 110000 1 111000 11000

q end f1-f2 2 1 8 4 48 1 56 24

bb end f1-f2 2 1 8 4 48 1 56 24

bw end f1-f2 2 1 8 4 48 1 56 24

firstr is c1, and lastr is h1

One Rook found

d1 4

e1 48

r f1-f2 2 1 8 4 48 1 56 24

first 2 1 8 4 48 1 56 24

mv is c8-e8, p is #p, o is c8

space c8 is c1

51 c1 c8-e8 2 1 8 4 48 1 56 24

10 1 1000 100 110000 1 111000 11000

1 one bits in var c1

10 1 1000 100 110000 1 111000 11000

q end c8-e8 2 1 8 4 48 1 56 24

bb end c8-e8 2 1 8 4 48 1 56 24

bw end c8-e8 2 1 8 4 48 1 56 24

firstr is c1, and lastr is h1

One Rook found

d1 4

e1 48

r c8-e8 2 1 8 4 48 1 56 24

first 2 1 8 4 48 1 56 24

Continue because mv is empty

This game may have been too short to properly calculate the original position, and the calculated pattern of BNRB?N?? is inconsistent with randomly generated value of NRBQKBNR. If you think this game does have enough data to calculate the original position, please report it to Fergus Duniho.

Use your browser's BACK button to go back to the previous page, then reload if necessary.

For general reference, here is the complete list of moves:

1. b2-b3 
1... d7 - d6 
2. c2-c4 
2... e7 - e5 
3. d1-c2 
3... b8 - d7 
4. f1-e3 
4... f8 - g6 
5. b1-c3 
5... b7 - b6 
6. c3-d5 
6... d7 - f6 
7. d5-f6 
7... d8 - f6 
8. e3-d5 
8... f6 - g5 
9. h1-f1 
9... c7 - c6 
10. d5-b4 
10... c6 - c5 
11. b4-d5 
11... g6 - e7 
12. d5-e7 
12... e8 - e7 
13. c2-f5 
13... c8 - e8 
14. c1-d1 
14... e7 - f6 
15. e2-e4 
15... g7 - g6 
16. f5-g4 
16... h7 - h5 
17. g4-h3 
17... a8 - b7 
18. a2-a4 
18... b7 - c8 
19. h3-c8 
19... e8 - c8 
20. d2-d3 
20... g5 - f4 
21. f2-f3 
21... f6 - g5 
22. a1-c3 
22... h5 - h4 
23. h2-h3 
23... f7 - f5 
24. c3-d2 
24... g8 - g7 
25. d2-f4 
25... e5 - f4 
26. f1-f2 
26... c8 - e8

If this is your settings file, you may edit it at https://www.chessvariants.com/play/pbm/play.php?game=Fischer+Random+Chess&settings=Abstract&submit=Edit

Here is a code listing:

   0 empty a1 b1 c1 d1 e1 f1 g1 h1 a8 b8 c8 d8 e8 f8 h8
   1 include fischer
   2 if isconst firstrank
   3   for i range 0 7
   4     set c join chr + 97 var i 1
   5     set p substr const firstrank var i 1
   6     add #p #c
   7   next
   8 elseif == status "Ongoing"
   9   drop B any a1 c1 e1 g1
  10   drop B any b1 d1 f1 h1
  11   drop Q any a1 b1 c1 d1 e1 f1 g1 h1
  12   drop N any a1 b1 c1 d1 e1 f1 g1 h1
  13   drop N any a1 b1 c1 d1 e1 f1 g1 h1
  14   drop R first a1 b1 c1 d1 e1 f1
  15   drop K first b1 c1 d1 e1 f1 g1
  16   drop R last c1 d1 e1 f1 g1 h1
  17   set fr null
  18   for i range a h
  19     set fr join var fr space join var i 1
  20   next
  21   setconst firstrank var fr
  22 else
  23   echo "Since no firstrank constant has been stored for this game, one will be calculated by analyzing the moves in the game. This will work only if the game lasted long enough to put enough pieces into play."
  24   gosub calc_original_position
  25 endif
  26 copy a1 a8
  27 copy b1 b8
  28 copy c1 c8
  29 copy d1 d8
  30 copy e1 e8
  31 copy f1 f8
  32 copy g1 g8
  33 copy h1 h8
  34 flip a8 b8 c8 d8 e8 f8 g8 h8
  35 set AR findpiece R first a1 b1 c1 d1 e1 f1
  36 set HR findpiece R first h1 g1 f1 e1 d1 c1
  37 set K findpiece K first b1 c1 d1 e1 f1 g1
  38 set ar findpiece r first a8 b8 c8 d8 e8 f8
  39 set hr findpiece r first h8 g8 f8 e8 d8 c8
  40 set k findpiece k first b8 c8 d8 e8 f8 g8
  41 setflag #AR #HR #K #ar #hr #k
  42 set k findpiece k spaces
  43 set K findpiece K spaces
  44 set ep false
  45 set koo g8
  46 set roo f8
  47 set kooo c8
  48 set rooo d8
  49 set KOO g1
  50 set ROO f1
  51 set KOOO c1
  52 set ROOO d1
  53 setsystem "dest" null
  54 sub postauto1
  55   if not equal moved P
  56     set ep false
  57     if unequal space dest moved
  58       die You may not change the type of this piece.
  59     endif
  60   endif
  61   set legal false
  62   if match moved P K R
  63     gosub moved origin dest
  64     if equal moved K
  65       set K dest
  66     endif
  67   elseif match moved Q B N
  68     set legal fn moved origin dest
  69   endif
  70   if not var legal
  71     die You may not move a moved from origin to dest
  72   endif
  73   if isupper $old and != $old K and != $moved R
  74     die You may not capture your own pieces.
  75   endif
  76   if fn ATTACKEDBYB #K
  77     die You may not move into check.
  78   endif
  79 endsub
  80 sub postauto2
  81   if not equal moved p
  82     set ep false
  83     if unequal space dest moved
  84       die You may not change the type of this piece.
  85     endif
  86   endif
  87   set legal false
  88   if match moved p k r
  89     gosub moved origin dest
  90     if equal moved k
  91       set k dest
  92     endif
  93   elseif match moved q b n
  94     set legal fn toupper moved origin dest
  95   endif
  96   if not var legal
  97     die You may not move a moved from origin to dest
  98   endif
  99   if islower old and != $old k and != $moved r
 100     die You may not capture your own pieces.
 101   endif
 102   if fn ATTACKEDBYW #k
 103     die You may not move into check.
 104   endif
 105 endsub
 106 moveindex 0
 107 MOVE: b2-b3
 108 postauto1
 109 moveindex 1
 110 MOVE: d7 - d6
 111 postauto2
 112 moveindex 2
 113 MOVE: c2-c4
 114 postauto1
 115 moveindex 3
 116 MOVE: e7 - e5
 117 postauto2
 118 moveindex 4
 119 MOVE: d1-c2
 120 postauto1
 121 moveindex 5
 122 MOVE: b8 - d7
 123 postauto2
 124 moveindex 6
 125 MOVE: f1-e3
 126 postauto1
 127 moveindex 7
 128 MOVE: f8 - g6
 129 postauto2
 130 moveindex 8
 131 MOVE: b1-c3
 132 postauto1
 133 moveindex 9
 134 MOVE: b7 - b6
 135 postauto2
 136 moveindex 10
 137 MOVE: c3-d5
 138 postauto1
 139 moveindex 11
 140 MOVE: d7 - f6
 141 postauto2
 142 moveindex 12
 143 MOVE: d5-f6
 144 postauto1
 145 moveindex 13
 146 MOVE: d8 - f6
 147 postauto2
 148 moveindex 14
 149 MOVE: e3-d5
 150 postauto1
 151 moveindex 15
 152 MOVE: f6 - g5
 153 postauto2
 154 moveindex 16
 155 MOVE: h1-f1
 156 postauto1
 157 moveindex 17
 158 MOVE: c7 - c6
 159 postauto2
 160 moveindex 18
 161 MOVE: d5-b4
 162 postauto1
 163 moveindex 19
 164 MOVE: c6 - c5
 165 postauto2
 166 moveindex 20
 167 MOVE: b4-d5
 168 postauto1
 169 moveindex 21
 170 MOVE: g6 - e7
 171 postauto2
 172 moveindex 22
 173 MOVE: d5-e7
 174 postauto1
 175 moveindex 23
 176 MOVE: e8 - e7
 177 postauto2
 178 moveindex 24
 179 MOVE: c2-f5
 180 postauto1
 181 moveindex 25
 182 MOVE: c8 - e8
 183 postauto2
 184 moveindex 26
 185 MOVE: c1-d1
 186 postauto1
 187 moveindex 27
 188 MOVE: e7 - f6
 189 postauto2
 190 moveindex 28
 191 MOVE: e2-e4
 192 postauto1
 193 moveindex 29
 194 MOVE: g7 - g6
 195 postauto2
 196 moveindex 30
 197 MOVE: f5-g4
 198 postauto1
 199 moveindex 31
 200 MOVE: h7 - h5
 201 postauto2
 202 moveindex 32
 203 MOVE: g4-h3
 204 postauto1
 205 moveindex 33
 206 MOVE: a8 - b7
 207 postauto2
 208 moveindex 34
 209 MOVE: a2-a4
 210 postauto1
 211 moveindex 35
 212 MOVE: b7 - c8
 213 postauto2
 214 moveindex 36
 215 MOVE: h3-c8
 216 postauto1
 217 moveindex 37
 218 MOVE: e8 - c8
 219 postauto2
 220 moveindex 38
 221 MOVE: d2-d3
 222 postauto1
 223 moveindex 39
 224 MOVE: g5 - f4
 225 postauto2
 226 moveindex 40
 227 MOVE: f2-f3
 228 postauto1
 229 moveindex 41
 230 MOVE: f6 - g5
 231 postauto2
 232 moveindex 42
 233 MOVE: a1-c3
 234 postauto1
 235 moveindex 43
 236 MOVE: h5 - h4
 237 postauto2
 238 moveindex 44
 239 MOVE: h2-h3
 240 postauto1
 241 moveindex 45
 242 MOVE: f7 - f5
 243 postauto2
 244 moveindex 46
 245 MOVE: c3-d2
 246 postauto1
 247 moveindex 47
 248 MOVE: g8 - g7
 249 postauto2
 250 moveindex 48
 251 MOVE: d2-f4
 252 postauto1
 253 moveindex 49
 254 MOVE: e5 - f4
 255 postauto2
 256 moveindex 50
 257 MOVE: f1-f2
 258 postauto1
 259 moveindex 51
 260 MOVE: c8 - e8
 261 postauto2
 262 set checks sub checks #K
 263 if var checks
 264   if sub checkmated #K #checks
 265     say Checkmate! Black has won!
 266     won
 267   else
 268     say Check!
 269   endif
 270 elseif sub stalemated #K
 271   say Stalemate! The game is drawn.
 272   drawn
 273 endif
 274 end
 275 
 276 lib fischer
 277 include chess
 278 set wprom (Q R B N)
 279 set bprom (q r b n)
 280 sub K from to
 281   set legal fn K #from #to
 282   if not var legal or == old R
 283     if == #to #KOOO
 284       castle #K #KOOO #AR #ROOO
 285     elseif == #to #KOO
 286       castle #K #KOO #HR #ROO
 287     endif
 288   endif
 289   set K #to
 290   unsetflag #from
 291 endsub
 292 sub k from to
 293   set legal fn K #from #to
 294   if not var legal or == old r
 295     if == #to #kooo
 296       castle #k #kooo #ar #rooo
 297     elseif == #to #koo
 298       castle #k #koo #hr #roo
 299     endif
 300   endif
 301   set k #to
 302   unsetflag #from
 303 endsub
 304 sub R from to
 305   set legal fn R #from #to
 306   if not var legal or == old K
 307     echo "Castling with Rook!" #from #to #AR #ROOO #HR #ROO
 308     if == #from #AR and == #to #ROOO
 309       castle #K #KOOO #from #ROOO
 310       set K #KOOO
 311     elseif == #from #HR and == #to #ROO
 312       castle #K #KOO #from #ROO
 313       set K #KOO
 314     endif
 315   endif
 316   unsetflag #from
 317 endsub
 318 sub r from to
 319   set legal fn R #from #to
 320   if not var legal or == old k
 321     if == #from #ar and == #to #rooo
 322       castle #k #kooo #from #rooo
 323       set k #kooo
 324     elseif == #from #hr and == #to #roo
 325       castle #k #koo #from #roo
 326       set k #koo
 327     endif
 328   endif
 329   unsetflag #from
 330 endsub
 331 sub castle
 332   local ATTACKED c KP RP KF KT RF RT RN
 333   if < count #subargs 4
 334     die The castle suboutine requires at least four arguments.
 335   endif
 336   set KF #subargs.0
 337   set KT #subargs.1
 338   set RF #subargs.2
 339   set RT #subargs.3
 340   if > count #subargs 4
 341     set RN #subargs.4
 342   else
 343     set RN Rook
 344   endif
 345   if not flag #KF
 346     die A King may not castle after it moves.
 347   endif
 348   if not flag #RF
 349     die A #RN may not castle after it moves.
 350   endif
 351   if empty #KF and empty #RF
 352     die Please castle by moving only one piece.
 353   elseif empty #KF
 354     if != #RF #KT
 355       if capture
 356         die The King may not castle to an occupied space.
 357       endif
 358       set RP space #RF
 359     else
 360       set RP old
 361       setglobal lastcaptured nil
 362     endif
 363     set KP space #KT
 364     empty #KT
 365     empty #RF
 366   elseif empty #RF
 367     if != #KF #RT
 368       if capture
 369         die The #RN may not castle to an occupied space.
 370       endif
 371       set KP space #KF
 372     else
 373       set KP old
 374       setglobal lastcaptured nil
 375     endif
 376     set RP space #RT
 377     empty #KF
 378     empty #RT
 379   elseif capture
 380     die You're not allowed to castle with a null move.
 381   else
 382     set RP space #RF
 383     set KP space #KF
 384     empty #KF
 385     empty #RF
 386   endif
 387   unsetflag #KF
 388   unsetflag #RF
 389   if not checkride #KF #KT 1 0 and != #KF #KT
 390     die The King may not castle across an obstructed path.
 391   endif
 392   if not checkride #RF #RT 1 0 and != #RF #RT
 393     die The #RN may not castle across an obstructed path.
 394   endif
 395   add #RP #RF
 396   set ATTACKED ATTACKEDBYW unless isupper moved ATTACKEDBYB
 397   if fn #ATTACKED #KT
 398     die A King may not castle out of check.
 399   endif
 400   for c path #KF #KT
 401     if fn var ATTACKED #c
 402       die A King may not castle through check.
 403     endif
 404   next
 405   move #RF #RT
 406   add #KP #KT
 407   set legal true
 408 endsub
 409 sub castlepos KF KT RF RT
 410   local ATTACKED c safe
 411   verify flag #KF
 412   verify flag #RF
 413   verify empty #KT or match #KT #KF #RF
 414   verify empty #RT or match #RT #KF #RF
 415   verify checkride #KF #RF 1 0
 416   verify checkride #KF #KT 1 0 or checkride #RF #KT 1 0
 417   verify allequal rank #KF rank #KT rank #RF rank #RT
 418   if isupper space #king
 419     def friend isupper #0
 420     def friends onlyupper
 421     set attacked ATTACKEDBYB
 422   else
 423     def friend islower #0
 424     def friends onlylower
 425     set attacked ATTACKEDBYW
 426   endif
 427   verify not fn var attacked #KF
 428   verify not fn var attacked #KT
 429   foreach c path #KF #KT
 430     verify not fn var attacked #c
 431   next
 432   store
 433   if != #KT #RF
 434     move #KF #KT
 435     move #RF #RT
 436   else
 437     move #RF #RT
 438     move #KF #KT
 439   endif
 440   set safe not fn var attacked #KT
 441   restore
 442   return #safe
 443 endsub
 444 sub stalemated king
 445   local legalmove temp from piece to attacked ra
 446   if isupper space #king
 447     def friend isupper #0
 448     def friends onlyupper
 449     set attacked ATTACKEDBYB
 450   else
 451     def friend islower #0
 452     def friends onlylower
 453     set attacked ATTACKEDBYW
 454   endif
 455   store
 456   set kingmoves fn KL #king
 457   for to #kingmoves
 458     if not fn friend space #to and onboard #to
 459       move #king #to
 460       set incheck fn var attacked #to
 461       restore
 462       if not #incheck
 463         setlegal #king #to
 464       endif
 465     endif
 466   next
 467   if isupper space #king
 468     if sub castlepos #king #KOOO #AR #ROOO
 469       if > distance #king #KOOO 1 or == #KOOO #AR
 470         setlegal #king #KOOO
 471       else
 472         setlegal #AR #ROOO
 473       endif
 474     endif
 475     if sub castlepos #king #KOO #HR #ROO
 476       if > distance #king #KOO 1 or == #KOO #HR
 477         setlegal #king #KOO
 478       else
 479         setlegal #HR #ROO
 480       endif
 481     endif
 482   else
 483     if sub castlepos #king #kooo #ar #rooo
 484       if > distance #king #kooo 1 or == #kooo #ar
 485         setlegal #king #kooo
 486       else
 487         setlegal #ar #rooo
 488       endif
 489     endif
 490     if sub castlepos #king #koo #hr #roo
 491       if > distance #king #koo 1 or == #koo #hr
 492         setlegal #king #koo
 493       else
 494         setlegal #hr #roo
 495       endif
 496     endif
 497   endif
 498   restore
 499   for (from piece) fn friends
 500     if == #from #king
 501       continue
 502     endif
 503     for to fn join #piece L #from
 504       if fn #piece #from #to and not fn friend space #to and onboard #to
 505         move #from #to
 506         set incheck fn var attacked #king
 507         if not #incheck
 508           setlegal #from #to
 509         endif
 510       endif
 511       restore
 512     next
 513   next
 514   return cond count system legalmoves false true
 515 endsub
 516 sub calc_original_position
 517   store
 518   local a1 b1 c1 d1 e1 f1 g1 h1 n bb w b r q k K Q R B N ra firstr lastr last
 519   add a1 a1
 520   add b1 b1
 521   add c1 c1
 522   add d1 d1
 523   add e1 e1
 524   add f1 f1
 525   add g1 g1
 526   add h1 h1
 527   add a1 a8
 528   add b1 b8
 529   add c1 c8
 530   add d1 d8
 531   add e1 e8
 532   add f1 f8
 533   add g1 g8
 534   add h1 h8
 535   set many n 1 bb 2 bw 4 b 6 r 8 q 16 k 32
 536   set a1 orsum #r #n #bb #q
 537   set b1 orsum #r #n #bw #q #k
 538   set c1 orsum #r #n #bb #q #k
 539   set d1 orsum #r #n #bw #q #k
 540   set e1 orsum #r #n #bb #q #k
 541   set f1 orsum #r #n #bw #q #k
 542   set g1 orsum #r #n #bb #q #k
 543   set h1 orsum #r #n #bw #q
 544   set many K 1 Q 1 R 2 B 2 N 2
 545   set rank1 array a1 b1 c1 d1 e1 f1 g1 h1
 546   setflag a1 b1 c1 d1 e1 f1 g1 h1 a8 b8 c8 d8 e8 f8 g8 h8
 547   foreach i range 0 $maxmoves
 548     set normal true
 549     set mv move #i
 550     if not var mv
 551       echo "Continue because mv is empty"
 552       continue
 553     endif
 554     set mv str_replace " - " chr 45 var mv
 555     set pm explode " " var mv
 556     set p elem 0 pm
 557     set m elem 1 pm
 558     if != var m null
 559       set od explode hyphen var m
 560     else
 561       set od explode hyphen var mv
 562       unset p
 563     endif
 564     set o elem 0 od
 565     set d elem 1 od
 566     echo "mv is {#mv}, p is {#p}, o is {#o}"
 567     if == #mv #o
 568       echo "Continue because {#mv} is {#o}"
 569       continue
 570     endif
 571     set pp space #o
 572     echo "space {#o} is {#pp}"
 573     echo #i #pp #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 574     set b2 list base 2 #a1 base 2 #b1 base 2 #c1 base 2 #d1 base 2 #e1 base 2 #f1 base 2 #g1 base 2 #h1
 575     echo #b2
 576     if match #pp p P
 577       if checkleap #o #d 1 1 and empty #d
 578         set ep join filename #d rankname #o
 579         if == space #ep flipcase space #0
 580           empty #ep
 581         endif
 582       endif
 583       move #o #d
 584       continue
 585     elseif match #pp n N b B r R q Q
 586       move #o #d
 587       continue
 588     endif
 589     set bp onebits var #pp
 590     echo "{#bp} one bits in var {#pp}"
 591     if > #bp 1 and match var p k q r b n p K Q R B N P and != var p null
 592       set lc tolower var p
 593       set #pp bitand ##pp ##lc
 594     elseif == ##pp "@"
 595       echo "Warning: There is no piece on {#o}"
 596     elseif > #bp 1
 597       if checkleap #o #d 1 2
 598         set #pp bitand ##pp #n
 599       elseif checkleap #o #d 1 0
 600         set os orsum #r #q #k
 601         set #pp bitand ##pp orsum #r #q #k
 602       elseif checkleap #o #d 1 1
 603         set #pp bitand ##pp orsum #b #q #k
 604       elseif checkride #o #d 1 1
 605         set #pp bitand ##pp orsum #b #q
 606       elseif checkride #o #d 1 0
 607         echo "rook ride"
 608         if == rank #o rank #d and match rankname #d 1 8
 609           if match #d c1 g1 c8 g8 and flag #o
 610             if not empty #d
 611               echo "King castles by moving to Rook's space."
 612               set #pp bitand ##pp #k
 613               set ro #d
 614               set rp space #ro
 615               set #rp #r
 616               echo "rp: {#rp}, val: {##rp}"
 617               if == #d c1
 618                 set rd d1
 619               elseif == #d c8
 620                 set rd d8
 621               elseif == #d g1
 622                 set rd f1
 623               else
 624                 set rd f8
 625               endif
 626               move #o temp
 627               move #d #rd
 628               move temp #d
 629               foreach f flags
 630                 if == rank f rank #o
 631                   unsetflag #f
 632                 endif
 633               next
 634               set normal false
 635             elseif empty #d and bitand ##pp #k
 636               echo "King castling by moving 2+ spaces"
 637               if == #d c1
 638                 if empty b1
 639                   set ro a1
 640                 else
 641                   set ro b1
 642                 endif
 643                 set rd d1
 644               elseif == #d g1
 645                 set ro h1
 646                 set rd f1
 647               elseif == #d c8
 648                 if empty b8
 649                   set ro a8
 650                 else
 651                   set ro b8
 652                 endif
 653                 set rd d8
 654               elseif == #d g8
 655                 set ro h8
 656                 set rd f8
 657               endif
 658               set rp space #ro
 659               if not bitand #ko #r or not bitand #a1 #r or match file #ro a h bitand ##rp #r and not bitand ##pp #q and flag #ro
 660                 move #o #d
 661                 move #ro #rd
 662                 set #pp #k
 663                 set #rp #r
 664                 foreach f flags
 665                   if == rank f rank #o
 666                     unsetflag #f
 667                   endif
 668                 next
 669                 set normal false
 670               else
 671                 echo "Assuming not actually a castling move."
 672                 set #pp bitand ##pp orsum #r #q
 673               endif
 674             else
 675               echo "Rook or Queen move"
 676               set #pp bitand ##pp orsum #r #q
 677             endif
 678           elseif not empty #d and match #d f1 d1 f8 d8 and flag #o
 679             echo "Rook castles by moving to King's space."
 680             set #pp bitand ##pp #r
 681             set ko #d
 682             echo "ko set to {#ko}"
 683             set kp space #ko
 684             set #kp #k
 685             echo "{#kp} set to {##kp}"
 686             if == #d f1
 687               set kd g1
 688             elseif == #d d1
 689               set kd c1
 690             elseif == #d f8
 691               set kd g8
 692             elseif == #d d8
 693               set kd c8
 694             endif
 695             if == #kd #o
 696               swap #kd #o
 697             else
 698               move #o #d
 699               move #ko #kd
 700             endif
 701             foreach f flags
 702               if == rank f rank #o
 703                 unsetflag #f
 704               endif
 705             next
 706             set normal false
 707           else
 708             echo "Rook or Queen move"
 709             set #pp bitand ##pp orsum #r #q
 710           endif
 711         else
 712           echo "{#pp} currently set to {##pp}"
 713           set #pp bitand ##pp bitor #r #q
 714           echo "{#pp} now set to {##pp}"
 715         endif
 716       elseif checkhop #o #d 1 0 and match rankname #o 1 8 and flag #o
 717         echo "rook hopping king to castle"
 718         if and match #d f1 d1 f8 d8
 719           set #pp bitand ##pp #r
 720           set ko screen
 721           set kp var space #ko
 722           set #kp #k
 723           if == #d f1
 724             set kd g1
 725           elseif == #d d1
 726             set kd c1
 727           elseif == #d f8
 728             set kd g8
 729           elseif == #d d8
 730             set kd c8
 731           endif
 732           if == #kd #o and == #d #ko
 733             swap #kd #o
 734           elseif == #d #ko
 735             move #o temp
 736             move #ko #kd
 737             move temp #d
 738           else
 739             move #o #d
 740             move #ko #kd
 741           endif
 742           foreach f flags
 743             if == rank f rank #o
 744               unsetflag #f
 745             endif
 746           next
 747           set normal false
 748         elseif match #d c1 g1 c8 g8 and flag #o
 749           echo "King castling by hopping over Rook"
 750           set #pp bitand ##pp #k
 751           set ro screen
 752           set rp var space #ro
 753           set #rp #r
 754           if == #d c1
 755             set rd d1
 756           elseif == #d c8
 757             set rd d8
 758           elseif == #d g1
 759             set rd f1
 760           else
 761             set rd f8
 762           endif
 763           move #o #d
 764           move #ro #rd
 765           foreach f flags
 766             if == rank f rank #o
 767               unsetflag #f
 768             endif
 769           next
 770           set normal false
 771         endif
 772       endif
 773       if == ##pp 0
 774         echo "ERROR: Potential piece value set to zero"
 775       endif
 776     endif
 777     do
 778       set b2 list base 2 #a1 base 2 #b1 base 2 #c1 base 2 #d1 base 2 #e1 base 2 #f1 base 2 #g1 base 2 #h1
 779       echo #b2
 780       set changed false
 781       set ra aggregate lambda (cond bitand var #0 #k #0 false) #rank1
 782       if == count #ra 1
 783         set kp #ra.0
 784         if != ##kp #k
 785           set #kp #k
 786           set changed true
 787         endif
 788         set ra aggregate lambda (cond == var #0 #k #0 false) #rank1
 789         set kp #ra.0
 790         echo #kp
 791         set leftside aggregate lambda (cond < #0 #kp #0 false) #rank1
 792         printr #leftside
 793         set ra aggregate lambda (cond bitand var #0 #r #0 false) #leftside
 794         if == count #ra 1
 795           foreach sp #ra
 796             if != ##sp #r
 797               set #sp #r
 798               set changed true
 799             endif
 800           next
 801         else
 802           set ra aggregate lambda (cond == var #0 #r #0 false) #leftside
 803           if == count #ra 1
 804             foreach sp #leftside
 805               if != ##sp #r
 806                 set #sp bitand ##sp bitxor 63 #r
 807                 set changed true
 808               endif
 809             next
 810           endif
 811         endif
 812         set rightside aggregate lambda (cond > #0 #kp #0 false) #rank1
 813         set ra aggregate lambda (cond bitand var #0 #r #0 false) #rightside
 814         if == count #ra 1
 815           foreach sp #ra
 816             if != ##sp #r
 817               set #sp #r
 818               set changed true
 819             endif
 820           next
 821         else
 822           set ra aggregate lambda (cond == var #0 #r #0 false) #rightside
 823           if == count #ra 1
 824             foreach sp #rightside
 825               if != ##sp #r
 826                 set #sp bitand ##sp bitxor 63 #r
 827                 set changed true
 828               endif
 829             next
 830           endif
 831         endif
 832       else
 833         set ra aggregate lambda (cond != var #0 #k #0 false) #rank1
 834         if == count #ra 7
 835           foreach sp #ra
 836             if bitand ##sp #k
 837               set #sp bitand ##sp bitxor 63 #k
 838               set changed true
 839             endif
 840           next
 841         endif
 842       endif
 843       set ra aggregate lambda (cond bitand var #0 #q #0 false) #rank1
 844       if == count #ra 1
 845         foreach sp #ra
 846           if != ##sp #q
 847             set #sp #q
 848             set changed true
 849           endif
 850         next
 851       else
 852         set ra aggregate lambda (cond != var #0 #q #0 false) #rank1
 853         if == count #ra 7
 854           echo queen before #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 855           foreach sp #ra
 856             if bitand ##sp #q
 857               set #sp bitand ##sp bitxor 63 #q
 858               set changed true
 859             endif
 860           next
 861           echo queen after #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 862         endif
 863       endif
 864       echo q end #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 865       set ra aggregate lambda (cond bitand var #0 #bb #0 false) #rank1
 866       if == count #ra 1
 867         foreach sp #ra
 868           if != ##sp #bb
 869             set #sp #bb
 870             set changed true
 871           endif
 872         next
 873       else
 874         set ra aggregate lambda (cond != var #0 #bb #0 false) #rank1
 875         if == count #ra 7
 876           foreach sp #ra
 877             if bitand ##sp #bb
 878               set #sp bitand ##sp bitxor 63 #bb
 879               set changed true
 880             endif
 881           next
 882         endif
 883       endif
 884       echo bb end #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 885       set ra aggregate lambda (cond bitand var #0 #bw #0 false) #rank1
 886       if == count #ra 1
 887         foreach sp #ra
 888           if != ##sp #bw
 889             set #sp #bw
 890             set changed true
 891           endif
 892         next
 893       else
 894         set ra aggregate lambda (cond != var #0 #bw #0 false) #rank1
 895         if == count #ra 7
 896           foreach sp #ra
 897             if bitand ##sp #bw
 898               set #sp bitand ##sp bitxor 63 #bw
 899               set changed true
 900             endif
 901           next
 902         endif
 903       endif
 904       echo bw end #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 905       set ra aggregate lambda (cond bitand var #0 #r #0 false) #rank1
 906       if == count #ra 2
 907         foreach sp #ra
 908           if != ##sp #r
 909             set #sp #r
 910             set changed true
 911           endif
 912         next
 913         set betweenrooks aggregate lambda (cond and < #ra.0 #0 > #ra.1 #0 #0 false) #rank1
 914         set ra2 aggregate lambda (cond bitand var #0 #k #0 false) #betweenrooks
 915         if == count #ra2 1
 916           foreach sp #ra2
 917             if != ##sp #k
 918               set #sp #k
 919               set changed true
 920             endif
 921           next
 922         else
 923           set ra2 aggregate lambda (cond == var #0 #r #0 false) #rank1
 924           foreach sp #rank1
 925             echo #ra2.0 #ra2.1
 926             if < #sp #ra2.0 or > #sp #ra2.1 and bitand ##sp #k
 927               set #sp bitand ##sp bitxor 63 #k
 928               set changed true
 929             endif
 930           next
 931         endif
 932       else
 933         set firstr #ra.0
 934         set last - count #ra 1
 935         set lastr #ra.{#last}
 936         echo "firstr is {#firstr}, and lastr is {#lastr}"
 937         set rooks 0
 938         foreach sp #rank1
 939           if match #sp #firstr #lastr
 940             inc rooks
 941             if bitand ##sp #k
 942               set #sp bitand ##sp bitxor 63 #k
 943               set changed true
 944             endif
 945           elseif != #rooks 1
 946             if bitand ##sp #k
 947               set #sp bitand ##sp bitxor 63 #k
 948               set changed true
 949             endif
 950           endif
 951         next
 952         if == count #ra 3
 953           set leftking anytrue lambda (bitand var #0 #k and > #0 #ra.0 and < #0 #ra.1) #rank1
 954           set rghtking anytrue lambda (bitand var #0 #k and > #0 #ra.1 and < #0 #ra.2) #rank1
 955           if not #leftking
 956             set #ra.2 #r
 957           elseif not #rghtking
 958             set #ra.0 #r
 959           endif
 960         endif
 961         set ra aggregate lambda (cond != var #0 #r #0 false) #rank1
 962         if == count #ra 6
 963           echo "Two rooks found."
 964           foreach sp #ra
 965             if bitand ##sp #r
 966               set #sp bitand ##sp bitxor 63 #r
 967               set changed true
 968             endif
 969           next
 970         elseif == count #ra 7
 971           echo "One Rook found"
 972           set ra aggregate lambda (cond == var #0 #r #0 false) #rank1
 973           set next where #ra.0 1 0
 974           do while onboard #next
 975             echo #next ##next
 976             if bitand ##next #r
 977               set #next bitand ##next bitxor 63 #r
 978               set changed true
 979             endif
 980             if bitand ##next #k
 981               break
 982             endif
 983             set next where #next 1 0
 984           loop
 985           set prev where #ra.0 -1 0
 986           do while onboard #prev
 987             if bitand ##prev #r
 988               set #prev bitand ##prev bitxor 63 #r
 989               set changed true
 990             endif
 991             if bitand ##prev #k
 992               break
 993             endif
 994             set prev where #prev -1 0
 995           loop
 996         endif
 997         echo r #mv #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
 998       endif
 999       echo first #a1 #b1 #c1 #d1 #e1 #f1 #g1 #h1
1000       set ra aggregate lambda (cond bitand var #0 #2 #0 false) #rank1
1001       if == count #ra 2
1002         foreach sp #ra
1003           if != ##sp #n
1004             set #sp #n
1005             set changed true
1006           endif
1007         next
1008       else
1009         set ra aggregate lambda (cond != var #0 #n #0 false) #rank1
1010         if == count #ra 6
1011           foreach sp #ra
1012             if bitand ##sp #n
1013               set #sp bitand ##sp bitxor 63 #n
1014               set changed true
1015             endif
1016           next
1017         endif
1018       endif
1019     loop while #changed
1020     if var normal
1021       move #o #d
1022       unsetflag #o #d
1023     endif
1024   next
1025   set fr ""
1026   foreach c (a1 b1 c1 d1 e1 f1 g1 h1)
1027     if == ##c #n
1028       set fr join #fr "N"
1029     elseif match ##c #bb #bw
1030       set fr join #fr "B"
1031     elseif == ##c #r
1032       set fr join #fr "R"
1033     elseif == ##c #q
1034       set fr join #fr "Q"
1035     elseif == ##c #k
1036       set fr join #fr "K"
1037     else
1038       set fr join #fr "@"
1039     endif
1040   next
1041   if !== false strstr #fr "@"
1042     set pat str_replace "@" "?" #fr
1043     empty a1 b1 c1 d1 e1 f1 g1 h1 a8 b8 c8 d8 e8 f8 h8
1044     drop B any a1 c1 e1 g1
1045     drop B any b1 d1 f1 h1
1046     drop Q any a1 b1 c1 d1 e1 f1 g1 h1
1047     drop N any a1 b1 c1 d1 e1 f1 g1 h1
1048     drop N any a1 b1 c1 d1 e1 f1 g1 h1
1049     drop R first a1 b1 c1 d1 e1 f1
1050     drop K first b1 c1 d1 e1 f1 g1
1051     drop R last c1 d1 e1 f1 g1 h1
1052     set fr null
1053     for i range a h
1054       set fr join var fr space join var i 1
1055     next
1056     if not fnmatch var pat var fr
1057       die "This game may have been too short to properly calculate the original position, and the calculated pattern of {#pat} is inconsistent with randomly generated value of {#fr}. If you think this game does have enough data to calculate the original position, please report it to Fergus Duniho."
1058     endif
1059   endif
1060   restore
1061   setconst firstrank #fr
1062   for i range 0 7
1063     set c join chr + 97 var i 1
1064     set p substr const firstrank var i 1
1065     add #p #c
1066   next
1067   echo "firstrank is" @firstrank
1068 endsub
1069 endlib
1070 lib chess
1071 set wpr 2
1072 set bpr 7
1073 set fps 2
1074 set pzs 1
1075 set wcastle c1 g1
1076 set bcastle c8 g8
1077 do
1078   local x
1079   for x piecekeys
1080     if match #x P K p k
1081       continue
1082     elseif isupper #x
1083       push wprom #x
1084     elseif islower #x
1085       push bprom #x
1086     endif
1087   next
1088 loop never
1089 setsystem maxmove 2
1090 ban commands allmoves
1091 allow moves 1 captures 1 promotions 2
1092 def N checkleap #0 #1 1 2
1093 def B checkride #0 #1 1 1
1094 def R checkride #0 #1 1 0
1095 def Q fn B #0 #1 or fn R #0 #1
1096 def K checkleap #0 #1 1 1 or checkleap #0 #1 1 0
1097 def M fn N #0 #1 or fn R #0 #1
1098 def A fn N #0 #1 or fn B #0 #1
1099 def n checkleap #0 #1 1 2
1100 def b checkride #0 #1 1 1
1101 def r checkride #0 #1 1 0
1102 def q fn b #0 #1 or fn r #0 #1
1103 def k checkleap #0 #1 1 1 or checkleap #0 #1 1 0
1104 def m fn n #0 #1 or fn r #0 #1
1105 def a fn n #0 #1 or fn b #0 #1
1106 def P
remove var ep
and checkleap #0 #1 1 1
and == var ep join filename #1 rankname #0
or and checkride #0 #1 0 1 == rankname #0 var wpr
or checkleap #0 #1 0 1
and empty #1
or and islower space #1 checkleap #0 #1 1 1
and <= distance #0 #1 var fps
and > rank #1 rank #0
1107 def p
remove var ep
and checkleap #0 #1 1 1
and == var ep join filename #1 rankname #0
or and checkride #0 #1 0 1 == rankname #0 var bpr
or checkleap #0 #1 0 1
and empty #1
or and isupper space #1 checkleap #0 #1 1 1
and <= distance #0 #1 var fps
and < rank #1 rank #0
1108 sub capturep p
1109   empty #p
1110   return true
1111 endsub
1112 sub checks king
1113   if not dest
1114     return false
1115   endif
1116   my checks c
1117   set checks ()
1118   if fn space dest dest #king
1119     setelem checks dest space dest
1120   endif
1121   set c sub checkedthru #king origin
1122   if #c
1123     setelem checks #c space #c
1124   elseif #epc
1125     set c sub checkedthru #king #epc
1126     if #c
1127       setelem checks #c space #c
1128     endif
1129   endif
1130   return var checks
1131 endsub
1132 sub checkmated king checks
1133   local from piece to key legalmove piece nopawn
1134   store
1135   if isupper space #king
1136     def friends onlyupper
1137     def friend isupper #0
1138     set attacked ATTACKEDBYB
1139   else
1140     def friends onlylower
1141     def friend islower #0
1142     set attacked ATTACKEDBYW
1143   endif
1144   set kingmoves fn KL #king
1145   for to #kingmoves
1146     if not fn friend space #to and onboard #to
1147       move #king #to
1148       set incheck fn var attacked #to
1149       restore
1150       if not #incheck
1151         setlegal #king #to
1152       endif
1153     endif
1154   next
1155   if == count var checks 1
1156     for (key enemy) var checks
1157       set possible path #king #key
1158       push possible #key
1159       if == #key #ep
1160         push possible cond isupper space #ep where #ep 0 -1 where #ep 0 1
1161       endif
1162       for (from piece) fn friends
1163         if == #from #king
1164           continue
1165         endif
1166         for to #possible
1167           if fn #piece #from #to
1168             move #from #to
1169             set incheck fn var attacked #king
1170             if not #incheck
1171               setlegal #from #to
1172             endif
1173           endif
1174           restore
1175         next
1176       next
1177     next
1178   endif
1179   return cond count system legalmoves false true and checks
1180 endsub
1181 def PL array where #0 0 2 where #0 0 1 where #0 -1 1 where #0 1 1
1182 def pL array where #0 0 -2 where #0 0 -1 where #0 -1 -1 where #0 1 -1
1183 def NL leaps #0 1 2
1184 def BL rays #0 1 1
1185 def RL rays #0 1 0
1186 def VL rays #0 1 1
1187 def CL rays #0 1 0
1188 def QL merge rays #0 1 0 rays #0 1 1
1189 def KL merge leaps #0 1 0 leaps #0 1 1
1190 def AL merge leaps #0 1 2 rays #0 1 1
1191 def ML merge rays #0 1 0 leaps #0 1 2
1192 def nL leaps #0 1 2
1193 def bL rays #0 1 1
1194 def rL rays #0 1 0
1195 def vL rays #0 1 1
1196 def cL rays #0 1 0
1197 def qL merge rays #0 1 0 rays #0 1 1
1198 def kL merge leaps #0 1 0 leaps #0 1 1
1199 def aL merge leaps #0 1 2 rays #0 1 1
1200 def mL merge rays #0 1 0 leaps #0 1 2
1201 sub castlepos from to
1202   local c RPOS RDEST xdir safe
1203   verify flag #from
1204   verify empty #to
1205   if isupper space #king
1206     def friend isupper #0
1207     def friends onlyupper
1208     set attacked ATTACKEDBYB
1209   else
1210     def friend islower #0
1211     def friends onlylower
1212     set attacked ATTACKEDBYW
1213   endif
1214   set xdir sign minus file #to file #from
1215   verify checkaride #from #to #xdir 0
1216   verify not fn var attacked #from
1217   set c #to
1218   do
1219     set c where #c #xdir 0
1220     if flag #c
1221       break
1222     endif
1223     verify onboard #c
1224     verify empty #c
1225   loop
1226   verify flag #c
1227   set RPOS #c
1228   store
1229   for c path #from #to
1230     move #from #c
1231     set safe not fn var attacked #c
1232     restore
1233     verify #safe
1234   next
1235   move #from #to
1236   set RDEST where #to neg #xdir 0
1237   move #RPOS #RDEST
1238   return true
1239 endsub
1240 sub stalemated king
1241   local legalmove temp from piece to attacked ra
1242   if isupper space #king
1243     def friend isupper #0
1244     def friends onlyupper
1245     set attacked ATTACKEDBYB
1246     set cspaces var wcastle
1247   else
1248     def friend islower #0
1249     def friends onlylower
1250     set attacked ATTACKEDBYW
1251     set cspaces var bcastle
1252   endif
1253   store
1254   set kingmoves fn KL #king
1255   for to #kingmoves
1256     if not fn friend space #to and onboard #to
1257       move #king #to
1258       set incheck fn var attacked #to
1259       restore
1260       if not #incheck
1261         setlegal #king #to
1262       endif
1263     endif
1264   next
1265   for to var cspaces
1266     if sub castlepos #king #to
1267       set incheck fn var attacked #to
1268       restore
1269       if not #incheck
1270         setlegal #king #to
1271       endif
1272     endif
1273   next
1274   restore
1275   for (from piece) fn friends
1276     if == #from #king
1277       continue
1278     endif
1279     for to fn join #piece L #from
1280       if fn #piece #from #to and not fn friend space #to and onboard #to
1281         move #from #to
1282         set incheck fn var attacked #king
1283         if not #incheck
1284           setlegal #from #to
1285         endif
1286       endif
1287       restore
1288     next
1289   next
1290   return cond count system legalmoves false true
1291 endsub
1292 def WPAWN match P what #0 1 -1 what #0 -1 -1
1293 def BPAWN match p what #0 1 1 what #0 -1 1
1294 def KNIGHT check what #0 1 2 check what #0 -1 2 check what #0 1 -2 check what #0 -1 -2 check what #0 2 1 check what #0 -2 1 check what #0 2 -1 check what #0 -2 -1 target #1
1295 def WAZIR check what #0 0 -1 check what #0 -1 0 check what #0 0 1 check what #0 1 0 target #1
1296 def FERZ check what #0 -1 -1 check what #0 -1 1 check what #0 1 -1 check what #0 1 1 target #1
1297 def KING fn WAZIR #0 #1 or fn FERZ #0 #1
1298 def ROOK check insight #0 0 -1 check insight #0 -1 0 check insight #0 0 1 check insight #0 1 0 target #1
1299 def BISHOP check insight #0 -1 -1 check insight #0 -1 1 check insight #0 1 -1 check insight #0 1 1 target #1
1300 def ATTACKEDBYB fn KING #0 k or fn BPAWN #0 or fn KNIGHT #0 (n a m) or fn ROOK #0 (r q m) or fn BISHOP #0 (b q a)
1301 def ATTACKEDBYW fn KING #0 K or fn WPAWN #0 or fn KNIGHT #0 (N A M) or fn ROOK #0 (R Q M) or fn BISHOP #0 (B Q A)
1302 sub P from to
1303   local ydir
1304   if == file #from file #to and not capture
1305     set legal checkaleap #from #to 0 1
1306     if var legal
1307       set ep false
1308     else
1309       set legal checkaride #from #to 0 1 and <= distance #from #to #fps and or == rankname #from #wpr < #wpr 0
1310       set ep #to
1311     endif
1312     set epc false
1313   elseif capture or #ep
1314     set legal checkaleap #from #to -1 1 or checkaleap #from #to 1 1
1315     set epc false
1316     if not capture and var legal
1317       set legal > rank #to rank #ep and < rankname #to #bpr and == file #to file #ep
1318       if var legal
1319         capture #ep
1320         set epc #ep
1321       endif
1322     endif
1323     set ep false
1324   endif
1325   if != space #to moved and onboard where #to 0 #pzs
1326     die "You may not promote a Pawn until it reaches the promotion zone."
1327   endif
1328   if not onboard where #to 0 1
1329     if == P space #to
1330       askpromote #wprom
1331     elseif not match space #to var wprom
1332       set np space #to
1333       die "You may not promote your Pawn to a" #np
1334     endif
1335   endif
1336 endsub
1337 sub p from to
1338   if == file #from file #to and not capture
1339     set legal checkaleap #from #to 0 -1
1340     if var legal
1341       set ep false
1342     else
1343       set legal checkaride #from #to 0 -1 and <= distance #from #to #fps and or == rankname #from #bpr > #bpr lastrank
1344       set ep #to
1345     endif
1346     set epc false
1347   elseif capture or #ep
1348     set legal checkaleap #from #to -1 -1 or checkaleap #from #to 1 -1
1349     set epc false
1350     if not capture and var legal
1351       set legal < rank #to rank #ep and > rankname #to #wpr and == file #to file #ep
1352       if var legal
1353         capture #ep
1354         set epc #ep
1355       endif
1356     endif
1357     set ep false
1358   endif
1359   if != space #to moved and onboard where #to 0 neg #pzs
1360     die You may not promote a Pawn until it reaches the promotion zone.
1361   endif
1362   if not onboard where #to 0 -1
1363     if == p space #to
1364       askpromote #bprom
1365     elseif not match space #to var bprom
1366       set np space #to
1367       die You may not promote your Pawn to a #np
1368     endif
1369   endif
1370 endsub
1371 sub K from to
1372   if match #to var wcastle and flag #from
1373     set legal sub castle
1374   else
1375     set legal fn K #from #to
1376   endif
1377   set K #to
1378   unsetflag e1
1379 endsub
1380 sub k from to
1381   if match #to var bcastle and flag #from
1382     set legal sub castle
1383   else
1384     set legal fn k #from #to
1385   endif
1386   set k #to
1387   unsetflag e8
1388 endsub
1389 sub castle
1390   local ATTACKED c RPOS RDEST xdir
1391   if not flag #from
1392     die A King may not castle after it moves.
1393   endif
1394   if capture
1395     die A King may not castle to an occupied space.
1396   endif
1397   set xdir sign minus file #to file #from
1398   if not checkaride #from #to #xdir 0
1399     die A King may not castle across any occupied space.
1400   endif
1401   set c #to
1402   do
1403     set c where #c #xdir 0
1404     if flag #c
1405       break
1406     elseif not onboard #c
1407       die No piece was found to castle with.
1408     elseif not empty #c
1409       die The King cannot castle with the piece at #c
1410     endif
1411   loop
1412   set RPOS #c
1413   set ATTACKED ATTACKEDBYW unless isupper moved ATTACKEDBYB
1414   if fn var ATTACKED #from
1415     die A King may not castle out of check.
1416   endif
1417   for c path #from #to
1418     if fn var ATTACKED #c
1419       die A King may not castle through check.
1420     endif
1421   next
1422   if == count var subargs 0
1423     set RDEST where #to neg #xdir 0
1424   else
1425     set RDEST elem 0 subarg
1426   endif
1427   unsetflag #RPOS
1428   move #RPOS #RDEST
1429   return true
1430 endsub
1431 sub checkedthru king loc
1432   my dir c
1433   set c revealed #king #loc
1434   verify fn space #c #c #king and not samecase space #king space #c and onboard #c and #c
1435   return #c
1436 endsub
1437 def fn checkedfrom fn space #1 #0 and xor isupper space #0 isupper space #1 and not empty #1
1438 sub P1 from to
1439   if == file #from file #to
1440     return not capture
1441   elseif capture
1442     return true
1443   elseif == file #to file #ep and == rank #from rank #ep and #ep
1444     capture #ep
1445     return true
1446   endif
1447   return false
1448 endsub
1449 sub PP from to
1450   if checkatwostep #from #to 0 1 0 1 or checkaleap #from #to 0 1
1451     return empty #to
1452   elseif not checkaleap #from #to 1 1 and not checkaleap #from #to -1 1
1453     return false
1454   elseif not empty #to
1455     return true
1456   elseif == file #to file #ep and == rank #from rank #ep and #ep
1457     capture #ep
1458     return true
1459   endif
1460   return false
1461 endsub
1462 sub pp from to
1463   if checkatwostep #from #to 0 -1 0 -1 or checkaleap #from #to 0 -1
1464     return empty #to
1465   elseif not checkaleap #from #to 1 -1 and not checkaleap #from #to -1 -1
1466     return false
1467   elseif not empty #to
1468     return true
1469   elseif == file #to file #ep and == rank #from rank #ep and #ep
1470     capture #ep
1471     return true
1472   endif
1473   return false
1474 endsub
1475 endlib