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 f7-f6, p is #p, o is f7

space f7 is p

1 p f7-f6 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

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

space h2 is P

2 P h2-h4 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

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

space b7 is p

3 p b7-b5 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

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

space e1 is e1

4 e1 e1-f3 27 61 59 61 59 61 59 29

11011 111101 111011 111101 111011 111101 111011 11101

5 one bits in var e1

11011 111101 111011 111101 1 111101 111011 11101

q end e1-f3 27 61 59 61 1 61 59 29

bb end e1-f3 27 61 59 61 1 61 59 29

bw end e1-f3 27 61 59 61 1 61 59 29

firstr is a1, and lastr is h1

r e1-f3 27 61 59 61 1 61 59 29

first 27 61 59 61 1 61 59 29

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

space c8 is c1

5 c1 c8-d6 27 61 59 61 1 61 59 29

11011 111101 111011 111101 1 111101 111011 11101

5 one bits in var c1

11011 111101 1 111101 1 111101 111011 11101

q end c8-d6 27 61 1 61 1 61 59 29

bb end c8-d6 27 61 1 61 1 61 59 29

bw end c8-d6 27 61 1 61 1 61 59 29

firstr is a1, and lastr is h1

r c8-d6 27 61 1 61 1 61 59 29

first 27 61 1 61 1 61 59 29

11010 111100 1 111100 1 111100 111010 11100

q end c8-d6 26 60 1 60 1 60 58 28

bb end c8-d6 26 60 1 60 1 60 58 28

bw end c8-d6 26 60 1 60 1 60 58 28

firstr is a1, and lastr is h1

r c8-d6 26 60 1 60 1 60 58 28

first 26 60 1 60 1 60 58 28

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

space c1 is c1

6 c1 c1-d3 26 60 1 60 1 60 58 28

11010 111100 1 111100 1 111100 111010 11100

1 one bits in var c1

11010 111100 1 111100 1 111100 111010 11100

q end c1-d3 26 60 1 60 1 60 58 28

bb end c1-d3 26 60 1 60 1 60 58 28

bw end c1-d3 26 60 1 60 1 60 58 28

firstr is a1, and lastr is h1

r c1-d3 26 60 1 60 1 60 58 28

first 26 60 1 60 1 60 58 28

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

space g8 is g1

7 g1 g8-d5 26 60 1 60 1 60 58 28

11010 111100 1 111100 1 111100 111010 11100

4 one bits in var g1

11010 111100 1 111100 1 111100 10010 11100

q end g8-d5 26 60 1 60 1 60 18 28

bb end g8-d5 26 60 1 60 1 60 18 28

bw end g8-d5 26 60 1 60 1 60 18 28

firstr is a1, and lastr is h1

r g8-d5 26 60 1 60 1 60 18 28

first 26 60 1 60 1 60 18 28

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

space e2 is P

8 P e2-e3 26 60 1 60 1 60 18 28

11010 111100 1 111100 1 111100 10010 11100

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

space e7 is p

9 p e7-e6 26 60 1 60 1 60 18 28

11010 111100 1 111100 1 111100 10010 11100

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

space h4 is P

10 P h4-h5 26 60 1 60 1 60 18 28

11010 111100 1 111100 1 111100 10010 11100

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

space b8 is b1

11 b1 b8-b6 26 60 1 60 1 60 18 28

11010 111100 1 111100 1 111100 10010 11100

4 one bits in var b1

rook ride

b1 currently set to 60

b1 now set to 24

11010 11000 1 111100 1 111100 10010 11100

q end b8-b6 26 24 1 60 1 60 18 28

bb end b8-b6 26 24 1 60 1 60 18 28

bw end b8-b6 26 24 1 60 1 60 18 28

firstr is a1, and lastr is h1

r b8-b6 26 24 1 60 1 60 18 28

first 26 24 1 60 1 60 18 28

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

space h5 is P

12 P h5-h6 26 24 1 60 1 60 18 28

11010 11000 1 111100 1 111100 10010 11100

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

space g7 is p

13 p g7-g6 26 24 1 60 1 60 18 28

11010 11000 1 111100 1 111100 10010 11100

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

space d3 is c1

14 c1 d3-f4 26 24 1 60 1 60 18 28

11010 11000 1 111100 1 111100 10010 11100

1 one bits in var c1

11010 11000 1 111100 1 111100 10010 11100

q end d3-f4 26 24 1 60 1 60 18 28

bb end d3-f4 26 24 1 60 1 60 18 28

bw end d3-f4 26 24 1 60 1 60 18 28

firstr is a1, and lastr is h1

r d3-f4 26 24 1 60 1 60 18 28

first 26 24 1 60 1 60 18 28

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

space f6 is p

15 p f6-f5 26 24 1 60 1 60 18 28

11010 11000 1 111100 1 111100 10010 11100

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

space a1 is a1

16 a1 a1-h8 26 24 1 60 1 60 18 28

11010 11000 1 111100 1 111100 10010 11100

3 one bits in var a1

10010 11000 1 111100 1 111100 10010 11100

q end a1-h8 18 24 1 60 1 60 18 28

bb end a1-h8 18 24 1 60 1 60 18 28

bw end a1-h8 18 24 1 60 1 60 18 28

firstr is b1, and lastr is h1

r a1-h8 18 24 1 60 1 60 18 28

first 18 24 1 60 1 60 18 28

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

space f8 is f1

17 f1 f8-e7 18 24 1 60 1 60 18 28

10010 11000 1 111100 1 111100 10010 11100

4 one bits in var f1

10010 11000 1 111100 1 110100 10010 11100

q end f8-e7 18 24 1 60 1 52 18 28

bb end f8-e7 18 24 1 60 1 52 18 28

bw end f8-e7 18 24 1 60 1 52 18 28

firstr is b1, and lastr is h1

One Rook found

r f8-e7 18 24 1 60 1 52 18 8

first 18 24 1 60 1 52 18 8

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

space h8 is a1

18 a1 h8-h7 18 24 1 60 1 52 18 8

10010 11000 1 111100 1 110100 10010 1000

2 one bits in var a1

10000 11000 1 111100 1 110100 10010 1000

queen before h8-h7 16 24 1 60 1 52 18 8

queen after h8-h7 16 8 1 44 1 36 2 8

q end h8-h7 16 8 1 44 1 36 2 8

bb end h8-h7 16 8 1 44 1 36 2 8

bw end h8-h7 16 8 1 44 1 36 2 8

firstr is b1, and lastr is h1

Two rooks found.

r h8-h7 16 8 1 36 1 36 2 8

first 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

q end h8-h7 16 8 1 36 1 36 2 8

bb end h8-h7 16 8 1 36 1 36 2 8

bw end h8-h7 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space d6 is c1

19 c1 d6-f7 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var c1

10000 1000 1 100100 1 100100 10 1000

q end d6-f7 16 8 1 36 1 36 2 8

bb end d6-f7 16 8 1 36 1 36 2 8

bw end d6-f7 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space h7 is a1

20 a1 h7-g6 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end h7-g6 16 8 1 36 1 36 2 8

bb end h7-g6 16 8 1 36 1 36 2 8

bw end h7-g6 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space e6 is p

21 p e6-e5 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

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

space h6 is P

22 P h6-h7 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

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

space f7 is c1

23 c1 f7-h8 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var c1

10000 1000 1 100100 1 100100 10 1000

q end f7-h8 16 8 1 36 1 36 2 8

bb end f7-h8 16 8 1 36 1 36 2 8

bw end f7-h8 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space f4 is c1

24 c1 f4-d5 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var c1

10000 1000 1 100100 1 100100 10 1000

q end f4-d5 16 8 1 36 1 36 2 8

bb end f4-d5 16 8 1 36 1 36 2 8

bw end f4-d5 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space a8 is a1

25 a1 a8-d5 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end a8-d5 16 8 1 36 1 36 2 8

bb end a8-d5 16 8 1 36 1 36 2 8

bw end a8-d5 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space g6 is a1

26 a1 g6-g8 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end g6-g8 16 8 1 36 1 36 2 8

bb end g6-g8 16 8 1 36 1 36 2 8

bw end g6-g8 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space d5 is a1

27 a1 d5-d2 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end d5-d2 16 8 1 36 1 36 2 8

bb end d5-d2 16 8 1 36 1 36 2 8

bw end d5-d2 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space f3 is e1

28 e1 f3-d2 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var e1

10000 1000 1 100100 1 100100 10 1000

q end f3-d2 16 8 1 36 1 36 2 8

bb end f3-d2 16 8 1 36 1 36 2 8

bw end f3-d2 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space e8 is e1

29 e1 e8-f6 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var e1

10000 1000 1 100100 1 100100 10 1000

q end e8-f6 16 8 1 36 1 36 2 8

bb end e8-f6 16 8 1 36 1 36 2 8

bw end e8-f6 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space g8 is a1

30 a1 g8-h8 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end g8-h8 16 8 1 36 1 36 2 8

bb end g8-h8 16 8 1 36 1 36 2 8

bw end g8-h8 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space f5 is p

31 p f5-f4 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

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

space h8 is a1

32 a1 h8-g7 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

1 one bits in var a1

10000 1000 1 100100 1 100100 10 1000

q end h8-g7 16 8 1 36 1 36 2 8

bb end h8-g7 16 8 1 36 1 36 2 8

bw end h8-g7 16 8 1 36 1 36 2 8

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

b1 h1

first 16 8 1 36 1 36 2 8

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

space e7 is f1

33 f1 e7-e8 16 8 1 36 1 36 2 8

10000 1000 1 100100 1 100100 10 1000

2 one bits in var f1

10000 1000 1 100100 1 100000 10 1000

q end e7-e8 16 8 1 4 1 32 2 8

bb end e7-e8 16 8 1 4 1 32 2 8

bw end e7-e8 16 8 1 4 1 32 2 8

first 16 8 1 4 1 32 2 8

10000 1000 1 100 1 100000 10 1000

f1

Array
(
    [0] => a1
    [1] => b1
    [2] => c1
    [3] => d1
    [4] => e1
)

q end e7-e8 16 8 1 4 1 32 2 8

bb end e7-e8 16 8 1 4 1 32 2 8

bw end e7-e8 16 8 1 4 1 32 2 8

first 16 8 1 4 1 32 2 8

mv is h7-h8; Q-h8, p is h7-h8;, o is Q

space Q is

34 h7-h8; Q-h8 16 8 1 4 1 32 2 8

10000 1000 1 100 1 100000 10 1000

0 one bits in var

10000 1000 1 100 1 100000 10 1000

f1

Array
(
    [0] => a1
    [1] => b1
    [2] => c1
    [3] => d1
    [4] => e1
)

q end h7-h8; Q-h8 16 8 1 4 1 32 2 8

bb end h7-h8; Q-h8 16 8 1 4 1 32 2 8

bw end h7-h8; Q-h8 16 8 1 4 1 32 2 8

first 16 8 1 4 1 32 2 8

\count is 3

Syntax Error on line 977

The first argument to the move command, Q, is not a recognized coordinate.

Edit the Settings File for Fischer Random Chess

For the sake of debugging, here is the full GAME Code program that this error occurred in. The lines have been properly indented to help you spot scope errors.

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

functions

Array ( [N] => Array ( [0] => checkleap [1] => #0 [2] => #1 [3] => 1 [4] => 2 ) [B] => Array ( [0] => checkride [1] => #0 [2] => #1 [3] => 1 [4] => 1 ) [R] => Array ( [0] => checkride [1] => #0 [2] => #1 [3] => 1 [4] => 0 ) [Q] => Array ( [0] => fn [1] => B [2] => #0 [3] => #1 [4] => or [5] => fn [6] => R [7] => #0 [8] => #1 ) [K] => Array ( [0] => checkleap [1] => #0 [2] => #1 [3] => 1 [4] => 1 [5] => or [6] => checkleap [7] => #0 [8] => #1 [9] => 1 [10] => 0 ) [M] => Array ( [0] => fn [1] => N [2] => #0 [3] => #1 [4] => or [5] => fn [6] => R [7] => #0 [8] => #1 ) [A] => Array ( [0] => fn [1] => N [2] => #0 [3] => #1 [4] => or [5] => fn [6] => B [7] => #0 [8] => #1 ) [n] => Array ( [0] => checkleap [1] => #0 [2] => #1 [3] => 1 [4] => 2 ) [b] => Array ( [0] => checkride [1] => #0 [2] => #1 [3] => 1 [4] => 1 ) [r] => Array ( [0] => checkride [1] => #0 [2] => #1 [3] => 1 [4] => 0 ) [q] => Array ( [0] => fn [1] => b [2] => #0 [3] => #1 [4] => or [5] => fn [6] => r [7] => #0 [8] => #1 ) [k] => Array ( [0] => checkleap [1] => #0 [2] => #1 [3] => 1 [4] => 1 [5] => or [6] => checkleap [7] => #0 [8] => #1 [9] => 1 [10] => 0 ) [m] => Array ( [0] => fn [1] => n [2] => #0 [3] => #1 [4] => or [5] => fn [6] => r [7] => #0 [8] => #1 ) [a] => Array ( [0] => fn [1] => n [2] => #0 [3] => #1 [4] => or [5] => fn [6] => b [7] => #0 [8] => #1 ) [P] => Array ( [0] => remove [1] => var [2] => ep [3] => and [4] => checkleap [5] => #0 [6] => #1 [7] => 1 [8] => 1 [9] => and [10] => == [11] => var [12] => ep [13] => join [14] => filename [15] => #1 [16] => rankname [17] => #0 [18] => or [19] => and [20] => checkride [21] => #0 [22] => #1 [23] => 0 [24] => 1 [25] => == [26] => rankname [27] => #0 [28] => var [29] => wpr [30] => or [31] => checkleap [32] => #0 [33] => #1 [34] => 0 [35] => 1 [36] => and [37] => empty [38] => #1 [39] => or [40] => and [41] => islower [42] => space [43] => #1 [44] => checkleap [45] => #0 [46] => #1 [47] => 1 [48] => 1 [49] => and [50] => <= [51] => distance [52] => #0 [53] => #1 [54] => var [55] => fps [56] => and [57] => > [58] => rank [59] => #1 [60] => rank [61] => #0 ) [p] => Array ( [0] => remove [1] => var [2] => ep [3] => and [4] => checkleap [5] => #0 [6] => #1 [7] => 1 [8] => 1 [9] => and [10] => == [11] => var [12] => ep [13] => join [14] => filename [15] => #1 [16] => rankname [17] => #0 [18] => or [19] => and [20] => checkride [21] => #0 [22] => #1 [23] => 0 [24] => 1 [25] => == [26] => rankname [27] => #0 [28] => var [29] => bpr [30] => or [31] => checkleap [32] => #0 [33] => #1 [34] => 0 [35] => 1 [36] => and [37] => empty [38] => #1 [39] => or [40] => and [41] => isupper [42] => space [43] => #1 [44] => checkleap [45] => #0 [46] => #1 [47] => 1 [48] => 1 [49] => and [50] => <= [51] => distance [52] => #0 [53] => #1 [54] => var [55] => fps [56] => and [57] => < [58] => rank [59] => #1 [60] => rank [61] => #0 ) [PL] => Array ( [0] => array [1] => where [2] => #0 [3] => 0 [4] => 2 [5] => where [6] => #0 [7] => 0 [8] => 1 [9] => where [10] => #0 [11] => -1 [12] => 1 [13] => where [14] => #0 [15] => 1 [16] => 1 ) [pL] => Array ( [0] => array [1] => where [2] => #0 [3] => 0 [4] => -2 [5] => where [6] => #0 [7] => 0 [8] => -1 [9] => where [10] => #0 [11] => -1 [12] => -1 [13] => where [14] => #0 [15] => 1 [16] => -1 ) [NL] => Array ( [0] => leaps [1] => #0 [2] => 1 [3] => 2 ) [BL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 1 ) [RL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 0 ) [VL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 1 ) [CL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 0 ) [QL] => Array ( [0] => merge [1] => rays [2] => #0 [3] => 1 [4] => 0 [5] => rays [6] => #0 [7] => 1 [8] => 1 ) [KL] => Array ( [0] => merge [1] => leaps [2] => #0 [3] => 1 [4] => 0 [5] => leaps [6] => #0 [7] => 1 [8] => 1 ) [AL] => Array ( [0] => merge [1] => leaps [2] => #0 [3] => 1 [4] => 2 [5] => rays [6] => #0 [7] => 1 [8] => 1 ) [ML] => Array ( [0] => merge [1] => rays [2] => #0 [3] => 1 [4] => 0 [5] => leaps [6] => #0 [7] => 1 [8] => 2 ) [nL] => Array ( [0] => leaps [1] => #0 [2] => 1 [3] => 2 ) [bL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 1 ) [rL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 0 ) [vL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 1 ) [cL] => Array ( [0] => rays [1] => #0 [2] => 1 [3] => 0 ) [qL] => Array ( [0] => merge [1] => rays [2] => #0 [3] => 1 [4] => 0 [5] => rays [6] => #0 [7] => 1 [8] => 1 ) [kL] => Array ( [0] => merge [1] => leaps [2] => #0 [3] => 1 [4] => 0 [5] => leaps [6] => #0 [7] => 1 [8] => 1 ) [aL] => Array ( [0] => merge [1] => leaps [2] => #0 [3] => 1 [4] => 2 [5] => rays [6] => #0 [7] => 1 [8] => 1 ) [mL] => Array ( [0] => merge [1] => rays [2] => #0 [3] => 1 [4] => 0 [5] => leaps [6] => #0 [7] => 1 [8] => 2 ) [WPAWN] => Array ( [0] => match [1] => P [2] => what [3] => #0 [4] => 1 [5] => -1 [6] => what [7] => #0 [8] => -1 [9] => -1 ) [BPAWN] => Array ( [0] => match [1] => p [2] => what [3] => #0 [4] => 1 [5] => 1 [6] => what [7] => #0 [8] => -1 [9] => 1 ) [KNIGHT] => Array ( [0] => check [1] => what [2] => #0 [3] => 1 [4] => 2 [5] => check [6] => what [7] => #0 [8] => -1 [9] => 2 [10] => check [11] => what [12] => #0 [13] => 1 [14] => -2 [15] => check [16] => what [17] => #0 [18] => -1 [19] => -2 [20] => check [21] => what [22] => #0 [23] => 2 [24] => 1 [25] => check [26] => what [27] => #0 [28] => -2 [29] => 1 [30] => check [31] => what [32] => #0 [33] => 2 [34] => -1 [35] => check [36] => what [37] => #0 [38] => -2 [39] => -1 [40] => target [41] => #1 ) [WAZIR] => Array ( [0] => check [1] => what [2] => #0 [3] => 0 [4] => -1 [5] => check [6] => what [7] => #0 [8] => -1 [9] => 0 [10] => check [11] => what [12] => #0 [13] => 0 [14] => 1 [15] => check [16] => what [17] => #0 [18] => 1 [19] => 0 [20] => target [21] => #1 ) [FERZ] => Array ( [0] => check [1] => what [2] => #0 [3] => -1 [4] => -1 [5] => check [6] => what [7] => #0 [8] => -1 [9] => 1 [10] => check [11] => what [12] => #0 [13] => 1 [14] => -1 [15] => check [16] => what [17] => #0 [18] => 1 [19] => 1 [20] => target [21] => #1 ) [KING] => Array ( [0] => fn [1] => WAZIR [2] => #0 [3] => #1 [4] => or [5] => fn [6] => FERZ [7] => #0 [8] => #1 ) [ROOK] => Array ( [0] => check [1] => insight [2] => #0 [3] => 0 [4] => -1 [5] => check [6] => insight [7] => #0 [8] => -1 [9] => 0 [10] => check [11] => insight [12] => #0 [13] => 0 [14] => 1 [15] => check [16] => insight [17] => #0 [18] => 1 [19] => 0 [20] => target [21] => #1 ) [BISHOP] => Array ( [0] => check [1] => insight [2] => #0 [3] => -1 [4] => -1 [5] => check [6] => insight [7] => #0 [8] => -1 [9] => 1 [10] => check [11] => insight [12] => #0 [13] => 1 [14] => -1 [15] => check [16] => insight [17] => #0 [18] => 1 [19] => 1 [20] => target [21] => #1 ) [ATTACKEDBYB] => Array ( [0] => fn [1] => KING [2] => #0 [3] => k [4] => or [5] => fn [6] => BPAWN [7] => #0 [8] => or [9] => fn [10] => KNIGHT [11] => #0 [12] => Array ( [0] => n [1] => a [2] => m ) [13] => or [14] => fn [15] => ROOK [16] => #0 [17] => Array ( [0] => r [1] => q [2] => m ) [18] => or [19] => fn [20] => BISHOP [21] => #0 [22] => Array ( [0] => b [1] => q [2] => a ) ) [ATTACKEDBYW] => Array ( [0] => fn [1] => KING [2] => #0 [3] => K [4] => or [5] => fn [6] => WPAWN [7] => #0 [8] => or [9] => fn [10] => KNIGHT [11] => #0 [12] => Array ( [0] => N [1] => A [2] => M ) [13] => or [14] => fn [15] => ROOK [16] => #0 [17] => Array ( [0] => R [1] => Q [2] => M ) [18] => or [19] => fn [20] => BISHOP [21] => #0 [22] => Array ( [0] => B [1] => Q [2] => A ) ) [fn] => Array ( [0] => checkedfrom [1] => fn [2] => space [3] => #1 [4] => #0 [5] => and [6] => xor [7] => isupper [8] => space [9] => #0 [10] => isupper [11] => space [12] => #1 [13] => and [14] => not [15] => empty [16] => #1 ) )

uservar

Array ( [0] => Array ( [main] => Array ( [wpr] => 2 [bpr] => 7 [fps] => 2 [pzs] => 1 [wcastle] => Array ( [0] => g1 [1] => c1 ) [bcastle] => Array ( [0] => g8 [1] => c8 ) [wprom] => Array ( [0] => Q [1] => R [2] => B [3] => N ) [bprom] => Array ( [0] => q [1] => r [2] => b [3] => n ) [bw] => 4 [rank1] => Array ( [0] => a1 [1] => b1 [2] => c1 [3] => d1 [4] => e1 [5] => f1 [6] => g1 [7] => h1 ) [i] => 34 [normal] => 1 [mv] => h7-h8; Q-h8 [pm] => Array ( [0] => h7-h8; [1] => Q-h8 ) [m] => Q-h8 [od] => Array ( [0] => Q [1] => h8 ) [o] => Q [d] => h8 [pp] => [b2] => 10000 1000 1 100 1 100000 10 1000 [bp] => 0 [changed] => [rooks] => 2 [sp] => h1 [leftking] => [rghtking] => 32 [next] => [prev] => f1 [os] => 56 [betweenrooks] => Array ( [0] => c1 [1] => d1 [2] => e1 [3] => f1 [4] => g1 ) [ra2] => Array ( [0] => f1 ) [kp] => f1 [leftside] => Array ( [0] => a1 [1] => b1 [2] => c1 [3] => d1 [4] => e1 ) [rightside] => Array ( [0] => g1 [1] => h1 ) [p] => h7-h8; ) ) [2] => Array ( [calc_original_position] => Array ( [subargs] => Array ( ) ) [main] => Array ( [a1] => 16 [b1] => 8 [c1] => 1 [d1] => 4 [e1] => 1 [f1] => 32 [g1] => 2 [h1] => 8 [n] => 1 [bb] => 2 [w] => 0 [b] => 6 [r] => 8 [q] => 16 [k] => 32 [K] => 1 [Q] => 1 [R] => 2 [B] => 2 [N] => 2 [ra] => Array ( [0] => a1 [1] => b1 [2] => d1 [3] => f1 [4] => g1 [5] => h1 ) [firstr] => b1 [lastr] => h1 [last] => 2 ) ) )

mline

Array ( [0] => MoveLine Object ( [movenum] => 1 [move] => b2-b3 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 1 ) [1] => MoveLine Object ( [movenum] => 2 [move] => f7-f6 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 1 ) [2] => MoveLine Object ( [movenum] => 3 [move] => h2-h4 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 2 ) [3] => MoveLine Object ( [movenum] => 4 [move] => b7-b5 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 2 ) [4] => MoveLine Object ( [movenum] => 5 [move] => e1-f3 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 3 ) [5] => MoveLine Object ( [movenum] => 6 [move] => c8-d6 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 3 ) [6] => MoveLine Object ( [movenum] => 7 [move] => c1-d3 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 4 ) [7] => MoveLine Object ( [movenum] => 8 [move] => g8-d5 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 4 ) [8] => MoveLine Object ( [movenum] => 9 [move] => e2-e3 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 5 ) [9] => MoveLine Object ( [movenum] => 10 [move] => e7-e6 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 5 ) [10] => MoveLine Object ( [movenum] => 11 [move] => h4-h5 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 6 ) [11] => MoveLine Object ( [movenum] => 12 [move] => b8-b6 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 6 ) [12] => MoveLine Object ( [movenum] => 13 [move] => h5-h6 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 7 ) [13] => MoveLine Object ( [movenum] => 14 [move] => g7-g6 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 7 ) [14] => MoveLine Object ( [movenum] => 15 [move] => d3-f4 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 8 ) [15] => MoveLine Object ( [movenum] => 16 [move] => f6-f5 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 8 ) [16] => MoveLine Object ( [movenum] => 17 [move] => a1-h8 [level] => 0 [comment] => [length] => 8 [newturn] => 1 [turn] => 9 ) [17] => MoveLine Object ( [movenum] => 18 [move] => f8-e7 [level] => 0 [comment] => [length] => 10 [newturn] => [turn] => 9 ) [18] => MoveLine Object ( [movenum] => 19 [move] => h8-h7 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 10 ) [19] => MoveLine Object ( [movenum] => 20 [move] => d6-f7 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 10 ) [20] => MoveLine Object ( [movenum] => 21 [move] => h7-g6 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 11 ) [21] => MoveLine Object ( [movenum] => 22 [move] => e6-e5 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 11 ) [22] => MoveLine Object ( [movenum] => 23 [move] => h6-h7 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 12 ) [23] => MoveLine Object ( [movenum] => 24 [move] => f7-h8 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 12 ) [24] => MoveLine Object ( [movenum] => 25 [move] => f4-d5 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 13 ) [25] => MoveLine Object ( [movenum] => 26 [move] => a8-d5 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 13 ) [26] => MoveLine Object ( [movenum] => 27 [move] => g6-g8 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 14 ) [27] => MoveLine Object ( [movenum] => 28 [move] => d5-d2 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 14 ) [28] => MoveLine Object ( [movenum] => 29 [move] => f3-d2 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 15 ) [29] => MoveLine Object ( [movenum] => 30 [move] => e8-f6 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 15 ) [30] => MoveLine Object ( [movenum] => 31 [move] => g8-h8 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 16 ) [31] => MoveLine Object ( [movenum] => 32 [move] => f5-f4 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 16 ) [32] => MoveLine Object ( [movenum] => 33 [move] => h8-g7 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 17 ) [33] => MoveLine Object ( [movenum] => 34 [move] => e7-e8 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 17 ) [34] => MoveLine Object ( [movenum] => 35 [move] => h7-h8; Q-h8 [level] => 0 [comment] => [length] => 15 [newturn] => 1 [turn] => 18 ) [35] => MoveLine Object ( [movenum] => 36 [move] => f6-g8 [level] => 0 [comment] => [length] => 11 [newturn] => [turn] => 18 ) [36] => MoveLine Object ( [movenum] => 37 [move] => h8-g8 [level] => 0 [comment] => [length] => 9 [newturn] => 1 [turn] => 19 ) )

allmoves

Array ( [0] => moveindex 36;MOVE: h8-g8;postauto1 [1] => moveindex 35;MOVE: f6-g8;postauto2 [2] => moveindex 34;MOVE: h7-h8; MOVE: Q-h8;postauto1 [3] => moveindex 33;MOVE: e7-e8;postauto2 [4] => moveindex 32;MOVE: h8-g7;postauto1 [5] => moveindex 31;MOVE: f5-f4;postauto2 [6] => moveindex 30;MOVE: g8-h8;postauto1 [7] => moveindex 29;MOVE: e8-f6;postauto2 [8] => moveindex 28;MOVE: f3-d2;postauto1 [9] => moveindex 27;MOVE: d5-d2;postauto2 [10] => moveindex 26;MOVE: g6-g8;postauto1 [11] => moveindex 25;MOVE: a8-d5;postauto2 [12] => moveindex 24;MOVE: f4-d5;postauto1 [13] => moveindex 23;MOVE: f7-h8;postauto2 [14] => moveindex 22;MOVE: h6-h7;postauto1 [15] => moveindex 21;MOVE: e6-e5;postauto2 [16] => moveindex 20;MOVE: h7-g6;postauto1 [17] => moveindex 19;MOVE: d6-f7;postauto2 [18] => moveindex 18;MOVE: h8-h7;postauto1 [19] => moveindex 17;MOVE: f8-e7;postauto2 [20] => moveindex 16;MOVE: a1-h8;postauto1 [21] => moveindex 15;MOVE: f6-f5;postauto2 [22] => moveindex 14;MOVE: d3-f4;postauto1 [23] => moveindex 13;MOVE: g7-g6;postauto2 [24] => moveindex 12;MOVE: h5-h6;postauto1 [25] => moveindex 11;MOVE: b8-b6;postauto2 [26] => moveindex 10;MOVE: h4-h5;postauto1 [27] => moveindex 9;MOVE: e7-e6;postauto2 [28] => moveindex 8;MOVE: e2-e3;postauto1 [29] => moveindex 7;MOVE: g8-d5;postauto2 [30] => moveindex 6;MOVE: c1-d3;postauto1 [31] => moveindex 5;MOVE: c8-d6;postauto2 [32] => moveindex 4;MOVE: e1-f3;postauto1 [33] => moveindex 3;MOVE: b7-b5;postauto2 [34] => moveindex 2;MOVE: h2-h4;postauto1 [35] => moveindex 1;MOVE: f7-f6;postauto2 [36] => moveindex 0;MOVE: b2-b3;postauto1 )

movelist

1. b2-b3 1... f7-f6 2. h2-h4 2... b7-b5 3. e1-f3 3... c8-d6 4. c1-d3 4... g8-d5 5. e2-e3 5... e7-e6 6. h4-h5 6... b8-b6 7. h5-h6 7... g7-g6 8. d3-f4 8... f6-f5 9. a1-h8 9... f8-e7 10. h8-h7 10... d6-f7 11. h7-g6 11... e6-e5 12. h6-h7 12... f7-h8 13. f4-d5 13... a8-d5 14. g6-g8 14... d5-d2 15. f3-d2 15... e8-f6 16. g8-h8 16... f5-f4 17. h8-g7 17... e7-e8 18. h7-h8; Q-h8 18... f6-g8 19. h8-g8

constants

Array ( )