You are here:

Finding the ID number for a specific position in Chess960

♕♘♗♘♖♔♖♗

While it is easy to find the position for the corresponding ID number from sheets of paper, the reverse is much more difficult.

Interestingly there seems to be no program out there, to accomplish this.

Because this is a good example to introduce many of the 7th language words – here now the program.

The pieces are added to the position by touching them. The last piece is removed by touching the red ⌫-symbol. Ok – the GUI features are rudimentary, but this part is normaly covered from the hosting Java™ program.

As soon as the row contains 8 pieces, the program terminates. If the position is valid in Chess960, the ID number is shown.

Remember to place the Bishops on two fields of different colors (that means an even number of pieces or no piece betweeen the Bishops) and the King must be placed between two Rooks.

If you are interested in the probability of winning for white, you can download the computer chess rating list from 01/15/2020.

 

// in memoriam Reinhard Scharnagl
// © 2020 Otmar Klenk
forget ♔table

: ♔table
  0   "♕♘♘♖♔♖" 16  "♘♕♘♖♔♖" 32  "♘♘♕♖♔♖" 48  "♘♘♖♕♔♖" 64  "♘♘♖♔♕♖"
  80  "♘♘♖♔♖♕" 96  "♕♘♖♘♔♖" 112 "♘♕♖♘♔♖" 128 "♘♖♕♘♔♖" 144 "♘♖♘♕♔♖"
  160 "♘♖♘♔♕♖" 176 "♘♖♘♔♖♕" 192 "♕♘♖♔♘♖" 208 "♘♕♖♔♘♖" 224 "♘♖♕♔♘♖"
  240 "♘♖♔♕♘♖" 256 "♘♖♔♘♕♖" 272 "♘♖♔♘♖♕" 288 "♕♘♖♔♖♘" 304 "♘♕♖♔♖♘"
  320 "♘♖♕♔♖♘" 336 "♘♖♔♕♖♘" 352 "♘♖♔♖♕♘" 368 "♘♖♔♖♘♕" 384 "♕♖♘♘♔♖"
  400 "♖♕♘♘♔♖" 416 "♖♘♕♘♔♖" 432 "♖♘♘♕♔♖" 448 "♖♘♘♔♕♖" 464 "♖♘♘♔♖♕"
  480 "♕♖♘♔♘♖" 496 "♖♕♘♔♘♖" 512 "♖♘♕♔♘♖" 528 "♖♘♔♕♘♖" 544 "♖♘♔♘♕♖"
  560 "♖♘♔♘♖♕" 576 "♕♖♘♔♖♘" 592 "♖♕♘♔♖♘" 608 "♖♘♕♔♖♘" 624 "♖♘♔♕♖♘"
  640 "♖♘♔♖♕♘" 656 "♖♘♔♖♘♕" 672 "♕♖♔♘♘♖" 688 "♖♕♔♘♘♖" 704 "♖♔♕♘♘♖"
  720 "♖♔♘♕♘♖" 736 "♖♔♘♘♕♖" 752 "♖♔♘♘♖♕" 768 "♕♖♔♘♖♘" 784 "♖♕♔♘♖♘"
  800 "♖♔♕♘♖♘" 816 "♖♔♘♕♖♘" 832 "♖♔♘♖♕♘" 848 "♖♔♘♖♘♕" 864 "♕♖♔♖♘♘"
  880 "♖♕♔♖♘♘" 896 "♖♔♕♖♘♘" 912 "♖♔♖♕♘♘" 928 "♖♔♖♘♕♘" 944 "♖♔♖♘♘♕"
;

: ♗table
  "♗♗------"  "♗--♗----"  "♗----♗--"  "♗------♗"
  "-♗♗-----"  "--♗♗----"  "--♗--♗--"  "--♗----♗"
  "-♗--♗---"  "---♗♗---"  "----♗♗--"  "----♗--♗"
  "-♗----♗-"  "---♗--♗-"  "-----♗♗-"  "------♗♗"
;

memory::♔map drop
memory::♗map drop
memory::stats drop
string position

: ♔map-onerr
  2drop
  "is not a valid position" println
  quit
;

: ♗map-onerr
  ♔map-onerr
;

: populate
  ♔map fn .clear
  ♗map fn .clear
  ♔table
  60 0 do
    ♔map !
  loop

  ♗table
  0 16 do
    i -rot '♗' indicesof ♗map !
  -1 +loop
;

: rect  ( piece x -- )
  green setcolor
  over '⌫' == if
    red setcolor
    g fn 3 pick 100 60 60 .drawRect
    5 -
  else
    g fn 3 pick 100 60 60 .drawRect
    black setcolor
  then
  10 + g fn 2swap swap str$ rot 145 .drawString
;

: click  ( piece x --  )
  2dup rect
  100 65 65 mouse? if
    paperWhite setcolor
    g fn position @ 60 80 .drawString
    dup '⌫' == if
      position size 0> if
        position position size 1- left$ position !
      then
      drop
    else
      str$ position s>&
      drop
    then
  else
    drop
  then
;

memory::POSmap drop
'K' '♔' POSmap !
'Q' '♕' POSmap !
'R' '♖' POSmap !
'B' '♗' POSmap !
'N' '♘' POSmap !

: merge
  0 value idx
  string rslt
  "" rslt !
  for
    forobj '-' == if
      dup 0 <@ str$
      rslt s>& drop
    else
      forobj str$ rslt s>& drop
    then
  each
  rslt @
;

: pos$  ( id -- pos$ )
  ♔map fn .clear
  ♗map fn .clear
  ♔table
  60 0 do
    rot ♔map !
  loop
  ♗table
  0 16 do
    i ♗map !
  -1 +loop
  16 /mod >int swap >int 16 *
  ♔map @ >carr
  ♗map rot @ >carr
  merge
  rot drop
;

: POS$  ( id -- POS$ )
  string s
  "" s !
  s swap
  pos$ >carr for
    forobj POSmap @ s<&
  each
  @
;

: POS  ( id --  )
  POS$
  2dup println
  stats size 0> if
    stats @ println
  else
    2drop
  then
;

: FEN$  ( id -- FEN$ )
  string s
  "" s !
  POS$ 2dup lower$ s s>&
  "/pppppppp/8/8/8/8/PPPPPPPP/" s<&
  s>&
  bl s<& "w KQkq -" s<&
  @
;

: match
  position @ "♗" strip$ ♔map @
  position @ '♗' indicesof ♗map @
  + dup "\n\n\n\n\n\n\n\nid: " print println
  dup pos$ print space
  POS
;

: id
  cls
  "Dialog" 0 40 setfont
  populate
  position 7 left$ position !
  repeat
    '♔' 50  click '♕' 120 click '♖' 190 click '♗' 260 click '♘' 330 click '⌫' 419 click
    black setcolor
    g fn position @ 60 80 .drawString
    position size 8 >=
  until
  match
  "" position !
;

: score
  stats fn .clear
  "opening_report_by_eco.txt" existsf? if
    "opening_report_by_eco.txt" openf
    begin
      readline$
      eof? not
    while
      split dup dup 3 @ 4 left$ val
      100.0 rot 2 @ 4 left$ val -
      / 10000 * 5+ 10 / >int 10 /
      str$ "%" concat$
      rot 0 @ stats !
    repeat
    2drop
    "opening_report_by_eco.txt" closef
  then
;

: pos  ( id --  )
  cls
  dup
  pos$ type cr
  POS
;

: FEN  ( id --  )
  FEN$ type cr
;

: rpos  (  --  )
  960 random
  pos
;

clear
decimal
score
."enter \"id\", \"‹id› pos\", \"rpos\" or \"‹id› FEN\"" cr


enter "id", "‹id› pos", "rpos" or "‹id› FEN"

ok> 123 pos
♘♕♖♘♗♔♖♗
NQRNBKRB
70.6%   ← only with opening_report_by_eco.txt
ok>

– or –

ok> rpos
a random position
ok>

– or –

ok> id
see picture

– or –

ok> 123 FEN
nqrnbkrb/pppppppp/8/8/8/8/PPPPPPPP/NQRNBKRB w KQkq -
ok>

Why to use 7th


  • 7ᵗʰ comes in a tiny package of only about 0.6 Mb containing the whole IDE
  • 7ᵗʰ needs no installation – only a download of one jar-file to start
  • 7ᵗʰ contains an integrated help
  • 7ᵗʰ is fully integratable in existing or new Java programs
  • 7ᵗʰ has access to Java™ classes and its member functions
  • 7ᵗʰ implements the ScriptEngine pattern
  • 7ᵗʰ runs on every computer with an installed JVM
  • 7ᵗʰ can run headless as a console application
  • 7ᵗʰ programs / words are very compact
  • 7ᵗʰ supports a Perl-like search and substitution syntax



here You can download the source-code of the example on the left:

Finding the ID of a Chess960 position:


here You can download the opening_report_by_eco.txt:

Probability of Winning for White: the statistical data came from here




Just generate a Chess960 random position


forget position
8 char-array position

: set  ( piece --  )
  position dup '♖' indicesof dup
  size random @ !
;

: rpos
  repeat
    position 8 '♖' fill
    "♗♗♕♘♘" >carr for
      forobj set
    each
    position '♗' indicesof n@ drop +
    isodd?
  until
  '♔' position dup
  '♖' indicesof 1 @ !

  position @ str$ println
;

clear
rpos


♕♗♖♔♗♘♘♖
♖♗♘♔♗♘♕♖
♘♕♗♘♖♔♖♗
♗♗♖♘♔♕♘♖
♘♖♘♔♕♖♗♗
♗♗♖♔♕♖♘♘
♗♘♖♗♔♘♖♕




Calculate the ID for a specific Chess960 position


// in memoriam Reinhard Scharnagl
forget position

string position

: ♗table
  /......♗♗/  /.....♗♗./  /...♗..♗./
  /.♗....♗./  /....♗..♗/  /....♗♗../
  /...♗♗.../  /.♗..♗.../  /..♗....♗/
  /..♗..♗../  /..♗♗..../  /.♗♗...../
  /♗......♗/  /♗....♗../  /♗..♗..../
  /♗♗....../
;

: ♘5♘
  /...♘♘/  /..♘.♘/  /..♘♘./  /.♘..♘/
  /.♘.♘./  /.♘♘../  /♘...♘/  /♘..♘./
  /♘.♘../  /♘♘.../
;

: POS
  8 0 do
    "KQRBN" position i c@ indexof dup 0 >= if
      "♔♕♖♗♘" rot c@
      position i c!
    else
      drop
    then
  loop
;

: id  ( POS$ --  )
  upper$ position ! POS
  ♗table
  16 0 do
    position @ rot =~ if
      15 i - 0 do
        drop
      loop
      i
      leave
    then
  loop
  position @ "♗" strip$
  2dup "♕" indexof -rot
  "♕" strip$ position !
  ♘5♘
  10 0 do
    position @ rot =~ if
      9 i - 0 do
        drop
      loop
      i
      leave
    then
  loop
  96 * -rot
  16 * -rot
  + +
;


ok> "nqrnbkrb" id


– or –

ok> "♘♕♖♘♗♔♖♗" id

123

We respect Your privacy and we neither track You nor use cookies…
7th and the 7th logo are trademarks of 7th Stone Software GmbH. All other product or service names are the property of their respective owners.