85

BANNED INPUT: e4-f6;won on turn 43:

There is a global ban on commands in user input, and no exception has been made for the won command on the part of the turn indexed 2.

Go back and try again.

What is otherwise valid user input in Game Courier can be banned in a GAME Code program for the sake of better enforcing the rules. See "Restricting User Input" in the Game Courier Developer's Guide for details on how this is done.

If you believe that your input should not have been banned, contact Fergus Duniho or whoever programmed the rules for this game.

Edit Settings File
   0 set k findpiece k spaces
   1 set K findpiece K spaces
   2 set ep false
   3 set cap assoc r 0 b 0 n 0 m 0 a 0 q 0
   4 set CAP assoc R 0 B 0 N 0 M 0 A 0 Q 0
   5 alias c a C A
   6 include grandchess
   7 sub postauto1
   8   if isupper old
   9     die You may not capture your own pieces.
  10   endif
  11   if not equal moved P
  12     set ep false
  13     if unequal space dest moved
  14       die You may not change the type of this piece.
  15     endif
  16   endif
  17   set legal false
  18   if == moved P
  19     gosub P origin dest
  20   elseif match moved K Q M A R B N
  21     set legal fn moved origin dest
  22     if equal moved K
  23       set K dest
  24     endif
  25   endif
  26   if not var legal
  27     die You may not move a moved from origin to dest
  28   endif
  29   if fn ATTACKEDBYB #K
  30     die You may not move into check.
  31   endif
  32   if match old r b n m a q
  33     setelem cap old inc elem old cap
  34   endif
  35 endsub
  36 sub postauto2
  37   if islower old
  38     die You may not capture your own pieces.
  39   endif
  40   if not equal moved p
  41     set ep false
  42     if unequal space dest moved
  43       die You may not change the type of this piece.
  44     endif
  45   endif
  46   set legal false
  47   if == moved p
  48     gosub p origin dest
  49   elseif match moved k q m a r b n
  50     set legal fn toupper moved origin dest
  51     if == moved k
  52       set k dest
  53     endif
  54   endif
  55   if not var legal
  56     die You may not move a moved from origin to dest
  57   endif
  58   if fn ATTACKEDBYW #k
  59     die You may not move into check.
  60   endif
  61   if match old R B N M A Q
  62     setelem CAP old inc elem old CAP
  63   endif
  64 endsub
  65 moveindex 0
  66 MOVE: h3-h5
  67 postauto1
  68 moveindex 1
  69 MOVE: g8-g7
  70 postauto2
  71 moveindex 2
  72 MOVE: c3-c4
  73 postauto1
  74 moveindex 3
  75 MOVE: e8-e7
  76 postauto2
  77 moveindex 4
  78 MOVE: i3-i4
  79 postauto1
  80 moveindex 5
  81 MOVE: b8-b7
  82 postauto2
  83 moveindex 6
  84 MOVE: i2-h4
  85 postauto1
  86 moveindex 7
  87 MOVE: h9-e6
  88 postauto2
  89 moveindex 8
  90 MOVE: f3-f5
  91 postauto1
  92 moveindex 9
  93 MOVE: e6-d7
  94 postauto2
  95 moveindex 10
  96 MOVE: e3-e5
  97 postauto1
  98 moveindex 11
  99 MOVE: b9-c7
 100 postauto2
 101 moveindex 12
 102 MOVE: b3-b5
 103 postauto1
 104 moveindex 13
 105 MOVE: a8-a6
 106 postauto2
 107 moveindex 14
 108 MOVE: b5-b6
 109 postauto1
 110 moveindex 15
 111 MOVE: c7-a8
 112 postauto2
 113 moveindex 16
 114 MOVE: a3-a5
 115 postauto1
 116 moveindex 17
 117 MOVE: c9-b8
 118 postauto2
 119 moveindex 18
 120 MOVE: g3-g4
 121 postauto1
 122 moveindex 19
 123 MOVE: h8-h7
 124 postauto2
 125 moveindex 20
 126 MOVE: h2-f4
 127 postauto1
 128 moveindex 21
 129 MOVE: i8-i7
 130 postauto2
 131 moveindex 22
 132 MOVE: e5-e6
 133 postauto1
 134 moveindex 23
 135 MOVE: b8-f4
 136 postauto2
 137 moveindex 24
 138 MOVE: g2-f4
 139 postauto1
 140 moveindex 25
 141 MOVE: d7-c6
 142 postauto2
 143 moveindex 26
 144 MOVE: d3-d5
 145 postauto1
 146 moveindex 27
 147 MOVE: c6-e8
 148 postauto2
 149 moveindex 28
 150 MOVE: f4-b8
 151 postauto1
 152 moveindex 29
 153 MOVE: d9-b9
 154 postauto2
 155 moveindex 30
 156 MOVE: b8-a7
 157 postauto1
 158 moveindex 31
 159 MOVE: b9-c10
 160 postauto2
 161 moveindex 32
 162 MOVE: c2-a4
 163 postauto1
 164 moveindex 33
 165 MOVE: e8-a4
 166 postauto2
 167 moveindex 34
 168 MOVE: b2-a4
 169 postauto1
 170 moveindex 35
 171 MOVE: a8-b10
 172 postauto2
 173 moveindex 36
 174 MOVE: d2-f4
 175 postauto1
 176 moveindex 37
 177 MOVE: a10-a7
 178 postauto2
 179 moveindex 38
 180 MOVE: b6-a7
 181 postauto1
 182 moveindex 39
 183 MOVE: c10-a8
 184 postauto2
 185 moveindex 40
 186 MOVE: f4-b8
 187 postauto1
 188 moveindex 41
 189 MOVE: c8-c7
 190 postauto2
 191 moveindex 42
 192 MOVE: b8-a8
 193 postauto1
 194 moveindex 43
 195 MOVE: b10-a8
 196 postauto2
 197 moveindex 44
 198 MOVE: c4-c5
 199 postauto1
 200 moveindex 45
 201 MOVE: g9-e8
 202 postauto2
 203 moveindex 46
 204 MOVE: a4-b6
 205 postauto1
 206 moveindex 47
 207 MOVE: c7-b6
 208 postauto2
 209 moveindex 48
 210 MOVE: a5-b6
 211 postauto1
 212 moveindex 49
 213 MOVE: e8-b5
 214 postauto2
 215 moveindex 50
 216 MOVE: f2-d3
 217 postauto1
 218 moveindex 51
 219 MOVE: j10-b10
 220 postauto2
 221 moveindex 52
 222 MOVE: j1-b1
 223 postauto1
 224 moveindex 53
 225 MOVE: b5-d3
 226 postauto2
 227 moveindex 54
 228 MOVE: e2-d3
 229 postauto1
 230 moveindex 55
 231 MOVE: e9-e8
 232 postauto2
 233 moveindex 56
 234 MOVE: g4-g5
 235 postauto1
 236 moveindex 57
 237 MOVE: j8-j7
 238 postauto2
 239 moveindex 58
 240 MOVE: h4-f3
 241 postauto1
 242 moveindex 59
 243 MOVE: i9-g8
 244 postauto2
 245 moveindex 60
 246 MOVE: f3-e5
 247 postauto1
 248 moveindex 61
 249 MOVE: f9-c9
 250 postauto2
 251 moveindex 62
 252 MOVE: e5-d7
 253 postauto1
 254 moveindex 63
 255 MOVE: c9-c8
 256 postauto2
 257 moveindex 64
 258 MOVE: d3-d4
 259 postauto1
 260 moveindex 65
 261 MOVE: g8-e9
 262 postauto2
 263 moveindex 66
 264 MOVE: d7-b8
 265 postauto1
 266 moveindex 67
 267 MOVE: d8-d7
 268 postauto2
 269 moveindex 68
 270 MOVE: b8-a6
 271 postauto1
 272 moveindex 69
 273 MOVE: c8-c9
 274 postauto2
 275 moveindex 70
 276 MOVE: b1-b5
 277 postauto1
 278 moveindex 71
 279 MOVE: e9-c8
 280 postauto2
 281 moveindex 72
 282 MOVE: e6-d7
 283 postauto1
 284 moveindex 73
 285 MOVE: e8-d7
 286 postauto2
 287 moveindex 74
 288 MOVE: a6-b8
 289 postauto1
 290 moveindex 75
 291 MOVE: d7-d8
 292 postauto2
 293 moveindex 76
 294 MOVE: g5-g6
 295 postauto1
 296 moveindex 77
 297 MOVE: h7-h6
 298 postauto2
 299 moveindex 78
 300 MOVE: d4-e5
 301 postauto1
 302 moveindex 79
 303 MOVE: c8-b6
 304 postauto2
 305 moveindex 80
 306 MOVE: c5-b6
 307 postauto1
 308 moveindex 81
 309 MOVE: c9-c4
 310 postauto2
 311 moveindex 82
 312 MOVE: e5-e6
 313 postauto1
 314 moveindex 83
 315 MOVE: c4-e4
 316 postauto2
 317 moveindex 84
 318 MOVE: e6-f7
 319 postauto1
 320 moveindex 85
 321 MOVE: e4-f6
 322 MOVE: won
 323 postauto2
 324 set checks sub checks #K
 325 if var checks
 326   if sub checkmated #K #checks
 327     say Checkmate! Black has won!
 328     won
 329   else
 330     say Check!
 331   endif
 332 elseif sub stalemated #K
 333   say Stalemate! The game is drawn.
 334   drawn
 335 endif
 336 end
 337 
 338 lib grandchess
 339 include chess
 340 set wpr 3
 341 set bpr 8
 342 set pzs 3
 343 sub P from to
 344   local ydir
 345   if == file #from file #to and not capture
 346     set legal checkaleap #from #to 0 1
 347     if var legal
 348       set ep false
 349     else
 350       set legal checkatwostep #from #to 0 1 0 1 and == rankname #from 3
 351       set ep #to
 352     endif
 353     set epc false
 354   elseif capture or #ep
 355     set legal checkaleap #from #to -1 1 or checkaleap #from #to 1 1
 356     set epc false
 357     if not capture and var legal
 358       set legal == #ep where #to 0 -1
 359       if var legal
 360         capture #ep
 361         set epc #ep
 362       endif
 363     endif
 364     set ep false
 365   endif
 366   set pp space #to
 367   if onboard where #to 0 #pzs
 368     if != #pp moved
 369       die "You may not promote a Pawn until it reaches the last" #pzs "ranks."
 370     endif
 371   elseif == 1 count explode chr 59 thismove
 372     set wprom ()
 373     foreach (key val) var CAP
 374       if > var val 0
 375         push wprom var key
 376       endif
 377     next
 378     if == count var wprom 0 and not onboard where #to 0 1
 379       die You may not move a Pawn to the last rank without a captured piece to promote it to.
 380     elseif > count var wprom 0 and onboard where #to 0 1
 381       push wprom P
 382     endif
 383     if > count var wprom 1
 384       askpromote #wprom
 385     elseif == count var wprom 1
 386       set np elem 0 wprom
 387       set newmove join var np "-dest"
 388       appendmove #newmove
 389       add #np dest
 390     endif
 391   elseif < elem #pp CAP 1 and != #pp P
 392     die "You may not promote a Pawn to a" #pp "until one has been captured."
 393   else
 394     echo #pp
 395     setelem CAP #pp dec elem #pp CAP
 396   endif
 397 endsub
 398 sub p from to
 399   if == file #from file #to and not capture
 400     set legal checkaleap #from #to 0 -1
 401     if var legal
 402       set ep false
 403     else
 404       set legal checkatwostep #from #to 0 -1 0 -1 and == rankname #from 8
 405       set ep #to
 406     endif
 407     set epc false
 408   elseif capture or #ep
 409     set legal checkaleap #from #to -1 -1 or checkaleap #from #to 1 -1
 410     set epc false
 411     if not capture and var legal
 412       set legal == #ep where #to 0 1
 413       if var legal
 414         capture #ep
 415         set epc #ep
 416       endif
 417     endif
 418     set ep false
 419   endif
 420   set pp space #to
 421   if onboard where #to 0 neg #pzs
 422     if != #pp moved
 423       die "You may not promote a Pawn until it reaches the last" #pzs "ranks."
 424     endif
 425   elseif == 1 count explode chr 59 thismove
 426     set bprom ()
 427     foreach (key val) var cap
 428       if > var val 0
 429         push bprom var key
 430       endif
 431     next
 432     if == count var bprom 0 and not onboard where #to 0 -1
 433       die You may not move a Pawn to the last rank without a captured piece to promote it to.
 434     elseif > count var bprom 0 and onboard where #to 0 -1
 435       push bprom p
 436     endif
 437     if > count var bprom 1
 438       askpromote #bprom
 439     elseif == count var bprom 1
 440       set np elem 0 bprom
 441       set newmove join var np "-dest"
 442       appendmove #newmove
 443       add #np dest
 444     endif
 445   elseif < elem #pp cap 1 and != #pp p
 446     die "You may not promote a Pawn to a" #pp "until one has been captured."
 447   else
 448     setelem cap #pp dec elem #pp cap
 449   endif
 450 endsub
 451 def ATTACKEDBYB fn KING #0 k or fn BPAWN #0 or fn KNIGHT #0 (n m a) or fn ROOK #0 (r q m) or fn BISHOP #0 (b q a)
 452 def ATTACKEDBYW fn KING #0 K or fn WPAWN #0 or fn KNIGHT #0 (N M A) or fn ROOK #0 (R Q M) or fn BISHOP #0 (B Q A)
 453 endlib
 454 lib chess
 455 set wpr 2
 456 set bpr 7
 457 set fps 2
 458 set pzs 1
 459 set wcastle c1 g1
 460 set bcastle c8 g8
 461 do
 462   local x
 463   for x piecekeys
 464     if match #x P K p k
 465       continue
 466     elseif isupper #x
 467       push wprom #x
 468     elseif islower #x
 469       push bprom #x
 470     endif
 471   next
 472 loop never
 473 setsystem maxmove 2
 474 ban commands allmoves
 475 allow moves 1 captures 1 promotions 2
 476 def N checkleap #0 #1 1 2
 477 def B checkride #0 #1 1 1
 478 def R checkride #0 #1 1 0
 479 def Q fn B #0 #1 or fn R #0 #1
 480 def K checkleap #0 #1 1 1 or checkleap #0 #1 1 0
 481 def M fn N #0 #1 or fn R #0 #1
 482 def A fn N #0 #1 or fn B #0 #1
 483 def n checkleap #0 #1 1 2
 484 def b checkride #0 #1 1 1
 485 def r checkride #0 #1 1 0
 486 def q fn b #0 #1 or fn r #0 #1
 487 def k checkleap #0 #1 1 1 or checkleap #0 #1 1 0
 488 def m fn n #0 #1 or fn r #0 #1
 489 def a fn n #0 #1 or fn b #0 #1
 490 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
 491 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
 492 sub capturep p
 493   empty #p
 494   return true
 495 endsub
 496 sub checks king
 497   if not dest
 498     return false
 499   endif
 500   my checks c
 501   set checks ()
 502   if fn space dest dest #king
 503     setelem checks dest space dest
 504   endif
 505   set c sub checkedthru #king origin
 506   if #c
 507     setelem checks #c space #c
 508   elseif #epc
 509     set c sub checkedthru #king #epc
 510     if #c
 511       setelem checks #c space #c
 512     endif
 513   endif
 514   return var checks
 515 endsub
 516 sub checkmated king checks
 517   local from piece to key legalmove piece nopawn
 518   store
 519   if isupper space #king
 520     def friends onlyupper
 521     def friend isupper #0
 522     set attacked ATTACKEDBYB
 523   else
 524     def friends onlylower
 525     def friend islower #0
 526     set attacked ATTACKEDBYW
 527   endif
 528   set kingmoves fn KL #king
 529   for to #kingmoves
 530     if not fn friend space #to and onboard #to
 531       move #king #to
 532       set incheck fn var attacked #to
 533       restore
 534       if not #incheck
 535         setlegal #king #to
 536       endif
 537     endif
 538   next
 539   if == count var checks 1
 540     for (key enemy) var checks
 541       set possible path #king #key
 542       push possible #key
 543       if == #key #ep
 544         push possible cond isupper space #ep where #ep 0 -1 where #ep 0 1
 545       endif
 546       for (from piece) fn friends
 547         if == #from #king
 548           continue
 549         endif
 550         for to #possible
 551           if fn #piece #from #to
 552             move #from #to
 553             set incheck fn var attacked #king
 554             if not #incheck
 555               setlegal #from #to
 556             endif
 557           endif
 558           restore
 559         next
 560       next
 561     next
 562   endif
 563   return cond count system legalmoves false true and checks
 564 endsub
 565 def PL array where #0 0 2 where #0 0 1 where #0 -1 1 where #0 1 1
 566 def pL array where #0 0 -2 where #0 0 -1 where #0 -1 -1 where #0 1 -1
 567 def NL leaps #0 1 2
 568 def BL rays #0 1 1
 569 def RL rays #0 1 0
 570 def VL rays #0 1 1
 571 def CL rays #0 1 0
 572 def QL merge rays #0 1 0 rays #0 1 1
 573 def KL merge leaps #0 1 0 leaps #0 1 1
 574 def AL merge leaps #0 1 2 rays #0 1 1
 575 def ML merge rays #0 1 0 leaps #0 1 2
 576 def nL leaps #0 1 2
 577 def bL rays #0 1 1
 578 def rL rays #0 1 0
 579 def vL rays #0 1 1
 580 def cL rays #0 1 0
 581 def qL merge rays #0 1 0 rays #0 1 1
 582 def kL merge leaps #0 1 0 leaps #0 1 1
 583 def aL merge leaps #0 1 2 rays #0 1 1
 584 def mL merge rays #0 1 0 leaps #0 1 2
 585 sub castlepos from to
 586   local c RPOS RDEST xdir safe
 587   verify flag #from
 588   verify empty #to
 589   if isupper space #king
 590     def friend isupper #0
 591     def friends onlyupper
 592     set attacked ATTACKEDBYB
 593   else
 594     def friend islower #0
 595     def friends onlylower
 596     set attacked ATTACKEDBYW
 597   endif
 598   set xdir sign minus file #to file #from
 599   verify checkaride #from #to #xdir 0
 600   verify not fn var attacked #from
 601   set c #to
 602   do
 603     set c where #c #xdir 0
 604     if flag #c
 605       break
 606     endif
 607     verify onboard #c
 608     verify empty #c
 609   loop
 610   verify flag #c
 611   set RPOS #c
 612   store
 613   for c path #from #to
 614     move #from #c
 615     set safe not fn var attacked #c
 616     restore
 617     verify #safe
 618   next
 619   move #from #to
 620   set RDEST where #to neg #xdir 0
 621   move #RPOS #RDEST
 622   return true
 623 endsub
 624 sub stalemated king
 625   local legalmove temp from piece to attacked ra
 626   if isupper space #king
 627     def friend isupper #0
 628     def friends onlyupper
 629     set attacked ATTACKEDBYB
 630     set cspaces var wcastle
 631   else
 632     def friend islower #0
 633     def friends onlylower
 634     set attacked ATTACKEDBYW
 635     set cspaces var bcastle
 636   endif
 637   store
 638   set kingmoves fn KL #king
 639   for to #kingmoves
 640     if not fn friend space #to and onboard #to
 641       move #king #to
 642       set incheck fn var attacked #to
 643       restore
 644       if not #incheck
 645         setlegal #king #to
 646       endif
 647     endif
 648   next
 649   for to var cspaces
 650     if sub castlepos #king #to
 651       set incheck fn var attacked #to
 652       restore
 653       if not #incheck
 654         setlegal #king #to
 655       endif
 656     endif
 657   next
 658   restore
 659   for (from piece) fn friends
 660     if == #from #king
 661       continue
 662     endif
 663     for to fn join #piece L #from
 664       if fn #piece #from #to and not fn friend space #to and onboard #to
 665         move #from #to
 666         set incheck fn var attacked #king
 667         if not #incheck
 668           setlegal #from #to
 669         endif
 670       endif
 671       restore
 672     next
 673   next
 674   return cond count system legalmoves false true
 675 endsub
 676 def WPAWN match P what #0 1 -1 what #0 -1 -1
 677 def BPAWN match p what #0 1 1 what #0 -1 1
 678 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
 679 def WAZIR check what #0 0 -1 check what #0 -1 0 check what #0 0 1 check what #0 1 0 target #1
 680 def FERZ check what #0 -1 -1 check what #0 -1 1 check what #0 1 -1 check what #0 1 1 target #1
 681 def KING fn WAZIR #0 #1 or fn FERZ #0 #1
 682 def ROOK check insight #0 0 -1 check insight #0 -1 0 check insight #0 0 1 check insight #0 1 0 target #1
 683 def BISHOP check insight #0 -1 -1 check insight #0 -1 1 check insight #0 1 -1 check insight #0 1 1 target #1
 684 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)
 685 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)
 686 sub P from to
 687   local ydir
 688   if == file #from file #to and not capture
 689     set legal checkaleap #from #to 0 1
 690     if var legal
 691       set ep false
 692     else
 693       set legal checkaride #from #to 0 1 and <= distance #from #to #fps and or == rankname #from #wpr < #wpr 0
 694       set ep #to
 695     endif
 696     set epc false
 697   elseif capture or #ep
 698     set legal checkaleap #from #to -1 1 or checkaleap #from #to 1 1
 699     set epc false
 700     if not capture and var legal
 701       set legal > rank #to rank #ep and < rankname #to #bpr and == file #to file #ep
 702       if var legal
 703         capture #ep
 704         set epc #ep
 705       endif
 706     endif
 707     set ep false
 708   endif
 709   if != space #to moved and onboard where #to 0 #pzs
 710     die "You may not promote a Pawn until it reaches the promotion zone."
 711   endif
 712   if not onboard where #to 0 1
 713     if == P space #to
 714       askpromote #wprom
 715     elseif not match space #to var wprom
 716       set np space #to
 717       die "You may not promote your Pawn to a" #np
 718     endif
 719   endif
 720 endsub
 721 sub p from to
 722   if == file #from file #to and not capture
 723     set legal checkaleap #from #to 0 -1
 724     if var legal
 725       set ep false
 726     else
 727       set legal checkaride #from #to 0 -1 and <= distance #from #to #fps and or == rankname #from #bpr > #bpr lastrank
 728       set ep #to
 729     endif
 730     set epc false
 731   elseif capture or #ep
 732     set legal checkaleap #from #to -1 -1 or checkaleap #from #to 1 -1
 733     set epc false
 734     if not capture and var legal
 735       set legal < rank #to rank #ep and > rankname #to #wpr and == file #to file #ep
 736       if var legal
 737         capture #ep
 738         set epc #ep
 739       endif
 740     endif
 741     set ep false
 742   endif
 743   if != space #to moved and onboard where #to 0 neg #pzs
 744     die You may not promote a Pawn until it reaches the promotion zone.
 745   endif
 746   if not onboard where #to 0 -1
 747     if == p space #to
 748       askpromote #bprom
 749     elseif not match space #to var bprom
 750       set np space #to
 751       die You may not promote your Pawn to a #np
 752     endif
 753   endif
 754 endsub
 755 sub K from to
 756   if match #to var wcastle and flag #from
 757     set legal sub castle
 758   else
 759     set legal fn K #from #to
 760   endif
 761   set K #to
 762   unsetflag e1
 763 endsub
 764 sub k from to
 765   if match #to var bcastle and flag #from
 766     set legal sub castle
 767   else
 768     set legal fn k #from #to
 769   endif
 770   set k #to
 771   unsetflag e8
 772 endsub
 773 sub castle
 774   local ATTACKED c RPOS RDEST xdir
 775   if not flag #from
 776     die A King may not castle after it moves.
 777   endif
 778   if capture
 779     die A King may not castle to an occupied space.
 780   endif
 781   set xdir sign minus file #to file #from
 782   if not checkaride #from #to #xdir 0
 783     die A King may not castle across any occupied space.
 784   endif
 785   set c #to
 786   do
 787     set c where #c #xdir 0
 788     if flag #c
 789       break
 790     elseif not onboard #c
 791       die No piece was found to castle with.
 792     elseif not empty #c
 793       die The King cannot castle with the piece at #c
 794     endif
 795   loop
 796   set RPOS #c
 797   set ATTACKED ATTACKEDBYW unless isupper moved ATTACKEDBYB
 798   if fn var ATTACKED #from
 799     die A King may not castle out of check.
 800   endif
 801   for c path #from #to
 802     if fn var ATTACKED #c
 803       die A King may not castle through check.
 804     endif
 805   next
 806   if == count var subargs 0
 807     set RDEST where #to neg #xdir 0
 808   else
 809     set RDEST elem 0 subarg
 810   endif
 811   unsetflag #RPOS
 812   move #RPOS #RDEST
 813   return true
 814 endsub
 815 sub checkedthru king loc
 816   my dir c
 817   set c revealed #king #loc
 818   verify fn space #c #c #king and not samecase space #king space #c and onboard #c and #c
 819   return #c
 820 endsub
 821 def fn checkedfrom fn space #1 #0 and xor isupper space #0 isupper space #1 and not empty #1
 822 sub P1 from to
 823   if == file #from file #to
 824     return not capture
 825   elseif capture
 826     return true
 827   elseif == file #to file #ep and == rank #from rank #ep and #ep
 828     capture #ep
 829     return true
 830   endif
 831   return false
 832 endsub
 833 sub PP from to
 834   if checkatwostep #from #to 0 1 0 1 or checkaleap #from #to 0 1
 835     return empty #to
 836   elseif not checkaleap #from #to 1 1 and not checkaleap #from #to -1 1
 837     return false
 838   elseif not empty #to
 839     return true
 840   elseif == file #to file #ep and == rank #from rank #ep and #ep
 841     capture #ep
 842     return true
 843   endif
 844   return false
 845 endsub
 846 sub pp from to
 847   if checkatwostep #from #to 0 -1 0 -1 or checkaleap #from #to 0 -1
 848     return empty #to
 849   elseif not checkaleap #from #to 1 -1 and not checkaleap #from #to -1 -1
 850     return false
 851   elseif not empty #to
 852     return true
 853   elseif == file #to file #ep and == rank #from rank #ep and #ep
 854     capture #ep
 855     return true
 856   endif
 857   return false
 858 endsub
 859 endlib