You are Red. You may not move Green pieces.

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

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

1. swap g1 h1 
1... swap g10 h10 
2. P i4-h4 
2... p a7-b7 
3. N b1-c3 
3... n b10-c8 
4. C b3-e3 
4... c b8-e8 
5. P e4-d4 
5... n g10-f8 
6. E c1-e4 
6... p e7-f7 
7. E h1-f4 
7... p g7-g6 
8. G e2-e1 
8... p f7-f6 
9. R a1-a2 
9... p f6-f5 
10. E f4-h1 
10... r a10-a6 
11. R a2-i2 
11... p g6-g5 
12. P g4-g5 
12... p f5-g5 
13. N g1-f3 
13... p g5-f5 
14. R i2-i7 
14... r i10-i7 
15. R i1-i7 
15... r a6-f6 
16. R i7-i9 
16... f f10-f9 
17. E e4-h6 
17... n f8-g6 
18. N c3-e4 
18... r f6-f8 
19. R i9-f9 
19... r f8-f9 
20. E h6-f9 
20... g e9-f9 
21. N e4-d6 
21... p f5-f4 
22. N f3-g1 
22... p c7-d7 
23. N d6-b7 
23... e c10-e7 
24. P h4-h5 
24... p f4-g4 
25. P h5-h6 
25... n g6-e5 
26. N b7-c9 
26... f d10-d9 
27. P h6-h7 
27... c h8-h4 
28. P d4-d5 
28... n e5-d3 
29. G e1-e2 
29... n d3-b2 
30. P c4-b4 
30... p g4-g3 
31. P h7-g7 
31... e e7-h5 
32. F f1-e1 
32... g f9-e9 
33. P d5-c5 
33... c e8-e10 
34. N c9-a8 
34... p g3-h3 
35. E h1-f4 
35... c h4-h8 
36. N a8-c9 
36... p h3-g3 
37. N g1-i2 
37... p g3-g2 
38. N i2-g3 
38... c h8-h2 
39. G e2-f1 
39... n b2-d3 
40. P c5-c6 
40... c e10-e8 
41. N g3-h5 
41... c e8-b8 
42. F e1-e2 
42... c b8-f8 
43. E f4-d7 
43... e h10-f7 
44. N h5-f4 
44... e f7-c9 
45. N f4-d3 
45... g e9-d10 
46. N d3-e5 
46... n c8-e9 
47. G f1-e1 
47... f d9-d8 
48. E d7-g5 
48... c f8-a8 
49. N e5-f3 
49... e c9-e6 
50. N f3-h2 
50... p g2-h2 
51. P c6-d6 
51... e e6-g3 
52. F e2-f3 
52... e g3-i6 
53. P d6-d7 
53... n e9-c10 
54. P d7-d8 
54... n c10-d8 
55. E g5-d7 
55... p h2-g2 
56. F d1-e2 
56... c a8-a1 
57. C e3-i3 
57... e i6-g3 
58. P b4-b5 
58... n d8-b7 
59. P b5-b6 
59... n b7-d6 
60. F f3-e3 
60... n d6-c4 
61. P b6-c6 
61... n c4-a3 
62. C i3-f3 
62... n a3-b1 
63. C f3-d1 
63... g d10-e9 
64. P a4-b4 
64... n b1-a3 
65. G e1-f1 
65... n a3-c2 
66. F e3-f3 
66... n c2-d4 
67. E d7-g5 
67... n d4-c6 
68. E g5-d3 
68... n c6-b4 
69. E d3-a1 
69... n b4-c6 
70. E a1-d3 
70... n c6-d8 
71. C d1-d7 
71... n d8-f9 
72. P g7-h7 
72... n f9-e7 
73. C d7-d2 
73... p g2-g1 
74. E d3-g1 
74... n e7-g6 
75. F f3-e3 
75... e g3-e6 
76. E g1-e4 
76... n g6-f8 
77. P h7-g7 
77... n f8-h9 
78. G f1-e1 
78... n h9-g7 
79. E e4-g7 
79... e e6-c9 
80. F e3-d3 
80... E g7-i4 
81. E i4-g7 
81... e c9-e6 
82. C d2-d6 
| // pass
82... pass 
83. F d3-d2 
83... pass 
84. F d2-d1 
84... pass 
85. F d1-d2 
85... drawn

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

Here is a code listing:

   0 set G findpiece G spaces
   1 set g findpiece g spaces
   2 include janggi
   3 if == fencode "rnef1fenr4g5c5c1p1p1p1p1p18P1P1P1P1P1C5C5G4RNEF1FENR"
   4   setflag firstturn
   5 endif
   6 setsystem maxmove 1
   7 allow pass 1
   8 set passes 0
   9 setflag rules
  10 sub postauto1
  11   if flag firstturn
  12     if == origin b1 and == dest c1 or and == origin c1 == dest b1
  13       rewritemove "swap b1 c1"
  14       add E b1 N c1
  15     elseif == origin g1 and == dest h1 or and == origin h1 == dest g1
  16       rewritemove "swap g1 h1"
  17       add N g1 E h1
  18     elseif == moved N and == old E or and == moved E == old N
  19       rewritemove "swap b1 c1 g1 h1"
  20       add E b1 N c1 N g1 E h1
  21     elseif == moved old and match old N E
  22       rewritemove pass
  23       add N b1 E c1 E g1 N h1
  24     elseif not match thismove "swap b1 c1" "swap g1 h1" "swap b1 c1 g1 h1" "pass"
  25       die The first move is reserved for positioning the Knights and Elephants.
  26     endif
  27     return
  28   endif
  29   if == thismove "pass"
  30     inc passes
  31   elseif islower moved
  32     die You are Green. You may not move Red pieces.
  33   elseif isupper old
  34     die You may not capture your own pieces.
  35   elseif not fn moved origin dest
  36     die You may not move a moved from origin to dest
  37   else
  38     set passes 0
  39   endif
  40   if == moved G
  41     set G dest
  42   endif
  43   if sub checked #G
  44     die You may not move your General into check
  45   endif
  46   set OG checkride #g #G 1 0
  47 endsub
  48 sub postauto2
  49   if flag firstturn
  50     if == origin b10 and == dest c10 or and == origin c10 == dest b10
  51       rewritemove "swap b10 c10"
  52       add e b10 n c10
  53     elseif == origin g10 and == dest h10 or and == origin h10 == dest g10
  54       rewritemove "swap g10 h10"
  55       add n g10 e h10
  56     elseif == moved n and == old e or and == moved e == old n
  57       rewritemove "swap b10 c10 g10 h10"
  58       add e b10 n c10 n g10 e h10
  59     elseif == moved old and match old n e
  60       rewritemove pass
  61       add n b10 e c10 e g10 n h10
  62     elseif not match thismove "swap b10 c10" "swap g10 h10" "swap b10 c10 g10 h10" "pass"
  63       die The first move is reserved for positioning the Knights and Elephants.
  64     endif
  65     unallow swap 1
  66     unsetflag firstturn
  67     return
  68   endif
  69   if == thismove "pass"
  70     inc passes
  71   elseif isupper moved
  72     die You are Red. You may not move Green pieces.
  73   elseif islower old
  74     die You may not capture your own pieces.
  75   elseif not fn moved origin dest
  76     die You may not move a moved from origin to dest
  77   else
  78     set passes 0
  79   endif
  80   if == moved g
  81     set g dest
  82   endif
  83   if sub checked #g
  84     die You may not move your General into check
  85   endif
  86   set og checkride #g #G 1 0
  87 endsub
  88 moveindex 1
  89 MOVE: swap g1 h1
  90 postauto1
  91 moveindex 2
  92 MOVE: swap g10 h10
  93 postauto2
  94 moveindex 3
  95 MOVE: P i4-h4
  96 postauto1
  97 moveindex 4
  98 MOVE: p a7-b7
  99 postauto2
 100 moveindex 5
 101 MOVE: N b1-c3
 102 postauto1
 103 moveindex 6
 104 MOVE: n b10-c8
 105 postauto2
 106 moveindex 7
 107 MOVE: C b3-e3
 108 postauto1
 109 moveindex 8
 110 MOVE: c b8-e8
 111 postauto2
 112 moveindex 9
 113 MOVE: P e4-d4
 114 postauto1
 115 moveindex 10
 116 MOVE: n g10-f8
 117 postauto2
 118 moveindex 11
 119 MOVE: E c1-e4
 120 postauto1
 121 moveindex 12
 122 MOVE: p e7-f7
 123 postauto2
 124 moveindex 13
 125 MOVE: E h1-f4
 126 postauto1
 127 moveindex 14
 128 MOVE: p g7-g6
 129 postauto2
 130 moveindex 15
 131 MOVE: G e2-e1
 132 postauto1
 133 moveindex 16
 134 MOVE: p f7-f6
 135 postauto2
 136 moveindex 17
 137 MOVE: R a1-a2
 138 postauto1
 139 moveindex 18
 140 MOVE: p f6-f5
 141 postauto2
 142 moveindex 19
 143 MOVE: E f4-h1
 144 postauto1
 145 moveindex 20
 146 MOVE: r a10-a6
 147 postauto2
 148 moveindex 21
 149 MOVE: R a2-i2
 150 postauto1
 151 moveindex 22
 152 MOVE: p g6-g5
 153 postauto2
 154 moveindex 23
 155 MOVE: P g4-g5
 156 postauto1
 157 moveindex 24
 158 MOVE: p f5-g5
 159 postauto2
 160 moveindex 25
 161 MOVE: N g1-f3
 162 postauto1
 163 moveindex 26
 164 MOVE: p g5-f5
 165 postauto2
 166 moveindex 27
 167 MOVE: R i2-i7
 168 postauto1
 169 moveindex 28
 170 MOVE: r i10-i7
 171 postauto2
 172 moveindex 29
 173 MOVE: R i1-i7
 174 postauto1
 175 moveindex 30
 176 MOVE: r a6-f6
 177 postauto2
 178 moveindex 31
 179 MOVE: R i7-i9
 180 postauto1
 181 moveindex 32
 182 MOVE: f f10-f9
 183 postauto2
 184 moveindex 33
 185 MOVE: E e4-h6
 186 postauto1
 187 moveindex 34
 188 MOVE: n f8-g6
 189 postauto2
 190 moveindex 35
 191 MOVE: N c3-e4
 192 postauto1
 193 moveindex 36
 194 MOVE: r f6-f8
 195 postauto2
 196 moveindex 37
 197 MOVE: R i9-f9
 198 postauto1
 199 moveindex 38
 200 MOVE: r f8-f9
 201 postauto2
 202 moveindex 39
 203 MOVE: E h6-f9
 204 postauto1
 205 moveindex 40
 206 MOVE: g e9-f9
 207 postauto2
 208 moveindex 41
 209 MOVE: N e4-d6
 210 postauto1
 211 moveindex 42
 212 MOVE: p f5-f4
 213 postauto2
 214 moveindex 43
 215 MOVE: N f3-g1
 216 postauto1
 217 moveindex 44
 218 MOVE: p c7-d7
 219 postauto2
 220 moveindex 45
 221 MOVE: N d6-b7
 222 postauto1
 223 moveindex 46
 224 MOVE: e c10-e7
 225 postauto2
 226 moveindex 47
 227 MOVE: P h4-h5
 228 postauto1
 229 moveindex 48
 230 MOVE: p f4-g4
 231 postauto2
 232 moveindex 49
 233 MOVE: P h5-h6
 234 postauto1
 235 moveindex 50
 236 MOVE: n g6-e5
 237 postauto2
 238 moveindex 51
 239 MOVE: N b7-c9
 240 postauto1
 241 moveindex 52
 242 MOVE: f d10-d9
 243 postauto2
 244 moveindex 53
 245 MOVE: P h6-h7
 246 postauto1
 247 moveindex 54
 248 MOVE: c h8-h4
 249 postauto2
 250 moveindex 55
 251 MOVE: P d4-d5
 252 postauto1
 253 moveindex 56
 254 MOVE: n e5-d3
 255 postauto2
 256 moveindex 57
 257 MOVE: G e1-e2
 258 postauto1
 259 moveindex 58
 260 MOVE: n d3-b2
 261 postauto2
 262 moveindex 59
 263 MOVE: P c4-b4
 264 postauto1
 265 moveindex 60
 266 MOVE: p g4-g3
 267 postauto2
 268 moveindex 61
 269 MOVE: P h7-g7
 270 postauto1
 271 moveindex 62
 272 MOVE: e e7-h5
 273 postauto2
 274 moveindex 63
 275 MOVE: F f1-e1
 276 postauto1
 277 moveindex 64
 278 MOVE: g f9-e9
 279 postauto2
 280 moveindex 65
 281 MOVE: P d5-c5
 282 postauto1
 283 moveindex 66
 284 MOVE: c e8-e10
 285 postauto2
 286 moveindex 67
 287 MOVE: N c9-a8
 288 postauto1
 289 moveindex 68
 290 MOVE: p g3-h3
 291 postauto2
 292 moveindex 69
 293 MOVE: E h1-f4
 294 postauto1
 295 moveindex 70
 296 MOVE: c h4-h8
 297 postauto2
 298 moveindex 71
 299 MOVE: N a8-c9
 300 postauto1
 301 moveindex 72
 302 MOVE: p h3-g3
 303 postauto2
 304 moveindex 73
 305 MOVE: N g1-i2
 306 postauto1
 307 moveindex 74
 308 MOVE: p g3-g2
 309 postauto2
 310 moveindex 75
 311 MOVE: N i2-g3
 312 postauto1
 313 moveindex 76
 314 MOVE: c h8-h2
 315 postauto2
 316 moveindex 77
 317 MOVE: G e2-f1
 318 postauto1
 319 moveindex 78
 320 MOVE: n b2-d3
 321 postauto2
 322 moveindex 79
 323 MOVE: P c5-c6
 324 postauto1
 325 moveindex 80
 326 MOVE: c e10-e8
 327 postauto2
 328 moveindex 81
 329 MOVE: N g3-h5
 330 postauto1
 331 moveindex 82
 332 MOVE: c e8-b8
 333 postauto2
 334 moveindex 83
 335 MOVE: F e1-e2
 336 postauto1
 337 moveindex 84
 338 MOVE: c b8-f8
 339 postauto2
 340 moveindex 85
 341 MOVE: E f4-d7
 342 postauto1
 343 moveindex 86
 344 MOVE: e h10-f7
 345 postauto2
 346 moveindex 87
 347 MOVE: N h5-f4
 348 postauto1
 349 moveindex 88
 350 MOVE: e f7-c9
 351 postauto2
 352 moveindex 89
 353 MOVE: N f4-d3
 354 postauto1
 355 moveindex 90
 356 MOVE: g e9-d10
 357 postauto2
 358 moveindex 91
 359 MOVE: N d3-e5
 360 postauto1
 361 moveindex 92
 362 MOVE: n c8-e9
 363 postauto2
 364 moveindex 93
 365 MOVE: G f1-e1
 366 postauto1
 367 moveindex 94
 368 MOVE: f d9-d8
 369 postauto2
 370 moveindex 95
 371 MOVE: E d7-g5
 372 postauto1
 373 moveindex 96
 374 MOVE: c f8-a8
 375 postauto2
 376 moveindex 97
 377 MOVE: N e5-f3
 378 postauto1
 379 moveindex 98
 380 MOVE: e c9-e6
 381 postauto2
 382 moveindex 99
 383 MOVE: N f3-h2
 384 postauto1
 385 moveindex 100
 386 MOVE: p g2-h2
 387 postauto2
 388 moveindex 101
 389 MOVE: P c6-d6
 390 postauto1
 391 moveindex 102
 392 MOVE: e e6-g3
 393 postauto2
 394 moveindex 103
 395 MOVE: F e2-f3
 396 postauto1
 397 moveindex 104
 398 MOVE: e g3-i6
 399 postauto2
 400 moveindex 105
 401 MOVE: P d6-d7
 402 postauto1
 403 moveindex 106
 404 MOVE: n e9-c10
 405 postauto2
 406 moveindex 107
 407 MOVE: P d7-d8
 408 postauto1
 409 moveindex 108
 410 MOVE: n c10-d8
 411 postauto2
 412 moveindex 109
 413 MOVE: E g5-d7
 414 postauto1
 415 moveindex 110
 416 MOVE: p h2-g2
 417 postauto2
 418 moveindex 111
 419 MOVE: F d1-e2
 420 postauto1
 421 moveindex 112
 422 MOVE: c a8-a1
 423 postauto2
 424 moveindex 113
 425 MOVE: C e3-i3
 426 postauto1
 427 moveindex 114
 428 MOVE: e i6-g3
 429 postauto2
 430 moveindex 115
 431 MOVE: P b4-b5
 432 postauto1
 433 moveindex 116
 434 MOVE: n d8-b7
 435 postauto2
 436 moveindex 117
 437 MOVE: P b5-b6
 438 postauto1
 439 moveindex 118
 440 MOVE: n b7-d6
 441 postauto2
 442 moveindex 119
 443 MOVE: F f3-e3
 444 postauto1
 445 moveindex 120
 446 MOVE: n d6-c4
 447 postauto2
 448 moveindex 121
 449 MOVE: P b6-c6
 450 postauto1
 451 moveindex 122
 452 MOVE: n c4-a3
 453 postauto2
 454 moveindex 123
 455 MOVE: C i3-f3
 456 postauto1
 457 moveindex 124
 458 MOVE: n a3-b1
 459 postauto2
 460 moveindex 125
 461 MOVE: C f3-d1
 462 postauto1
 463 moveindex 126
 464 MOVE: g d10-e9
 465 postauto2
 466 moveindex 127
 467 MOVE: P a4-b4
 468 postauto1
 469 moveindex 128
 470 MOVE: n b1-a3
 471 postauto2
 472 moveindex 129
 473 MOVE: G e1-f1
 474 postauto1
 475 moveindex 130
 476 MOVE: n a3-c2
 477 postauto2
 478 moveindex 131
 479 MOVE: F e3-f3
 480 postauto1
 481 moveindex 132
 482 MOVE: n c2-d4
 483 postauto2
 484 moveindex 133
 485 MOVE: E d7-g5
 486 postauto1
 487 moveindex 134
 488 MOVE: n d4-c6
 489 postauto2
 490 moveindex 135
 491 MOVE: E g5-d3
 492 postauto1
 493 moveindex 136
 494 MOVE: n c6-b4
 495 postauto2
 496 moveindex 137
 497 MOVE: E d3-a1
 498 postauto1
 499 moveindex 138
 500 MOVE: n b4-c6
 501 postauto2
 502 moveindex 139
 503 MOVE: E a1-d3
 504 postauto1
 505 moveindex 140
 506 MOVE: n c6-d8
 507 postauto2
 508 moveindex 141
 509 MOVE: C d1-d7
 510 postauto1
 511 moveindex 142
 512 MOVE: n d8-f9
 513 postauto2
 514 moveindex 143
 515 MOVE: P g7-h7
 516 postauto1
 517 moveindex 144
 518 MOVE: n f9-e7
 519 postauto2
 520 moveindex 145
 521 MOVE: C d7-d2
 522 postauto1
 523 moveindex 146
 524 MOVE: p g2-g1
 525 postauto2
 526 moveindex 147
 527 MOVE: E d3-g1
 528 postauto1
 529 moveindex 148
 530 MOVE: n e7-g6
 531 postauto2
 532 moveindex 149
 533 MOVE: F f3-e3
 534 postauto1
 535 moveindex 150
 536 MOVE: e g3-e6
 537 postauto2
 538 moveindex 151
 539 MOVE: E g1-e4
 540 postauto1
 541 moveindex 152
 542 MOVE: n g6-f8
 543 postauto2
 544 moveindex 153
 545 MOVE: P h7-g7
 546 postauto1
 547 moveindex 154
 548 MOVE: n f8-h9
 549 postauto2
 550 moveindex 155
 551 MOVE: G f1-e1
 552 postauto1
 553 moveindex 156
 554 MOVE: n h9-g7
 555 postauto2
 556 moveindex 157
 557 MOVE: E e4-g7
 558 postauto1
 559 moveindex 158
 560 MOVE: e e6-c9
 561 postauto2
 562 moveindex 159
 563 MOVE: F e3-d3
 564 postauto1
 565 moveindex 160
 566 MOVE: E g7-i4
 567 postauto2
 568 moveindex 161
 569 MOVE: E i4-g7
 570 postauto1
 571 moveindex 162
 572 MOVE: e c9-e6
 573 postauto2
 574 moveindex 163
 575 MOVE: C d2-d6
 576 postauto1
 577 moveindex 165
 578 MOVE: pass
 579 postauto2
 580 moveindex 166
 581 MOVE: F d3-d2
 582 postauto1
 583 moveindex 167
 584 MOVE: pass
 585 postauto2
 586 moveindex 168
 587 MOVE: F d2-d1
 588 postauto1
 589 moveindex 169
 590 MOVE: pass
 591 postauto2
 592 moveindex 170
 593 MOVE: F d1-d2
 594 postauto1
 595 moveindex 171
 596 MOVE: drawn
 597 postauto2
 598 if flag firstturn
 599   remind "

Start by positioning your Horses and Elephant.


Move one to the one adjacent to swap just those two.
Move one to the other one on the other side to swap both pairs.
Move one to the same one on the other side, or just click Pass, to leave their position unchanged." 600 setlegal b1 c1 g1 h1 601 setlegal c1 b1 g1 h1 602 setlegal g1 b1 c1 h1 603 setlegal h1 b1 c1 g1 604 end 605 endif 606 if == #passes 2 607 say Both Sides Passed! Game Drawn! 608 drawn 609 elseif checkride #g #G 1 0 and var OG 610 say Mutual Opposing Generals! Game Drawn! 611 drawn 612 elseif sub stalemated #G 613 if sub checked #G 614 say Checkmate! Red has won! 615 won 616 endif 617 elseif sub checked #G 618 say Check! 619 endif 620 end 621 622 lib janggi 623 include xiangqi 624 allow swap 1 swap 2 moves 2 moves 3 625 set many d1 1 f1 1 e2 1 d3 1 f3 1 d8 1 f8 1 e9 1 d10 1 f10 1 626 def c != tolower space screen c and checkhop #0 #1 1 1 and var #0 and var #1 or and != tolower space screen c checkhop #0 #1 0 1 and != C cond empty #0 captured space #1 627 def C != toupper space screen C and checkhop #0 #1 1 1 and var #0 and var #1 or and != toupper space screen C checkhop #0 #1 0 1 and != c cond empty #0 captured space #1 628 def e checkpath #0 #1 1 0 1 1 1 1 629 def E checkpath #0 #1 1 0 1 1 1 1 630 def r checkride #0 #1 1 1 and var #0 and var #1 or checkride #0 #1 1 0 631 def R checkride #0 #1 1 1 and var #0 and var #1 or checkride #0 #1 1 0 632 def f checkleap #0 #1 1 1 and var #0 and var #1 or or checkleap #0 #1 1 0 and flag #1 633 def F checkleap #0 #1 1 1 and var #0 and var #1 or or checkleap #0 #1 1 0 and flag #1 634 def p checkleap #0 #1 1 1 and var #0 and var #1 or checkleap #0 #1 1 0 and >= rank #0 rank #1 635 def P checkleap #0 #1 1 1 and var #0 and var #1 or checkleap #0 #1 1 0 and <= rank #0 rank #1 636 def g checkleap #0 #1 1 1 and var #0 and var #1 or or checkleap #0 #1 1 0 and flag #1 637 def G checkleap #0 #1 1 1 and var #0 and var #1 or or checkleap #0 #1 1 0 and flag #1 638 def EL leaps #0 2 3 639 def eL leaps #0 2 3 640 def fL merge leaps #0 1 1 leaps #0 1 0 641 def FL merge leaps #0 1 1 leaps #0 1 0 642 def gL merge leaps #0 1 1 leaps #0 1 0 643 def GL merge leaps #0 1 1 leaps #0 1 0 644 endlib 645 lib xiangqi 646 setsystem maxmove 1 647 ban commands allmoves 648 allow moves 1 captures 1 649 setflag d1 e1 f1 d2 e2 f2 e3 d3 f3 d8 e8 f8 d9 e9 f9 d10 e10 f10 650 def N checktwostep #0 #1 0 1 1 1 651 def P checkaleap #0 #1 -1 0 or checkaleap #0 #1 1 0 and > rank #0 4 or checkaleap #0 #1 0 1 652 def R checkride #0 #1 0 1 653 def E checktwostep #0 #1 1 1 1 1 and < rank #1 5 654 def C cond cond empty #0 capture (not empty #1) (checkhop #0 #1 0 1) (checkride #0 #1 0 1) and #1 655 def G checkride #0 #1 1 0 and == space #1 g or checkleap #0 #1 0 1 and flag #1 656 def F checkleap #0 #1 1 1 and flag #1 657 def n checktwostep #0 #1 0 1 1 1 658 def p checkaleap #0 #1 -1 0 or checkaleap #0 #1 1 0 and < rank #0 5 or checkaleap #0 #1 0 -1 659 def r checkride #0 #1 0 1 660 def e checktwostep #0 #1 1 1 1 1 and > rank #1 4 661 def c cond cond empty #0 capture (not empty #1) (checkhop #0 #1 0 1) (checkride #0 #1 0 1) and #1 662 def g checkride #0 #1 1 0 and == space #1 G or checkleap #0 #1 0 1 and flag #1 663 def f checkleap #0 #1 1 1 and flag #1 664 sub checked general 665 local piece from 666 if isupper space #general 667 def enemies onlylower 668 else 669 def enemies onlyupper 670 endif 671 for (from piece) fn enemies 672 if fn #piece #from #general 673 return true 674 endif 675 next 676 return false 677 endsub 678 sub stalemated kingpos 679 store 680 local from piece to key lglmvs 681 set lglmvs () 682 if isupper space #kingpos 683 def friends onlyupper 684 def nofriends noupper 685 def friend isupper #0 686 else 687 def friends onlylower 688 def nofriends nolower 689 def friend islower #0 690 endif 691 set royal space var kingpos 692 store 693 for to fn join #royal L #kingpos 694 if fn #royal #kingpos #to and not fn friend space #to and onboard #to 695 move #kingpos #to 696 set incheck sub checked #to 697 restore 698 if not #incheck 699 setlegal #kingpos #to 700 endif 701 endif 702 next 703 restore 704 for (from piece) fn friends 705 if == #from #kingpos 706 continue 707 endif 708 for to fn join #piece L #from 709 if fn #piece #from #to and not fn friend space #to and onboard #to 710 move #from #to 711 set incheck sub checked #kingpos 712 restore 713 if not #incheck 714 setlegal #from #to 715 endif 716 endif 717 next 718 next 719 return cond count system legalmoves false true 720 endsub 721 def PL leaps #0 1 0 722 def EL leaps #0 2 2 723 def RL rays #0 1 0 724 def CL rays #0 1 0 725 def GL merge leaps #0 1 0 (#g #G) 726 def FL leaps #0 1 1 727 def NL leaps #0 1 2 728 def pL leaps #0 -1 0 729 def eL leaps #0 2 2 730 def rL rays #0 1 0 731 def cL rays #0 1 0 732 def gL merge leaps #0 1 0 (#G #g) 733 def fL leaps #0 1 1 734 def nL leaps #0 1 2 735 endlib