'tea4move.tea, solve 4-move chess problems
'Written in Teapro which uses the OpenTea technology
'People need computer software that actually works.
vari sg_pass1, sg_pass2, sg_pass3
vari dg_pass1, dg_pass2, dg_pass3

vari dg_ply
vari sg_menwhite, sg_menblack
vari sg_abcdefgh, sg_12345678
vari sg_tobywhite, sg_tobyblack
vari sg_board0, sg_dates, sg_in1, sg_in2
vari dg_movestoshow, sg_fileout, dg_fileout
vari dg_value1, dg_value2, dg_value3, dg_value4
vari dg_value5, dg_value6, dg_value7, dg_value8
vari sg_move1, sg_move2, sg_move3, sg_move4
vari sg_move5, sg_move6, sg_move7, sg_move8

vari dg_movecount1, dg_movecount2, dg_movecount3, dg_movecount4
vari dg_movecount5, dg_movecount6, dg_movecount7, dg_movecount8

vari dg_onecount1, dg_onecount2, dg_onecount3, dg_onecount4
vari dg_onecount5, dg_onecount6, dg_onecount7, dg_onecount8

vari dg_totalmoves1, dg_totalmoves2, dg_totalmoves3
vari dg_totalmoves4, dg_totalmoves5, dg_totalmoves6
vari dg_totalmoves7, dg_totalmoves8

vari dg_solutionindex, sg_score, sg_number
vari dg_matescount7, dg_totalmatescount
vari sg_nothing

sub_main
endp

subr sub_main
'updated 2008/02/25, 2005/10/07, 2004/04/18
    vari s_any, d_any, s_dot, d_dot
    vari d_loop, s_pick

    $trb sg_nothing, " "

    $out "Program: tea4move.tea, build 39, 2009/10/25"
    $out "Copyright (c) 2000-2009 D La Pierre Ballard"
    $out "Written in Teapro which uses the OpenTea technology"
    $out "Copyright (c) 1997-2009 D La Pierre Ballard"
    $out "This program was begun 26-APR-2000"
    $out "People need computer software that actually works."
    $out s_any
    dsec d_any
    ded$ s_any, d_any, 0, 0
    $out "seconds = " + s_any

    dsys d_any, 1
    dsys d_dot, 2
    ded$ s_any, d_any, 0, 0
    ded$ s_dot, d_dot, 0, 0
    $out "memory=" + s_any + ", lines=" + s_dot

    'get sg_fileout
    dran d_any
    d_any = d_any * 99999 * 99999 \ 1
    sg_fileout = "T" + d_any + d_any
    $cut sg_fileout, sg_fileout, 1, 8
    sg_fileout = sg_fileout + ".TEXT"
    $out "fileout=" + sg_fileout

    dg_fileout = 2
    $inp s_any, "1 = output board and results to file=" + sg_fileout
    $ift s_any = "1": dg_fileout = 1

    dg_movestoshow = 0
    d_loop = 1
    dwhi d_loop = 1
        dsys d_any, 1
        dsys d_dot, 2
        ded$ s_any, d_any, 0, 0
        ded$ s_dot, d_dot, 0, 0
        $out "memory=" + s_any + ", lines=" + s_dot

	  $out "capturing en passant and castling are not yet supported"
	  $out "the output file is=" + sg_fileout
	  sub_speedquick
	  $out "speed=" + dg_pass1
	  $out "1. Solve one"
	  $inp s_pick, "* to end"

	  $ift s_pick = "1": sub_begin
	  $ift s_pick = "*": dinc d_loop
    endw    
ends sub_main


subr sub_problems
'updated 2003/10/06
    vari s_any, d_any, s_dot, d_dot
    vari s_pick, d_continue, d_loop, d_holdfileout

    d_continue = 1
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#1.Test 4-Mover, "
	  $app sg_in1, "1.Kd5-c6 and 1.Rh6-h7, "
	  sg_in2 = "7-ply positions=240,776, 7-ply mates=255"
        sg_board0 = sg_board0 + "k-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------R  "
        sg_board0 = sg_board0 + "---K----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#2. Lev Loshinski, Vladimir Sif, Konk. "
	  $app sg_in1, "Pamjati Platova 1954, 1st Prize"
	  sg_in2 = "1.Re8-e4, 7-ply positions=6,615,369, "
	  $app sg_in2, "7-ply mates=114,761"
        sg_board0 = sg_board0 + "N-R-R--K  "
        sg_board0 = sg_board0 + "r-------  "
        sg_board0 = sg_board0 + "B--p-P--  "
        sg_board0 = sg_board0 + "p--k--pQ  "
        sg_board0 = sg_board0 + "r-p-----  "
        sg_board0 = sg_board0 + "-----P--  "
        sg_board0 = sg_board0 + "--Nbn-n-  "
        sg_board0 = sg_board0 + "-q------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#3. Samuel Loyd, Frank Leslie's Illustrated "
	  $app sg_in1, "1858"
	  sg_in2 = "1.Qc5-b5, 7-ply=621,207, 7-ply mates=367"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--Q-----  "
        sg_board0 = sg_board0 + "-----k--  "
        sg_board0 = sg_board0 + "----p--K  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "----N---  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#4. Samuel Loyd, New York Clipper 1856"
	  sg_in2 = "1.Qe1-g1, 7-ply positions=948,679, "
	  $app sg_in2, "7-ply mates=241"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-----p--  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "--K-Nk--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----Q---  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/04"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#5. Samuel Loyd, Frere's Chess Hand-Book "
	  $app sg_in1, "1857"
	  sg_in2 = "1.Qc1-h6, 7-ply positions=1,031,314, "
	  $app sg_in2, "7-ply mates=28,106"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "-----p--  "
        sg_board0 = sg_board0 + "-----K-k  "
        sg_board0 = sg_board0 + "r-------  "
        sg_board0 = sg_board0 + "---n----  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "R-Q-----  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#6. Samuel Loyd, Chess Monthly 1858"
	  sg_in2 = "1.Ne3-d5, 7-ply positions=220,018, "
	  $app sg_in2, "7-ply mates=5,333"
        sg_board0 = sg_board0 + "n-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "n-------  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----N---  "
        sg_board0 = sg_board0 + "p-K-----  "
        sg_board0 = sg_board0 + "k-------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/04"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#7. Samuel Loyd, Frank Leslie's "
	  $app sg_in1, "Illustrated 1857"
	  sg_in2 = "1.Ne6-d8, 7-ply=3,776,910, 7-ply mates=4,880"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "p---k---  "
        sg_board0 = sg_board0 + "----N---  "
        sg_board0 = sg_board0 + "---p----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------Q-  "
        sg_board0 = sg_board0 + "---B----  "
        sg_board0 = sg_board0 + "-K------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#8. Samuel Loyd, New York Albion 1857"
	  sg_in2 = "1.Be1-b4, 7-ply=590,725, 7-ply mates=43"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-N------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--P-k---  "
        sg_board0 = sg_board0 + "----BRK-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#9. Samuel Loyd, Saturday Press 1859"
	  sg_in2 = "1.Ke4-f5, 7-ply=346,429, 7-ply mates=209"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "----K---  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "--B-k-p-  "
        sg_board0 = sg_board0 + "------B-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#10. Samuel Loyd, British Chess "
	  $app sg_in1, "Association 1866-67"
	  sg_in2 = "1.Nc5-b3, 7-ply positions=1,586,421, "
	  $app sg_in2, "7-ply mates=752"
        sg_board0 = sg_board0 + "-----K--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--N-----  "
        sg_board0 = sg_board0 + "--k-p--Q  "
        sg_board0 = sg_board0 + "--B----P  "
        sg_board0 = sg_board0 + "-P------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/07"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#11. Samuel Loyd, New York Clipper, 1856"
	  sg_in2 = "1. Qd4-g1, 7-ply positions=3,019,557, "
	  $app sg_in2, "7-ply mates=27,436"
        sg_board0 = sg_board0 + "n-------  "
        sg_board0 = sg_board0 + "---p-p--  "
        sg_board0 = sg_board0 + "NpkNp-p-  "
        sg_board0 = sg_board0 + "-p--P---  "
        sg_board0 = sg_board0 + "---Q----  "
        sg_board0 = sg_board0 + "------B-  "
        sg_board0 = sg_board0 + "b-------  "
        sg_board0 = sg_board0 + "----K---  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/04"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#12. Samuel Loyd, American Union 1858"
	  sg_in2 = "1.e5-e6, 7-ply=2,391,069, 7-ply mates=2,107"
        sg_board0 = sg_board0 + "-------n  "
        sg_board0 = sg_board0 + "------Q-  "
        sg_board0 = sg_board0 + "--Np----  "
        sg_board0 = sg_board0 + "--k-P---  "
        sg_board0 = sg_board0 + "---N----  "
        sg_board0 = sg_board0 + "-------K  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#13. Miroslav Havel, Vynalezy a pokroky "
	  $app sg_in1, "12/1 1906 "
	  sg_in2 = "1.Nc6-e7, 7-ply positions=396,980, "
	  $app sg_in2, "7-ply mates=580"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-R------  "
        sg_board0 = sg_board0 + "--N-----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "p--p----  "
        sg_board0 = sg_board0 + "k--K----  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#14. Miroslav Havel, Zlata Praha 1903 "
	  $app sg_in1, "russ285"
	  sg_in2 = "1.Rg2-d2, 7-ply positions=1,350,179, "
	  $app sg_in2, "7-ply mates=26,420"
        sg_board0 = sg_board0 + "K----b--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------R-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------R-  "
        sg_board0 = sg_board0 + "-------k  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/05"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#15. Miroslav Havel, Sachove Listy 1, 1902"
	  sg_in2 = "1.Ke2-d2, 7-ply positions=2,368,355, "
	  $app sg_in2, "7-ply mates-2,718"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-p-Q--B-  "
        sg_board0 = sg_board0 + "k-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----K---  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#16. Miroslav Havel, Zlata Praha 29/3 1901"
	  sg_in2 = "1.Qe1-g1, 7-ply positions=537,405, "
	  $app sg_in2, "7-ply mates=400"
        sg_board0 = sg_board0 + "-------N  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---p--p-  "
        sg_board0 = sg_board0 + "---K----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------k  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----Q---  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#17. Miroslav Havel, Sachove Listy 11, 1901"
	  sg_in2 = "1.Rf5-h5, 7-ply positions=9,156,782, "
	  $app sg_in2, "7-ply mates=267,054"
        sg_board0 = sg_board0 + "-n--K---  "
        sg_board0 = sg_board0 + "--bp----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---p-R--  "
        sg_board0 = sg_board0 + "--N--pk-  "
        sg_board0 = sg_board0 + "---p--N-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---b---Q  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/05"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#18. Miroslav Havel, Zlata Praha 23/2 1906"
	  sg_in2 = "1.Qc1-c3, 7-ply positions=3,449,947, "
	  $app sg_in2, "7-ply mates=11,713"
        sg_board0 = sg_board0 + "----N---  "
        sg_board0 = sg_board0 + "n-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----k---  "
        sg_board0 = sg_board0 + "-------R  "
        sg_board0 = sg_board0 + "-n--N---  "
        sg_board0 = sg_board0 + "b-Q-K--b  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#19. Miroslav Havel, Zlata Praha 6/1 1911"
	  sg_in2 = "1.Ne5-d3, 7-ply positions=4,367,787, "
	  $app sg_in2, "7-ply mates=47,934"
        sg_board0 = sg_board0 + "-----r--  "
        sg_board0 = sg_board0 + "-------n  "
        sg_board0 = sg_board0 + "B--Q-p-K  "
        sg_board0 = sg_board0 + "----N---  "
        sg_board0 = sg_board0 + "p---k---  "
        sg_board0 = sg_board0 + "r-----B-  "
        sg_board0 = sg_board0 + "----b---  "
        sg_board0 = sg_board0 + "-----n--  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#20. Miroslav Havel, Munchener Neueste "
	  $app sg_in1, "Nachrichten 16/9 1911"
	  sg_in2 = "1.Ng1-h3, 7-ply positions=2,395,596, "
	  $app sg_in2, "7-ply mates=3,969"
        sg_board0 = sg_board0 + "-B------  "
        sg_board0 = sg_board0 + "------K-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----k-Pp  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "-Q------  "
        sg_board0 = sg_board0 + "------N-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#21. Miroslav Havel, Zlata Praha 16/2 1912"
	  sg_in2 = "1.Ba6-e2, 7-ply positions=757,032, "
	  $app sg_in2, "7-ply mates=1,098"
        sg_board0 = sg_board0 + "---QK---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "B---k---  "
        sg_board0 = sg_board0 + "--p-----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-----P--  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#22. Miroslav Havel, Sport a hry 21/2 1912"
	  sg_in2 = "1.Qd8-c8, 7-ply positions=582,809, "
	  $app sg_in2, "7-ply mates=1,545"
        sg_board0 = sg_board0 + "---Q---K  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "-------k  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------P  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#23. Miroslav Havel, Zlata Praha 15/3 1912"
	  sg_in2 = "1.Qe6-e2, 7-ply positions=2,136,608, "
	  $app sg_in2, "7-ply mates=604"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-R--Q---  "
        sg_board0 = sg_board0 + "-------p  "
        sg_board0 = sg_board0 + "-----kP-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "K-------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#24. Miroslav Havel, Zlata Praha 24/5 1912"
	  sg_in2 = "1.Qa2-f7, 7-ply positions=699,196, "
	  $app sg_in2, "7-ply mates=873"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------k  "
        sg_board0 = sg_board0 + "----K---  "
        sg_board0 = sg_board0 + "Q------P  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#25. Miroslav Havel, Munchener Neueste "
	  $app sg_in1, "Nachrichten 3/11 1912"
	  sg_in2 = "1.Qc4-f7, 7-ply positions=2,157,913, "
	  $app sg_in2, "7-ply mates=2,514" 
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "B-Q--Nk-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "------K-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#26. Miroslav Havel, Zlata Praha 7/2 1913"
	  sg_in2 = "1.Pg6-g7, 7-ply positions=1,078,686, "
	  $app sg_in2, "7-ply mates=4,503"
        sg_board0 = sg_board0 + "----B---  "
        sg_board0 = sg_board0 + "----k---  "
        sg_board0 = sg_board0 + "-Q-b--P-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "K-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#27. Miroslav Havel, Zlata Praha 18/4 1913"
	  sg_in2 = "1.Ra5-a7, 7-ply positions=1,513,130, "
        $app sg_in2, "7-ply mates=1,568"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-----p--  "
        sg_board0 = sg_board0 + "----k-P-  "
        sg_board0 = sg_board0 + "R-------  "
        sg_board0 = sg_board0 + "----pK--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--R-----  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#28. Miroslav Havel, Zlata Praha 26/6 1914"
	  sg_in2 = "1.Qh5-h8, 7-ply=6,544,278, 7-ply mates=58,208"
        sg_board0 = sg_board0 + "--B-----  "
        sg_board0 = sg_board0 + "---N----  "
        sg_board0 = sg_board0 + "-p--k---  "
        sg_board0 = sg_board0 + "ppp---BQ  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----n---  "
        sg_board0 = sg_board0 + "Kb----N-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#29. Miroslav Havel, Zlata Praha 18/12 "
	  $app sg_in1, "1914 "
	  sg_in2 = "1.Rf8-f1, 7-ply positions=1,339,916, "
	  $app sg_in2, "7-ply mates=735"
        sg_board0 = sg_board0 + "-----R--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----p-p-  "
        sg_board0 = sg_board0 + "----B-k-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------N-  "
        sg_board0 = sg_board0 + "------K-  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#30. Samuel Loyd, Tournoi de Paris, "
	  $app sg_in1, "1867, 2/3 prix"
	  sg_in2 = "1.Bf1-a6, 7-ply positions=19,711,276, "
	  $app sg_in2, "7-ply mates=665,864"
        sg_board0 = sg_board0 + "K------Q  "
        sg_board0 = sg_board0 + "-p------  "
        sg_board0 = sg_board0 + "pPq----P  "
        sg_board0 = sg_board0 + "P--p--P-  "
        sg_board0 = sg_board0 + "----pP-N  "
        sg_board0 = sg_board0 + "-------k  "
        sg_board0 = sg_board0 + "n-----R-  "
        sg_board0 = sg_board0 + "-n--BB--  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#31. Samuel Loyd, Chess Monthly 1857"
	  sg_in2 = "1.Ke1-d1, 7-ply positions=519,389, "
	  $app sg_in2, "7-ply mates=1,089"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---P----  "
        sg_board0 = sg_board0 + "--N---p-  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "--Q-K-k-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#32. Samuel Loyd, London Chess Congress 1866"
	  sg_in2 = "1.Bc3-d2, 7-ply positions=4,782,695, "
	  $app sg_in2, "7-ply mates=17,043"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--P--Q--  "
        sg_board0 = sg_board0 + "--p-----  "
        sg_board0 = sg_board0 + "------B-  "
        sg_board0 = sg_board0 + "--Bk----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-----K--  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#33. Miroslav Havel, SVTS 1956 "
	  $app sg_in1, "1 Mention"
	  sg_in2 = "1.Qc7-b6, 7-ply positions=3,918,400, "
	  $app sg_in2, "7-ply mates=30,237"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "rpQKp-n-  "
        sg_board0 = sg_board0 + "p-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-pN-p--p  "
        sg_board0 = sg_board0 + "-pN-----  "
        sg_board0 = sg_board0 + "--k-----  "
        sg_board0 = sg_board0 + "-R------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/05"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#34. Lev Loshinski, Problem 1962, "
	  $app sg_in1, "4th Prize"
	  sg_in2 = "1.Kb7-a6, 7-ply positions=3,298,313, "
 	  $app sg_in2, "7-ply mates=150,570"
        sg_board0 = sg_board0 + "---bB---  "
        sg_board0 = sg_board0 + "-Kp-k-N-  "
        sg_board0 = sg_board0 + "--P--Rp-  "
        sg_board0 = sg_board0 + "-P--ppP-  "
        sg_board0 = sg_board0 + "--p--p--  "
        sg_board0 = sg_board0 + "P------r  "
        sg_board0 = sg_board0 + "----Pn--  "
        sg_board0 = sg_board0 + "-bB--n--  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/05"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#35. Lev Loshinski, Yakov Georgevich Vladimirov, "
	  $app sg_in1, "Sachmaty v CCCP 1964, 2nd Prize"
	  sg_in2 = "1.Pc6-b7 7-ply positions=250,343, "
	  $app sg_in2, "7-ply mates=1,417"
        sg_board0 = sg_board0 + "--n-----  "
        sg_board0 = sg_board0 + "RpP--R--  "
        sg_board0 = sg_board0 + "-BPk----  "
        sg_board0 = sg_board0 + "K------P  "
        sg_board0 = sg_board0 + "P---PP--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#36. Samuel Loyd "
	  $app sg_in1, "Detroit Free Press 1878"
	  sg_in2 = "1.Na4-b6, 7-ply positions=525,235, "
	  $app sg_in2, "7-ply mates=390"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "p-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-B------  "
        sg_board0 = sg_board0 + "N-------  "
        sg_board0 = sg_board0 + "k-------  "
        sg_board0 = sg_board0 + "--KB----  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#37. Miroslav Havel "
	  $app sg_in1, "Narodni Listy 12/2 1905"
	  sg_in2 = "1.Qh4-e7, 7-ply positions=837,419, "
	  $app sg_in2, "7-ply mates=410"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------p  "
        sg_board0 = sg_board0 + "----N--Q  "
        sg_board0 = sg_board0 + "----k---  "
        sg_board0 = sg_board0 + "----B---  "
        sg_board0 = sg_board0 + "----K---  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#38. Miroslav Havel "
	  $app sg_in1, "Zlata Praha 20/4 1906"
	  sg_in2 = "1.Qh5-e8, 7-ply positions=3,886,064, "
	  $app sg_in2, "7-ply mates=18,694"
        sg_board0 = sg_board0 + "K-------  "
        sg_board0 = sg_board0 + "-R--B---  "
        sg_board0 = sg_board0 + "p---k---  "
        sg_board0 = sg_board0 + "---p-p-Q  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------b-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#39. Miroslav Havel "
	  $app sg_in1, "Zlata Praha 2/8 1912"
	  sg_in2 = "1.Qb6-a5, 7-ply positions=982,166, "
	  $app sg_in2, "7-ply mates=1,042"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-Qp-----  "
        sg_board0 = sg_board0 + "--Bk----  "
        sg_board0 = sg_board0 + "-----K--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/07"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#40. Miroslav Havel"
	  $app sg_in1, "Zlata Praha 18/10 1912"
	  sg_in2 = "1.Rh8-h1, 7-ply positions=1,515,001, "
	  $app sg_in2, "7-ply mates=1,513"
        sg_board0 = sg_board0 + "-------R  "
        sg_board0 = sg_board0 + "---BpKp-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----B-k-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#41. Miroslav Havel"
	  $app sg_in1, "Zlata Praha 29/11 1912"
	  sg_in2 = "1.Qh6-f8, 7-ply positions=1,589,744, "
	  $app sg_in2, "7-ply mates=2,953"
        sg_board0 = sg_board0 + "K-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------Q  "
        sg_board0 = sg_board0 + "-N--k--N  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----P---  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#42. Miroslav Havel, Munchener "
	  $app sg_in1, "Neueste Nachrichten 8/2 1913"
	  sg_in2 = "1.Bc6-b5, 7-ply positions=1,078,814, "
	  $app sg_in2, "7-ply mates=11,295"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------KR  "
        sg_board0 = sg_board0 + "--BB----  "
        sg_board0 = sg_board0 + "------k-  "
        sg_board0 = sg_board0 + "----p-p-  "
        sg_board0 = sg_board0 + "-p--p--p  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#43. Miroslav Havel, "
	  $app sg_in1, "Magyar Sakkujsag 10/6 1913"
	  sg_in2 = "1.Re7-e5, 7-ply positions=13,230,650, "
	  $app sg_in2, "7-ply mates=158,880"
        sg_board0 = sg_board0 + "B-------  "
        sg_board0 = sg_board0 + "----R-Q-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "npkn--p-  "
        sg_board0 = sg_board0 + "-pp-----  "
        sg_board0 = sg_board0 + "-r-p----  "
        sg_board0 = sg_board0 + "r-pp---B  "
        sg_board0 = sg_board0 + "-----bK-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/10"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#44. Miroslav Havel, Ceskoslovenski Sach "
	  $app sg_in1, "1958 2 Mention"
	  sg_in2 = "1.Qe3-f4, 7-ply positions=8,872,724, "
	  $app sg_in2, "7-ply mates=69,426"
        sg_board0 = sg_board0 + "-------K  "
        sg_board0 = sg_board0 + "-R-----p  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "-Npk-b--  "
        sg_board0 = sg_board0 + "n-------  "
        sg_board0 = sg_board0 + "-R--Q---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------n-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#45. Miroslav Havel, Westminster Gazette "
	  $app sg_in1, "1920 1er Prix"
	  sg_in2 = "1.Nf7-d6, 7-ply positions=1,625,646, "
	  $app sg_in2, "7-ply mates=5,081"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---p-Np-  "
        sg_board0 = sg_board0 + "--p---R-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-----k--  "
        sg_board0 = sg_board0 + "---R--N-  "
        sg_board0 = sg_board0 + "-------p  "
        sg_board0 = sg_board0 + "------nK  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/11"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#46. Miroslav Havel, Hampshire Telegraph "
	  $app sg_in1, "and Post 15/5 1914"
	  sg_in2 = "1.Nh5-g3, 7-ply positions=747,364, "
	  $app sg_in2, "7-ply mates=152"
        sg_board0 = sg_board0 + "-B------  "
        sg_board0 = sg_board0 + "----p----  "
        sg_board0 = sg_board0 + "N-----B-  "
        sg_board0 = sg_board0 + "------N-  "
        sg_board0 = sg_board0 + "---k----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--KP----  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#47. Miroslav Havel, UJCS 30/6 1948, "
	  $app sg_in1, "4th Prize"
	  sg_in2 = "1.Rg2-a2, 7-ply positions=115,286, "
	  $app sg_in2, "7-ply mates=425"
        sg_board0 = sg_board0 + "-----K--  "
        sg_board0 = sg_board0 + "-----p-N  "
        sg_board0 = sg_board0 + "------k-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--p--pP-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------R-  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/10"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#48. Miroslav Havel, Sachove "
	  $app sg_in1, "umeni 31/3 1949"
	  sg_in2 = "1.Qg8-b8, 7-ply positions=1,269,056, "
	  $app sg_in2, "7-ply mates=760"
        sg_board0 = sg_board0 + "------Q-  "
        sg_board0 = sg_board0 + "p-------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----N---  "
        sg_board0 = sg_board0 + "k---p---  "
        sg_board0 = sg_board0 + "----K---  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/08"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#49. Miroslav Havel, "
	  $app sg_in1, "Zlata Praha 21/2 1924"
	  sg_in2 = "1.Re5-d5, 7-ply positions=698,258, "
	  $app sg_in2, "7-ply mates=1,067"
        sg_board0 = sg_board0 + "-k----K-  "
        sg_board0 = sg_board0 + "-------p  "
        sg_board0 = sg_board0 + "---P----  "
        sg_board0 = sg_board0 + "-B--R---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/09"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#50. Miroslav Havel, Parallele 50 22/11 "
	  $app sg_in1, "1951, Honorable Mention"
	  sg_in2 = "1.Kh6-g5, 7-ply positions=1,704,807, "
	  $app sg_in2, "7-ply mates=1,021"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------K  "
        sg_board0 = sg_board0 + "B----Q--  "
        sg_board0 = sg_board0 + "---k----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----P---  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/11"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#51.Miroslav Havel, "
	  $app sg_in1, "Narodni osvobozeni 9/6 1929 "
	  sg_in2 = "1.Ng8-f6, 7-ply positions=336,316, "
	  $app sg_in2, "7-ply mates=219"
        sg_board0 = sg_board0 + "-----KN-  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------k-  "
        sg_board0 = sg_board0 + "------P-  "
        sg_board0 = sg_board0 + "---R----  "
        sg_board0 = sg_board0 + "-----P--  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#52.Miroslav Havel, Ceskoslovensky "
	  $app sg_in1, "sach 6, 1929"
	  sg_in2 = "1.Qb3-a3, 7-ply positions=1,595,217, "
	  $app sg_in2, "7-ply mates=6,752"
        sg_board0 = sg_board0 + "r-B-----  "
        sg_board0 = sg_board0 + "kP----K-  "
        sg_board0 = sg_board0 + "b-----p-  "
        sg_board0 = sg_board0 + "-pp-----  "
        sg_board0 = sg_board0 + "---p----  "
        sg_board0 = sg_board0 + "-Q------  "
        sg_board0 = sg_board0 + "-p------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#53.Miroslav Havel, Ceskoslovensky "
	  $app sg_in1, "sach 7, 1929"
	  sg_in2 = "1.Qg1-d1, 7-ply positions=4,212,614, "
	  $app sg_in2, "7-ply mates=35,167"
        sg_board0 = sg_board0 + "--Kb----  "
        sg_board0 = sg_board0 + "-----prR  "
        sg_board0 = sg_board0 + "-----pNp  "
        sg_board0 = sg_board0 + "--p--k-p  "
        sg_board0 = sg_board0 + "-------R  "
        sg_board0 = sg_board0 + "--r-----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "------Q-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/11"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#54.Miroslav Havel, Narodni "
	  $app sg_in1, "osvobozeni 13/4 1930"
	  sg_in2 = "1.Pd6=d7, 7-ply positions=488,193, "
	  $app sg_in2, "7-ply mates=1,330"
        sg_board0 = sg_board0 + "-k------  "
        sg_board0 = sg_board0 + "n---K---  "
        sg_board0 = sg_board0 + "---P----  "
        sg_board0 = sg_board0 + "R-R-----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#55.Miroslav Havel, Ceskoslovensky "
	  $app sg_in1, "sach 4, 1930"
	  sg_in2 = "1.Kd4-e4, 7-ply positions=2,031,435, "
	  $app sg_in2, "7-ply mates=7,070"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "p-------  "
        sg_board0 = sg_board0 + "---p----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---K--B-  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "------k-  "
        sg_board0 = sg_board0 + "--Q--n--  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#56.Miroslav Havel, Basler "
	  $app sg_in1, "Nachrichten 22/11 1930"
	  sg_in2 = "1.Qg1-a7, 7-ply positions=2,369,606, "
	  $app sg_in2, "7-ply mates=5,901"
        sg_board0 = sg_board0 + "-----B--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "----K---  "
        sg_board0 = sg_board0 + "-pk-----  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---N--Q-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/11"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#57.Miroslav Havel, "
	  $app sg_in1, "Sachove noviny 24/1 1931"
	  sg_in2 = "1.Rf8-f3, 7-ply positions=700,640, "
	  $app sg_in2, "7-ply mates=316"
        sg_board0 = sg_board0 + "-----R--  "
        sg_board0 = sg_board0 + "-KN-----  "
        sg_board0 = sg_board0 + "-N-k----  "
        sg_board0 = sg_board0 + "----p---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#58.Miroslav Havel, Schweizerische "
	  $app sg_in1, "Schachzeitung 1, 1932"
	  sg_in2 = "1.Qe8-c8, 1.Nf2-e4, 7-ply positions=1,639,805, "
	  $app sg_in2, "7-ply mates="
        sg_board0 = sg_board0 + "----Q---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "---k--p-  "
        sg_board0 = sg_board0 + "---P--p-  "
        sg_board0 = sg_board0 + "------p-  "
        sg_board0 = sg_board0 + "------K-  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "B-------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/11"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#59.Miroslav Havel, Narodni "
	  $app sg_in1, "osvobozeni 31/7 1932"
	  sg_in2 = "1.Bf1-b5, 7-ply positions=369,408, "
	  $app sg_in2, "7-ply mates=17"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----R---  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "-------P  "
        sg_board0 = sg_board0 + "-----pk-  "
        sg_board0 = sg_board0 + "-----N--  "
        sg_board0 = sg_board0 + "-----BK-  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/12"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#60.Miroslav Havel, Ceskoslovensky "
	  $app sg_in1, "sach 10-11, 1932"
	  sg_in2 = "1.Re1-c1, 7-ply positions=1,435,052, "
	  $app sg_in2, "7-ply mates=18,767"
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----K--p  "
        sg_board0 = sg_board0 + "p-----k-  "
        sg_board0 = sg_board0 + "----p-p-  "
        sg_board0 = sg_board0 + "rp------  "
        sg_board0 = sg_board0 + "p----p--  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "----R--Q  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dift d_continue = 1
	  sg_dates = "2003/10/06"
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#99. Starting position"
	  sg_in2 = "7-ply positions=294,031, "
	  $app sg_in2, "7-ply mates=72"
        sg_board0 = sg_board0 + "rnbqkbnr  "
        sg_board0 = sg_board0 + "pppppppp  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "PPPPPPPP  "
        sg_board0 = sg_board0 + "RNBQKBNR  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi

    'template below
    dift d_continue = 1
	  sg_dates = ""
        'the board starts with 110 spaces
        dch$ sg_board0, 32, 110
	  sg_in1 = "#999. "
	  $app sg_in1, " "
	  sg_in2 = "7-ply positions=, "
	  $app sg_in2, "7-ply mates="
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "
        sg_board0 = sg_board0 + "--------  "

	  sub_offer_problem
	  d_continue = dg_pass1
    endi
    dg_pass1 = d_continue
ends sub_problems


subr sub_offer_problem
'updated 2003/10/11
    vari s_any, d_any, s_dot, d_dot
    vari d_continue

    $lok d_any, sg_in1, 1, "."
    dift d_any > 0: $cut sg_number, sg_in1, 1, d_any
     
    'the board ends with 100 spaces
    dch$ s_any, 32, 100
    sg_board0 = sg_board0 + s_any

    'rotate if needed
    sg_pass1 = sg_board0
    sub_rotate_right
    sg_board0 = sg_pass1

    sub_begin_initialize

    'show the board
    sg_pass1 = sg_board0
    sub_board

    d_continue = 1
    $inp s_any, "1 = solve this one, * to end"
    $ift s_any = "1": d_continue = 2
    $ift s_any = "*": d_continue = 99999
    dg_pass1 = d_continue    
ends sub_offer_problem


subr sub_begin
'updated 2002/08/04
    vari s_any, d_any, s_dot, d_dot
    vari s_pick, d_good, d_loop

    d_loop = 1
    dwhi d_loop = 1
	  sub_problems
	  d_loop = dg_pass1
    endw

    d_good = 1
    dift d_loop <> 2: dinc d_good

    dift d_good = 1
        dg_movestoshow = 1
        $inp s_any, "ply to show 1..7"
        $isd d_any, s_any
        dift d_any = 1
		$tod dg_movestoshow, s_any   
		dift dg_movestoshow < 1: dg_movestoshow = 1
		dift dg_movestoshow > 7: dg_movestoshow = 7
	  endi

	  sub_process
    endi
ends sub_begin


subr sub_begin_initialize
'updated 2005/03/14
    'initialize the string array
    dg_solutionindex = 1
    dwhi dg_solutionindex <= 100
	  $toi dg_solutionindex, sg_nothing
	  dinc dg_solutionindex
    endw
    dg_solutionindex = 0

    dtoi 81, 1
    dtoi 82, -1
    dtoi 83, 10
    dtoi 84, -10

    dtoi 85, 11
    dtoi 86, -11
    dtoi 87, 9
    dtoi 88, -9

    dtoi 91, 12
    dtoi 92, -12
    dtoi 93, 21
    dtoi 94, -21
    dtoi 95, 19
    dtoi 96, -19
    dtoi 97, 8
    dtoi 98, -8       

    sg_abcdefgh = "abcdefgh"
    sg_12345678 = "12345678"

    sg_menwhite = "PNBRQK"
    sg_menblack = "pnbrqk"

    sg_tobyblack = "-PNBRQK"
    sg_tobywhite = "-pnbrqk"

    dg_movecount1 = 0
    dg_movecount2 = 0
    dg_movecount3 = 0
    dg_movecount4 = 0
    dg_movecount5 = 0
    dg_movecount6 = 0
    dg_movecount7 = 0
    dg_movecount8 = 0

    dg_onecount1 = 0
    dg_onecount2 = 0
    dg_onecount3 = 0
    dg_onecount4 = 0
    dg_onecount5 = 0
    dg_onecount6 = 0
    dg_onecount7 = 0
    dg_onecount8 = 0

    dg_totalmoves1 = 0
    dg_totalmoves2 = 0
    dg_totalmoves3 = 0
    dg_totalmoves4 = 0
    dg_totalmoves5 = 0
    dg_totalmoves6 = 0
    dg_totalmoves7 = 0
    dg_totalmoves8 = 0

    dg_totalmatescount = 0
    sg_score = sg_nothing
ends sub_begin_initialize


subr sub_board
'updated 2002/10/05
    vari d_any, s_any, d_dot, s_dot
    vari s_rank, d_rank, d_file, s_left
    vari s_board

    s_board = sg_pass1
    dch$ s_left, 32, 10
    
    $out sg_in1
    dift dg_fileout = 1: fapp d_any, sg_fileout, sg_in1

    $out sg_in2
    dift dg_fileout = 1: fapp d_any, sg_fileout, sg_in2

    $out sg_dates
    dift dg_fileout = 1: fapp d_any, sg_fileout, sg_dates
    'from White's side
    d_rank = 8
    dwhi d_rank >= 1

        s_rank = s_left
	  d_file = 1
	  dwhi d_file <= 8

		d_dot = d_file * 10 + d_rank + 100
		$cut s_dot, s_board, d_dot, 1
		$app s_rank, s_dot + " "

		dinc d_file
	  endw

        $out s_rank
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_rank

        ddec d_rank
    endw 
ends sub_board


subr sub_process
'updated 2008/02/03, 2005/10/08, 2003/10/06
    vari s_any, d_any, s_dot, d_dot
    vari d_seconds, d_minutes, s_board, d_loop, s_date

    $dat s_any
    $cut s_any, s_any, 1, 20
    $app s_any, ", file=" + sg_fileout
    $out s_any
    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

    'show the board
    sg_pass1 = sg_board0
    sub_board

    dsec d_seconds

    dg_ply = 0
    s_board = sg_board0
    sg_pass1 = s_board
    sub_wmove

    dsec d_any
    d_seconds = d_any - d_seconds
    d_minutes = d_seconds / 60
    $dat s_date
    $cut s_date, s_date, 1, 20

    d_loop = 1
    dwhi d_loop = 1
	  sg_pass1 = sg_board0
	  sub_board

	  $out sg_in1
	  dift dg_fileout = 1: fapp d_any, sg_fileout, sg_in1

	  $out sg_in2
	  dift dg_fileout = 1: fapp d_any, sg_fileout, sg_in2
 
        'output results
        ded$ s_any, dg_totalmoves1, 9, 0
        s_any = "total 1-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves2, 9, 0
        s_any = "total 2-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves3, 9, 0
        s_any = "total 3-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves4, 9, 0
        s_any = "total 4-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves5, 9, 0
        s_any = "total 5-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves6, 9, 0
        s_any = "total 6-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves7, 9, 0
        s_any = "total 7-ply positions = " + s_any + " *** value"
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmoves8, 9, 0
        s_any = "total 8-ply positions = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        ded$ s_any, dg_totalmatescount, 9, 0
        s_any = "total 7-ply mates     = " + s_any
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        dsec d_any
        d_seconds = d_any - d_seconds

        s_any = "The solution follows:"
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        'output all of the solutions
        d_dot = 1
        dwhi d_dot <= dg_solutionindex
            ito$ s_dot, d_dot
	      s_any = "Solution=" + s_dot

	      $out s_any
	      dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

	      dinc d_dot
        endw

        dsys d_any, 1
        dsys d_dot, 2
        ded$ s_any, d_any, 0, 0
        ded$ s_dot, d_dot, 0, 0
        $out "memory=" + s_any + ", lines=" + s_dot

        ded$ s_any, d_minutes, 9, 3
	  s_any = "minutes = " + s_any + ", " + s_date
	  $out s_any
	  dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

        $inp s_any, "return, * to end"
	  $ift s_any = "*": dinc d_loop
    endw
ends sub_process


subr sub_wmove
'updated 2002/03/02
    'White move
    vari d_any, s_any, d_dot, s_dot
    vari s_board, d_movefrom, s_moveman, d_value

    s_board = sg_pass1

    dinc dg_ply

    d_value = 2
    d_movefrom = 111
    dwhi d_movefrom <= 188

	  $cut s_moveman, s_board, d_movefrom, 1
	  $lok d_any, sg_menwhite, 1, s_moveman

	  dift d_any > 0
	      dg_pass1 = d_movefrom
	      sg_pass1 = s_board

		$ift s_moveman = "P": sub_wpawn
		$ift s_moveman = "N": sub_wknight
		$ift s_moveman = "B": sub_wbishop
		$ift s_moveman = "R": sub_wrook
		$ift s_moveman = "Q": sub_wqueen
		$ift s_moveman = "K": sub_wking
	  endi

	  dinc d_movefrom
    endw
    ddec dg_ply
ends sub_wmove


subr sub_wpawn
'updated 2002/03/02
    'White Pawn move
    vari d_any, s_any, d_dot, s_dot
    vari s_board, d_movefrom, d_moveto, s_moveto
    vari s_promote
    vari d_index, d_delta, d_torank

    d_movefrom = dg_pass1
    s_board = sg_pass1

    'one move forward
    d_moveto = d_movefrom + 1
    d_torank = d_moveto % 10
    $cut s_moveto, s_board, d_moveto, 1

    $ift s_moveto = "-"
	  dift d_torank = 8
		s_promote = "N"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "N"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "N"
	      sub_test_wmove

		s_promote = "B"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "B"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "B"
	      sub_test_wmove

		s_promote = "R"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "R"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "R"
	      sub_test_wmove

		s_promote = "Q"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "Q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "Q"
	      sub_test_wmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "P"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto 
	      sub_test_wmove
	  endi

	  'two moves forward
	  d_any = d_movefrom % 10

	  dift d_any = 2
            d_moveto = d_movefrom + 2
            $cut s_moveto, s_board, d_moveto, 1

            $ift s_moveto = "-"
	          sg_pass1 = s_board
	          $rep sg_pass1, d_moveto, "P"
	          $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "P" + d_movefrom + d_moveto 
	          sub_test_wmove
		endi
	  endi
    endi

    'capture 44 to 35
    d_moveto = d_movefrom - 9
    $cut s_moveto, s_board, d_moveto, 1
    $lok d_any, sg_menblack, 1, s_moveto

    dift d_any > 0
	  dift d_torank = 8
		s_promote = "N"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "N"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "N"
	      sub_test_wmove

		s_promote = "B"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "B"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "B"
	      sub_test_wmove

		s_promote = "R"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "R"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "R"
	      sub_test_wmove

		s_promote = "Q"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "Q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "Q"
	      sub_test_wmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "P"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto
	      sub_test_wmove
	  endi
    endi

    'capture 44 to 55
    d_moveto = d_movefrom + 11
    $cut s_moveto, s_board, d_moveto, 1
    $lok d_any, sg_menblack, 1, s_moveto

    dift d_any > 0
	  dift d_torank = 8
		s_promote = "N"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "N"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "N"
	      sub_test_wmove

		s_promote = "B"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "B"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "B"
	      sub_test_wmove

		s_promote = "R"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "R"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "R"
	      sub_test_wmove

		s_promote = "Q"
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "Q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto + "Q"
	      sub_test_wmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "P"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "P" + d_movefrom + d_moveto
	      sub_test_wmove
	  endi
    endi
ends sub_wpawn


subr sub_wknight
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 91
    dwhi d_index <= 98
	  itod d_delta, d_index
	  d_moveto = d_movefrom + d_delta

	  $cut s_moveto, s_board, d_moveto, 1
	  $lok d_any, sg_tobywhite, 1, s_moveto

	  dift d_any > 0
		sg_pass1 = s_board
		$rep sg_pass1, d_moveto, "N"
		$rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "N" + d_movefrom + d_moveto
		sub_test_wmove
	  endi

	  dinc d_index
    endw
ends sub_wknight


subr sub_wbishop
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 85
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobywhite, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "B"
		    $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "B" + d_movefrom + d_moveto
		    sub_test_wmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_wbishop


subr sub_wrook
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 84
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobywhite, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "R"
		    $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "R" + d_movefrom + d_moveto
		    sub_test_wmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_wrook


subr sub_wqueen
'updated 2000/09/25
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobywhite, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "Q"
		    $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "Q" + d_movefrom + d_moveto
		    sub_test_wmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_wqueen


subr sub_wking
'updated 2000/09/25
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom + d_delta

	  $cut s_moveto, s_board, d_moveto, 1
	  $lok d_any, sg_tobywhite, 1, s_moveto

	  dift d_any > 0
		sg_pass1 = s_board
		$rep sg_pass1, d_moveto, "K"
		$rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "K" + d_movefrom + d_moveto
		sub_test_wmove
	  endi

	  dinc d_index
    endw
ends sub_wking


subr sub_test_wmove
'updated 2008/02/03, 2003/10/11
    vari d_any, s_any, d_dot, s_dot, s_out
    vari s_board, s_lastmove, d_bincheck, d_testmore

    d_testmore = 1

    s_lastmove = sg_pass2
    s_board = sg_pass1
    sub_wincheck
    dift dg_pass1 = 1: dinc d_testmore

    dift dg_ply = 3
	  dift dg_value3 = 1: dinc d_testmore
    endi
    dift dg_ply = 5
	  dift dg_value5 = 1: dinc d_testmore
    endi
    dift dg_ply = 7
	  dift dg_value7 = 1: dinc d_testmore
    endi


    dift d_testmore = 1
	  'is black in check
	  sg_pass1 = s_board
	  sub_bincheck
	  d_bincheck = dg_pass1

	  'K151161
	  sg_pass1 = s_lastmove
	  sub_to_algebra
	  s_lastmove = sg_pass1

	  dift dg_ply = 1
		sg_move1 = s_lastmove
		dift dg_movestoshow > 0
		    $dat s_any
		    $cut s_any, s_any, 1, 20
		    s_out = sg_number + " " + sg_move1 + " " + s_any
		    $out s_out
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_out
		endi

		dinc dg_movecount1
		dinc dg_totalmoves1

		'get black move2
		dg_value2 = 2
		dg_movecount2 = 0
		sg_pass1 = s_board
		sub_bmove

		dift dg_movecount2 = 0
		    dift d_bincheck <> 1: dg_value2 = 1
		endi

		dift dg_movecount1 = 1
		    dift dg_fileout = 1: fapp d_any, sg_fileout, sg_in1
		endi

	      s_any = sg_move1 + " " + sg_move2 
		$out s_any
		dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

	      s_any = "p2=" + dg_onecount2 
	      $app s_any, ", p3=" + dg_onecount3 
	      $app s_any, ", p4=" + dg_onecount4  
	      $app s_any, ", p5=" + dg_onecount5
	      $app s_any, ", p6=" + dg_onecount6
	      $app s_any, ", p7=" + dg_onecount7
	      $app s_any, ", p8=" + dg_onecount8
		$app s_any, ", m7=" + dg_matescount7

	      $out s_any
		dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

		dg_onecount2 = 0
		dg_onecount3 = 0
		dg_onecount4 = 0
		dg_onecount5 = 0
		dg_onecount6 = 0
		dg_onecount7 = 0
		dg_onecount8 = 0
		dg_matescount7 = 0

		dg_value1 = 2
		dift dg_value2 <> 1: dg_value1 = 1

		dift dg_value1 = 1
		    s_any = sg_move1 + " wins"
		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any

		    dinc dg_solutionindex
		    $toi dg_solutionindex, sg_move1
		endi
	  endi
	  dift dg_ply = 3
		sg_move3 = s_lastmove
		dift dg_movestoshow > 2
		    s_any = sg_move1 + " " + sg_move2 + " " + sg_move3
		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount3
		dinc dg_onecount3
		dinc dg_totalmoves3

		'get black move4
		dg_value4 = 2
		dg_movecount4 = 0
		sg_pass1 = s_board
		sub_bmove

		dift dg_movecount4 = 0
		    dift d_bincheck <> 1: dg_value4 = 1
		endi

		dift dg_value4 <> 1: dg_value3 = 1
	  endi
	  dift dg_ply = 5
		sg_move5 = s_lastmove
		dift dg_movestoshow > 4
		    s_any = sg_move1 + " " + sg_move2 + " " + sg_move3
		    $app s_any, " " + sg_move4 + " " + sg_move5

		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount5
		dinc dg_onecount5
		dinc dg_totalmoves5

		'get black move6
		dg_value6 = 2
		dg_movecount6 = 0
		sg_pass1 = s_board
		sub_bmove

		dift dg_movecount6 = 0
		    dift d_bincheck <> 1: dg_value6 = 1
		endi

		dift dg_value6 <> 1: dg_value5 = 1
	  endi
	  dift dg_ply = 7
		sg_move7 = s_lastmove
		dift dg_movestoshow > 6
		    s_any = sg_move1 + " " + sg_move2 + " " + sg_move3
		    $app s_any, " " + sg_move4 + " " + sg_move5
		    $app s_any, " " + sg_move6 + " " + sg_move7

		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount7
		dinc dg_onecount7
		dinc dg_totalmoves7

		dift d_bincheck = 1
		    'get black move8
		    dg_value8 = 2
		    dg_movecount8 = 0
		    sg_pass1 = s_board
		    sub_bmove

		    dift dg_value8 <> 1
			  dg_value7 = 1
			  dinc dg_totalmatescount
			  dinc dg_matescount7
		    endi
		endi
	  endi
    endi
ends sub_test_wmove


subr sub_bmove
'updated 2002/03/02
    'board is s_board
    vari d_any, s_any, d_dot, s_dot
    vari s_board, d_movefrom, s_moveman

    s_board = sg_pass1

    dinc dg_ply

    d_movefrom = 111
    dwhi d_movefrom <= 188
	  $cut s_moveman, s_board, d_movefrom, 1
	  $lok d_any, sg_menblack, 1, s_moveman
	  dift d_any > 0
		dg_pass1 = d_movefrom
		sg_pass1 = s_board

		$ift s_moveman = "p": sub_bpawn
		$ift s_moveman = "n": sub_bknight
		$ift s_moveman = "b": sub_bbishop
		$ift s_moveman = "r": sub_brook
		$ift s_moveman = "q": sub_bqueen
		$ift s_moveman = "k": sub_bking
	  endi

	  dinc d_movefrom
    endw
    ddec dg_ply
ends sub_bmove


subr sub_bpawn
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_torank
    vari s_board, d_movefrom, d_moveto, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    'one move forward
    d_moveto = d_movefrom - 1
    d_torank = d_moveto % 10
    $cut s_moveto, s_board, d_moveto, 1

    $ift s_moveto = "-"
	  dift d_torank = 1
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "n"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "n"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "b"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "b"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "r"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "r"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "q"
	      sub_test_bmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "p"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto
	      sub_test_bmove
	  endi

	  'two moves forward
	  d_any = d_movefrom % 10

	  dift d_any = 7
            d_moveto = d_movefrom - 2
            $cut s_moveto, s_board, d_moveto, 1

            $ift s_moveto = "-"
	          sg_pass1 = s_board
	          $rep sg_pass1, d_moveto, "p"
	          $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "p" + d_movefrom + d_moveto
	          sub_test_bmove
		endi
	  endi
    endi

    'capture 45 to 34
    d_moveto = d_movefrom - 11
    $cut s_moveto, s_board, d_moveto, 1
    $lok d_any, sg_menwhite, 1, s_moveto

    dift d_any > 0
	  dift d_torank = 1
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "n"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "n"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "b"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "b"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "r"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "r"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "q"
	      sub_test_bmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "p"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto
	      sub_test_bmove
	  endi
    endi

    'capture 45 to 54
    d_moveto = d_movefrom + 9
    $cut s_moveto, s_board, d_moveto, 1
    $lok d_any, sg_menwhite, 1, s_moveto

    dift d_any > 0
	  dift d_torank = 1
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "n"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "n"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "b"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "b"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "r"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "r"
	      sub_test_bmove

	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "q"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto + "q"
	      sub_test_bmove
	  else
	      sg_pass1 = s_board
	      $rep sg_pass1, d_moveto, "p"
	      $rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "p" + d_movefrom + d_moveto
	      sub_test_bmove
	  endi
    endi
ends sub_bpawn


subr sub_bknight
'updated 2002/03/02
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 91
    dwhi d_index <= 98
	  itod d_delta, d_index
	  d_moveto = d_movefrom + d_delta

	  $cut s_moveto, s_board, d_moveto, 1
	  $lok d_any, sg_tobyblack, 1, s_moveto

	  dift d_any > 0
		sg_pass1 = s_board
		$rep sg_pass1, d_moveto, "n"
		$rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "n" + d_movefrom + d_moveto 
		sub_test_bmove
	  endi

	  dinc d_index
    endw
ends sub_bknight


subr sub_bbishop
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 85
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobyblack, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "b"
		    $rep sg_pass1, d_movefrom, "-"
 		    sg_pass2 = "b" + d_movefrom + d_moveto 
		    sub_test_bmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_bbishop


subr sub_brook
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 84
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobyblack, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "r"
		    $rep sg_pass1, d_movefrom, "-"
  		    sg_pass2 = "r" + d_movefrom + d_moveto 
		    sub_test_bmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_brook


subr sub_bqueen
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta, d_loop
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom

	  d_loop = 1
	  dwhi d_loop = 1
	      d_moveto = d_moveto + d_delta

	      $cut s_moveto, s_board, d_moveto, 1
	      $lok d_any, sg_tobyblack, 1, s_moveto

		dift d_any > 1: dinc d_loop
	      dift d_any > 0
		    sg_pass1 = s_board
		    $rep sg_pass1, d_moveto, "q"
		    $rep sg_pass1, d_movefrom, "-"
		    sg_pass2 = "q" + d_movefrom + d_moveto 
		    sub_test_bmove
		else
		    dinc d_loop
		endi
	  endw

	  dinc d_index
    endw
ends sub_bqueen


subr sub_bking
'updated 2002/03/02
    'board is in s_board, d_movefrom
    vari d_any, s_any, d_dot, s_dot
    vari d_index, d_delta
    vari s_board, d_moveto, d_movefrom, s_moveto

    s_board = sg_pass1
    d_movefrom = dg_pass1

    d_index = 81
    dwhi d_index <= 88
	  itod d_delta, d_index
	  d_moveto = d_movefrom + d_delta

	  $cut s_moveto, s_board, d_moveto, 1
	  $lok d_any, sg_tobyblack, 1, s_moveto

	  dift d_any > 0
		sg_pass1 = s_board
		$rep sg_pass1, d_moveto, "k"
		$rep sg_pass1, d_movefrom, "-"
		sg_pass2 = "k" + d_movefrom + d_moveto 
		sub_test_bmove
	  endi

	  dinc d_index
    endw
ends sub_bking


subr sub_test_bmove
'updated 2002/03/06
    vari d_any, s_any, d_dot, s_dot
    vari s_board, s_lastmove, d_wincheck, d_testmore

    d_testmore = 1

    s_lastmove = sg_pass2
    s_board = sg_pass1
    sub_bincheck
    dift dg_pass1 = 1: dinc d_testmore

    dift d_testmore = 1
	  dift dg_ply = 2
		dift dg_value2 = 1: dinc d_testmore
	  endi
	  dift dg_ply = 4
		dift dg_value4 = 1: dinc d_testmore
	  endi
	  dift dg_ply = 6
		dift dg_value6 = 1: dinc d_testmore
	  endi
    endi
    dift d_testmore = 1
	  'k158157
	  sg_pass1 = s_lastmove
	  sub_to_algebra
	  s_lastmove = sg_pass1

	  dift dg_ply = 2
		sg_move2 = s_lastmove
		dift dg_movestoshow > 1
		    s_any = sg_move1 + " " + sg_move2
		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount2
		dinc dg_onecount2
		dinc dg_totalmoves2

		'get white's move3
		dg_movecount3 = 0
		dg_value3 = 2
		sg_pass1 = s_board
	      sub_wmove

		dift dg_value3 <> 1: dg_value2 = 1
	  endi
	  dift dg_ply = 4
		sg_move4 = s_lastmove
		dift dg_movestoshow > 3
		    s_any = sg_move1 + " " + sg_move2 + " " 
		    $app s_any, sg_move3 + " " + sg_move4

		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount4
		dinc dg_onecount4
		dinc dg_totalmoves4

		'get white's move5
		dg_movecount5 = 0
		dg_value5 = 2
		sg_pass1 = s_board
	      sub_wmove

		dift dg_value5 <> 1: dg_value4 = 1
	  endi
	  dift dg_ply = 6
		sg_move6 = s_lastmove
		dift dg_movestoshow > 5
		    s_any = sg_move1 + " " + sg_move2 + " " 
		    $app s_any, sg_move3 + " " + sg_move4
		    $app s_any, " " + sg_move5 + " " + sg_move6

		    $out s_any
		    dift dg_fileout = 1: fapp d_any, sg_fileout, s_any
		endi

		dinc dg_movecount6
		dinc dg_onecount6
		dinc dg_totalmoves6

		'get white's move7
		dg_movecount7 = 0
		dg_value7 = 2
		sg_pass1 = s_board
	      sub_wmove

		dift dg_value7 <> 1: dg_value6 = 1
	  endi
	  dift dg_ply = 8
		dg_value8 = 1
		dinc dg_movecount8
		dinc dg_onecount8
		dinc dg_totalmoves8
	  endi
    endi
ends sub_test_bmove


subr sub_wincheck
'updated 2000/09/26
    'is White in check
    vari d_any, s_any, d_dot, s_dot
    vari d_loop, d_count
    vari d_index, d_delta, d_wking, d_wincheck
    vari s_board, d_square, s_square

    s_board = sg_pass1

    d_wincheck = 2
    $lok d_wking, s_board, 111, "K"

    'check by knight
    d_index = 91

    dwhi d_index <= 98
	  itod d_delta, d_index

	  d_square = d_wking + d_delta
	  $cut s_square, s_board, d_square, 1
	  $ift s_square = "n": d_wincheck = 1

	  dinc d_index
    endw

    'check by Pawn, bishop, rook, queen or king
    d_index = 81

    dwhi d_index <= 88
	  itod d_delta, d_index

	  'is white in check
	  d_square = d_wking
	  d_count = 0
	  d_loop = 1

	  dwhi d_loop = 1
		dinc d_count
		d_square = d_square + d_delta
		$cut s_square, s_board, d_square, 1
		$ift s_square <> "-": dinc d_loop
	  endw
	  dift d_count = 1
		'Black Pawn or Black King
		$ift s_square = "k": d_wincheck = 1

		'how about a Pawn
		$ift s_square = "p"
		    '54 by 45 or 65
		    dift d_delta = -9: d_wincheck = 1
		    dift d_delta = 11: d_wincheck = 1
		endi 
	  endi
	  $ift s_square = "q": d_wincheck = 1
	  $ift s_square = "r"
		dift d_index <= 84: d_wincheck = 1
	  endi
	  $ift s_square = "b"
		dift d_index >= 85: d_wincheck = 1
	  endi

	  dinc d_index
    endw
    dg_pass1 = d_wincheck
ends sub_wincheck


subr sub_bincheck
'updated 2000/09/26
    'is Black in check
    vari d_any, s_any, d_dot, s_dot
    vari d_loop, d_count
    vari d_index, d_delta, d_bking, d_bincheck
    vari s_board, d_square, s_square

    s_board = sg_pass1

    d_bincheck = 2
    $lok d_bking, s_board, 111, "k"

    'check by knight
    d_index = 91

    dwhi d_index <= 98
	  itod d_delta, d_index

	  d_square = d_bking + d_delta
	  $cut s_square, s_board, d_square, 1
	  $ift s_square = "N": d_bincheck = 1

	  dinc d_index
    endw

    'check by Pawn, bishop, rook, queen or king
    d_index = 81

    dwhi d_index <= 88
	  itod d_delta, d_index

	  'is Black in check
	  d_square = d_bking
	  d_count = 0
	  d_loop = 1

	  dwhi d_loop = 1
		dinc d_count
		d_square = d_square + d_delta
		$cut s_square, s_board, d_square, 1
		$ift s_square <> "-": dinc d_loop
	  endw
	  dift d_count = 1
		'White Pawn or White King
		$ift s_square = "K": d_bincheck = 1

		'how about a Pawn, 45 by 34, 45 by 54
		$ift s_square = "P"
		    '55 by 44 or 64
		    dift d_delta = -11: d_bincheck = 1
		    dift d_delta = 9: d_bincheck = 1
		endi 
	  endi
	  $ift s_square = "Q": d_bincheck = 1
	  $ift s_square = "R"
		dift d_index <= 84: d_bincheck = 1
	  endi
	  $ift s_square = "B"
		dift d_index >= 85: d_bincheck = 1
	  endi

	  dinc d_index
    endw
    dg_pass1 = d_bincheck
ends sub_bincheck


subr sub_to_algebra
'updated 2002/03/02
    vari d_any, s_any, d_dot, s_dot
    vari s_lastmove

    s_lastmove = sg_pass1

    'K151162
    $del s_lastmove, 2, 1

    'K51162
    $rep s_lastmove, 4, "-"

    'K51-62
    $cut s_any, s_lastmove, 2, 1
    $tod d_any, s_any
    $cut s_any, sg_abcdefgh, d_any, 1
    $rep s_lastmove, 2, s_any

    'Ke1-62
    $cut s_any, s_lastmove, 5, 1
    $tod d_any, s_any
    $cut s_any, sg_abcdefgh, d_any, 1
    $rep s_lastmove, 5, s_any
    'Ke1-f2

    sg_pass1 = dg_ply + "." + s_lastmove
ends sub_to_algebra


subr sub_rotate_right
'updated 2002/04/20
'rotate the board to the right
    vari d_any, s_any, d_dot, s_dot
    vari d_loop
    vari s_board1, s_board2, d_file1, d_rank1, d_file2, d_rank2

    s_board1 = sg_pass1
    dch$ s_board2, 32, 222
    d_file1 = 1
    dwhi d_file1 <= 8
	  d_rank1 = 1
	  dwhi d_rank1 <= 8
		'file 1 becomes rank 8
		'file 2 becomes rank 7
		'file 8 becomes rank 1
		d_rank2 = 9 - d_file1
		d_file2 = d_rank1

		d_dot = 10 * d_file1 + d_rank1 + 100
		$cut s_dot, s_board1, d_dot, 1

		d_dot = 10 * d_file2 + d_rank2 + 100
		$rep s_board2, d_dot, s_dot

		dinc d_rank1
	  endw
	  dinc d_file1
    endw
    sg_pass1 = s_board2
ends sub_rotate_right

subr sub_speedquick
'updated 2008/02/23
    vari d_any, d_dot, d_time

    dsec d_time
    d_dot = 10 ^ 6 * 2
    d_any = 0
    dwhi d_any < d_dot
	  dinc d_any
    endw
    dsec d_any
    dg_pass1 = d_any - d_time
ends sub_speedquick