This preset for Takeover Chess should enforce rules and spot check, checkmate, and stalemate.

16

BANNED INPUT: resigns on turn 9:

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

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 echo This preset for Takeover Chess should enforce rules and spot check, checkmate, and stalemate.
   1 set k e8
   2 set K e1
   3 set ep null
   4 setflag a1 a8 h1 h8 e1 e8
   5 include takeover
   6 alias M Z m z
   7 sub postauto1
   8   if isupper old
   9     die You may not capture your own pieces.
  10   endif
  11   set screen null
  12   if or checkhop origin dest 1 0 checkhop origin dest 1 1
  13     set screen screen
  14   endif
  15   if equal moved N
  16     set screen where dest cmp file origin file dest cmp rank origin rank dest
  17   endif
  18   if equal moved Z
  19     set screen where origin cmp file dest file origin cmp rank dest rank origin
  20   endif
  21   if not equal moved P
  22     set ep false
  23     if unequal space dest moved
  24       die You may not change the type of this piece.
  25     endif
  26   endif
  27   set legal false
  28   if match moved P K
  29     gosub moved origin dest
  30     if equal moved K
  31       set K dest
  32     endif
  33   elseif match moved Q R B N Z
  34     set legal fn moved origin dest or fn join moved H origin dest
  35     if equal moved R
  36       unsetflag origin
  37     endif
  38   endif
  39   if not var legal
  40     die You may not move a moved from origin to dest
  41   endif
  42   if match space #screen q r b n z p
  43     flip #screen
  44   endif
  45   if sub checked #K
  46     die You may not move into check.
  47   endif
  48 endsub
  49 sub postauto2
  50   if islower old
  51     die you may not capture your own pieces.
  52   endif
  53   set screen null
  54   if or checkhop origin dest 1 0 checkhop origin dest 1 1
  55     set screen screen
  56   endif
  57   if equal moved n
  58     set screen where dest cmp file origin file dest cmp rank origin rank dest
  59   endif
  60   if equal moved z
  61     set screen where origin cmp file dest file origin cmp rank dest rank origin
  62   endif
  63   if not equal moved p
  64     set ep false
  65     if unequal space dest moved
  66       die You may not change the type of this piece.
  67     endif
  68   endif
  69   set legal false
  70   if match moved p k
  71     gosub moved origin dest
  72     if equal moved k
  73       set k dest
  74     endif
  75   elseif match moved q r b n z
  76     set legal fn moved origin dest or fn join moved H origin dest
  77     if equal moved r
  78       unsetflag origin
  79     endif
  80   endif
  81   if not var legal
  82     die you may not move a moved from origin to dest
  83   endif
  84   if match space #screen Q R B N Z P
  85     flip #screen
  86   endif
  87   if sub checked #k
  88     die you may not move into check.
  89   endif
  90 endsub
  91 moveindex 0
  92 MOVE: e2-e4
  93 postauto1
  94 moveindex 1
  95 MOVE: p e7-e5
  96 postauto2
  97 moveindex 2
  98 MOVE: N g1-f3
  99 postauto1
 100 moveindex 3
 101 MOVE: z b8-c6
 102 postauto2
 103 moveindex 4
 104 MOVE: B f1-b5
 105 postauto1
 106 moveindex 5
 107 MOVE: z c6-b4
 108 postauto2
 109 moveindex 6
 110 MOVE: d2-d3
 111 postauto1
 112 moveindex 7
 113 MOVE: p d7-d6
 114 postauto2
 115 moveindex 8
 116 MOVE: K e1-g1
 117 postauto1
 118 moveindex 9
 119 MOVE: b b5-e2
 120 postauto2
 121 moveindex 10
 122 MOVE: Q d1-d2
 123 postauto1
 124 moveindex 11
 125 MOVE: b e2-h5
 126 postauto2
 127 moveindex 12
 128 MOVE: g2-f3
 129 postauto1
 130 moveindex 13
 131 MOVE: z b4-c2
 132 postauto2
 133 moveindex 14
 134 MOVE: Z b1-c3
 135 postauto1
 136 moveindex 15
 137 MOVE: p d3-b1
 138 MOVE: q-b1
 139 postauto2
 140 moveindex 16
 141 MOVE: resigns
 142 postauto1
 143 if sub checked #k
 144   if sub stalemated #k
 145     say Checkmate! White has won!
 146     won
 147   else
 148     say Check!
 149   endif
 150 elseif sub stalemated #k
 151   say Stalemate! The game is drawn.
 152   drawn
 153 endif
 154 end
 155 
 156 lib takeover
 157 include chess2
 158 def RH checkhop #0 #1 1 0 and cond empty #0 not capture empty #1 and islower space screen
 159 def BH checkhop #0 #1 1 1 and cond empty #0 not capture empty #1 and islower space screen
 160 def QH fn RH #0 #1 or fn BH #0 #1
 161 def KH or checkhop #0 #1 1 0 checkhop #0 #1 1 1 and or checkleap #0 #1 2 0 checkkleap #0 #1 2 2 and cond empty #0 not capture empty #1 and islower space screen and not checked screen
 162 def PH checkhop #0 #1 1 1 and checkleap #0 #1 2 2 and < rank #0 rank #1 and cond empty #0 not capture empty #1 and islower space screen
 163 def rH checkhop #0 #1 1 0 and cond empty #0 not capture empty #1 and isupper space screen
 164 def bH checkhop #0 #1 1 1 and cond empty #0 not capture empty #1 and isupper space screen
 165 def qH fn rH #0 #1 or fn bH #0 #1
 166 def kH and or checkhop #0 #1 1 0 checkhop #0 #1 1 1 and or checkleap #0 #1 2 0 checkkleap #0 #1 2 2 and cond empty #0 not capture empty #1 and isupper space screen not checked screen
 167 def pH checkhop #0 #1 1 1 and checkleap #0 #1 2 2 and > rank #0 rank #1 and cond empty #0 not capture empty #1 and isupper space screen
 168 def NH false and == #0 #1
 169 def ZH false and == #0 #1
 170 def nH false and == #0 #1
 171 def zH false and == #0 #1
 172 def Z checkleap #0 #1 1 2
 173 def z checkleap #0 #1 1 2
 174 def PL array where #0 0 2 where #0 -2 2 where #0 2 2 where #0 0 1 where #0 -1 1 where #0 1 1
 175 def pL array where #0 0 -2 where #0 -2 -2 where #0 -2 2 where #0 0 -1 where #0 -1 -1 where #0 1 -1
 176 def ZL leaps #0 1 2
 177 def zL leaps #0 1 2
 178 sub P from to
 179   if == file #from file #to and not capture
 180     set legal checkaleap #from #to 0 1
 181     if var legal
 182       set ep false
 183     else
 184       set legal checkatwostep #from #to 0 1 0 1 and == rankname #from 2
 185       set ep #to
 186     endif
 187     set epc false
 188   elseif capture or #ep
 189     set legal checkaleap #from #to -1 1 or checkaleap #from #to 1 1
 190     set epc false
 191     if not capture and var legal
 192       set legal == #ep where #to 0 -1
 193       if var legal
 194         capture #ep
 195         set epc #ep
 196       endif
 197     endif
 198     set ep false
 199   elseif fn PH #from #to
 200     set legal true
 201     set ep false
 202   endif
 203   if != space #to moved and onboard where #to 0 1
 204     die "You may not promote a Pawn that can still move forward."
 205   endif
 206   if not onboard where #to 0 1
 207     if == P space #to
 208       die "You must promote a Pawn when it can no longer move forward."
 209     elseif not match space #to var wprom
 210       set np space #to
 211       die "You may not promote your Pawn to a" #np
 212     endif
 213   endif
 214 endsub
 215 sub p from to
 216   if == file #from file #to and not capture
 217     set legal checkaleap #from #to 0 -1
 218     if var legal
 219       set ep false
 220     else
 221       set legal checkatwostep #from #to 0 -1 0 -1 and == rankname #from 7
 222       set ep #to
 223     endif
 224     set epc false
 225   elseif capture or #ep
 226     set legal checkaleap #from #to -1 -1 or checkaleap #from #to 1 -1
 227     set epc false
 228     if not capture and var legal
 229       set legal == #ep where #to 0 1
 230       if var legal
 231         capture #ep
 232         set epc #ep
 233       endif
 234     endif
 235     set ep false
 236   elseif fn pH #from #to
 237     set legal true
 238     set ep false
 239   endif
 240   if != space #to moved and onboard where #to 0 -1
 241     die You may not promote a Pawn that can still move forward.
 242   endif
 243   if not onboard where #to 0 -1
 244     if == p space #to
 245       die You must promote a Pawn when it can no longer move forward.
 246     elseif not match space #to var bprom
 247       set np space #to
 248       die You may not promote your Pawn to a #np
 249     endif
 250   endif
 251 endsub
 252 sub stalemated kingpos
 253   store
 254   local from piece to
 255   if isupper space #kingpos
 256     def friends onlyupper
 257     def nofriends noupper
 258     def friend isupper #0
 259   else
 260     def friends onlylower
 261     def nofriends nolower
 262     def friend islower #0
 263   endif
 264   store
 265   for to fn KL #kingpos
 266     if fn space #kingpos #kingpos #to and not fn friend space #to and onboard #to
 267       move #kingpos #to
 268       set incheck sub checked #to
 269       restore
 270       verify #incheck
 271     endif
 272   next
 273   restore
 274   for (from piece) fn friends
 275     if == #from #kingpos
 276       continue
 277     endif
 278     for to fn join #piece L #from
 279       if fn #piece #from #to and not fn friend space #to and onboard #to
 280         move #from #to
 281         if == toupper #piece P and #ep
 282           gosub enpassant #piece #from #to
 283         endif
 284         if == toupper #piece N
 285           def screen2 where #to cmp file #from file #to cmp rank #from rank #to
 286           if #screen2 and not fn friend space #screen2
 287             flip #screen2
 288           endif
 289         endif
 290         if == toupper #piece Z
 291           def screen2 where #from cmp file #to file #from cmp rank #to rank #from
 292           if #screen2 and not fn friend space #screen2
 293             flip #screen2
 294           endif
 295         endif
 296         set incheck sub checked #kingpos
 297         restore
 298         verify #incheck
 299       endif
 300       if fn join #piece H #from #to and not fn friend space #to and onboard #to
 301         move #from #to
 302         flip screen
 303         set incheck sub checked #kingpos
 304         restore
 305         verify #incheck
 306       endif
 307     next
 308   next
 309   return true
 310 endsub
 311 sub K from to
 312   set legal fn K #from #to or fn KH #from #to
 313   if not checkhop #from #to 1 0 and match #to where #from 2 0 where #from -2 0
 314     set legal sub castle
 315   endif
 316   set K #to
 317   unsetflag #from
 318 endsub
 319 sub k from to
 320   set legal fn k #from #to or fn kH #from #to
 321   if not checkhop #from #to 1 0 and match #to where #from 2 0 where #from -2 0
 322     set legal sub castle
 323   endif
 324   set k #to
 325   unsetflag #from
 326 endsub
 327 endlib
 328 lib chess2
 329 set wpr 2
 330 set bpr 7
 331 set fps 2
 332 set pzs 1
 333 set wcastle c1 g1
 334 set bcastle c8 g8
 335 setsystem maxmove 2
 336 ban commands allmoves
 337 allow moves 1 captures 1 promotions 2
 338 for x piecekeys
 339   if match #x P K p k
 340     continue
 341   elseif isupper #x
 342     push wprom #x
 343   elseif islower #x
 344     push bprom #x
 345   endif
 346 next
 347 def N checkleap #0 #1 1 2
 348 def B checkride #0 #1 1 1
 349 def R checkride #0 #1 1 0
 350 def Q fn B #0 #1 or fn R #0 #1
 351 def K checkleap #0 #1 1 1 or checkleap #0 #1 1 0
 352 def M fn N #0 #1 or fn R #0 #1
 353 def A fn N #0 #1 or fn B #0 #1
 354 def n checkleap #0 #1 1 2
 355 def b checkride #0 #1 1 1
 356 def r checkride #0 #1 1 0
 357 def q fn B #0 #1 or fn R #0 #1
 358 def k checkleap #0 #1 1 1 or checkleap #0 #1 1 0
 359 def m fn N #0 #1 or fn R #0 #1
 360 def a fn N #0 #1 or fn B #0 #1
 361 def C cond cond empty #0 capture (not empty #1) (checkhop #0 #1 0 1) (checkride #0 #1 0 1) and #1
 362 def V cond cond empty #0 capture (not empty #1) (checkhop #0 #1 1 1) (checkride #0 #1 1 1) and #1
 363 def c cond cond empty #0 capture (not empty #1) (checkhop #0 #1 0 1) (checkride #0 #1 0 1) and #1
 364 def v cond cond empty #0 capture (not empty #1) (checkhop #0 #1 1 1) (checkride #0 #1 1 1) and #1
 365 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
 366 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
 367 def PL filter lambda (onboard #1) mergeall where #ori -1 1 where #ori 1 1 values lambda (where #ori 0 #1) range 1 var fps =ori
 368 def pL filter lambda (onboard #1) mergeall where #ori -1 -1 where #ori 1 -1 values lambda (where #ori 0 neg #1) range 1 var fps =ori
 369 setflag rules
 370 def NL leaps #0 1 2
 371 def BL rays #0 1 1
 372 def RL rays #0 1 0
 373 def VL rays #0 1 1
 374 def CL rays #0 1 0
 375 def QL merge rays #0 1 0 rays #0 1 1
 376 def KL merge leaps #0 1 0 leaps #0 1 1
 377 def AL merge leaps #0 1 2 rays #0 1 1
 378 def ML merge rays #0 1 0 leaps #0 1 2
 379 def nL leaps #0 1 2
 380 def bL rays #0 1 1
 381 def rL rays #0 1 0
 382 def vL rays #0 1 1
 383 def cL rays #0 1 0
 384 def qL merge rays #0 1 0 rays #0 1 1
 385 def kL merge leaps #0 1 0 leaps #0 1 1
 386 def aL merge leaps #0 1 2 rays #0 1 1
 387 def mL merge rays #0 1 0 leaps #0 1 2
 388 sub checked king
 389   my from piece
 390   if isupper cond empty #king moved space #king
 391     def enemies onlylower
 392   else
 393     def enemies onlyupper
 394   endif
 395   for (from piece) fn enemies
 396     if fn #piece #from #king
 397       return #from
 398     endif
 399   next
 400   return false
 401 endsub
 402 sub P from to
 403   local ydir
 404   if == file #from file #to and not capture
 405     set legal checkaleap #from #to 0 1
 406     if var legal
 407       set ep false
 408     else
 409       set legal checkaride #from #to 0 1 and <= distance #from #to #fps and == rankname #from #wpr
 410       set ep #to
 411     endif
 412     set epc false
 413   elseif capture or #ep
 414     set legal checkaleap #from #to -1 1 or checkaleap #from #to 1 1
 415     set epc false
 416     if not capture and var legal
 417       set legal > rank #to rank #ep and < rankname #to #bpr and == file #to file #ep
 418       if var legal
 419         capture #ep
 420         set epc #ep
 421       endif
 422     endif
 423     set ep false
 424   endif
 425   if != space #to moved and onboard where #to 0 #pzs
 426     die "You may not promote a Pawn until it reaches the promotion zone."
 427   endif
 428   if not onboard where #to 0 #pzs
 429     if == P space #to
 430       askpromote #wprom
 431     elseif not match space #to var wprom
 432       set np space #to
 433       die "You may not promote your Pawn to a" #np
 434     endif
 435   endif
 436   return true
 437 endsub
 438 sub p from to
 439   if == file #from file #to and not capture
 440     set legal checkaleap #from #to 0 -1
 441     if var legal
 442       set ep false
 443     else
 444       set legal checkaride #from #to 0 -1 and <= distance #from #to #fps and == rankname #from #bpr
 445       set ep #to
 446     endif
 447     set epc false
 448   elseif capture or #ep
 449     set legal checkaleap #from #to -1 -1 or checkaleap #from #to 1 -1
 450     set epc false
 451     if not capture and var legal
 452       set legal < rank #to rank #ep and > rankname #to #wpr and == file #to file #ep
 453       if var legal
 454         capture #ep
 455         set epc #ep
 456       endif
 457     endif
 458     set ep false
 459   endif
 460   if != space #to moved and onboard where #to 0 neg #pzs
 461     die You may not promote a Pawn until it reaches the promotion zone.
 462   endif
 463   if not onboard where #to 0 neg #pzs
 464     if == p space #to
 465       askpromote #bprom
 466     elseif not match space #to var bprom
 467       set np space #to
 468       die You may not promote your Pawn to a #np
 469     endif
 470   endif
 471   return true
 472 endsub
 473 sub K from to
 474   set legal fn K #from #to
 475   if match #to where #from 2 0 where #from -2 0
 476     set legal sub castle
 477   endif
 478   set K #to
 479   unsetflag #from
 480 endsub
 481 sub k from to
 482   set legal fn K #from #to
 483   if match #to where #from 2 0 where #from -2 0
 484     set legal sub castle
 485   endif
 486   set k #to
 487   unsetflag #from
 488 endsub
 489 sub castle
 490   local c RPOS RDEST xdir
 491   if not flag #from
 492     die A King may not castle after it moves.
 493   endif
 494   if capture
 495     die A King may not castle to an occupied space.
 496   endif
 497   set xdir sign minus file #to file #from
 498   if not checkaride #from #to #xdir 0
 499     die A King may not castle across any occupied space.
 500   endif
 501   set c #to
 502   do
 503     set c where #c #xdir 0
 504     if flag #c
 505       break
 506     elseif not onboard #c
 507       die No piece was found to castle with.
 508     elseif not empty #c
 509       die The King cannot castle with the piece at #c
 510     endif
 511   loop
 512   set RPOS #c
 513   move #to #from
 514   if sub checked #from
 515     die A King may not castle out of check.
 516   endif
 517   store
 518   for c path #from #to
 519     move #from #c
 520     if sub checked #c
 521       die A King may not castle through check.
 522     endif
 523     restore
 524   next
 525   move #from #to
 526   if == count var subargs 0
 527     set RDEST where #to neg #xdir 0
 528   else
 529     set RDEST elem 0 subargs
 530   endif
 531   unsetflag #RPOS
 532   move #RPOS #RDEST
 533   return true
 534 endsub
 535 sub castlepos from to
 536   local c RPOS RDEST xdir safe
 537   verify flag #from
 538   verify empty #to
 539   set xdir sign minus file #to file #from
 540   verify checkaride #from #to #xdir 0
 541   verify not sub checked #from
 542   set c #to
 543   do
 544     set c where #c #xdir 0
 545     if flag #c
 546       break
 547     endif
 548     verify onboard #c
 549     verify empty #c
 550   loop
 551   verify flag #c
 552   set RPOS #c
 553   store
 554   for c path #from #to
 555     move #from #c
 556     set safe not sub checked #c
 557     restore
 558     verify #safe
 559   next
 560   move #from #to
 561   set RDEST where #to neg #xdir 0
 562   move #RPOS #RDEST
 563   return true
 564 endsub
 565 sub stalemated kingpos
 566   store
 567   local from piece to
 568   if isupper space #kingpos
 569     def friends onlyupper
 570     def nofriends noupper
 571     def friend isupper #0
 572     set cspaces var wcastle
 573   else
 574     def friends onlylower
 575     def nofriends nolower
 576     def friend islower #0
 577     set cspaces var bcastle
 578   endif
 579   set royal space var kingpos
 580   store
 581   for (from piece) fn friends
 582     for to fn join #piece L #from
 583       if fn #piece #from #to and not fn friend space #to and onboard #to
 584         move #from #to
 585         if not sub checked cond == #from #kingpos #to #kingpos
 586           setlegal #from #to
 587         endif
 588       endif
 589       restore
 590     next
 591   next
 592   for to var cspaces
 593     if sub castlepos #kingpos #to
 594       if not sub checked #to
 595         setlegal #kingpos #to
 596       endif
 597     endif
 598     restore
 599   next
 600   return cond count system legalmoves false true
 601 endsub
 602 sub enpassant piece from to
 603   local pe
 604   verify not capture and #ep
 605   verify == P toupper #piece
 606   set pe join filename #to rankname #from
 607   verify == #ep #pe
 608   capture #ep
 609 endsub
 610 endlib