
3 Jan'09
Just noticed the lines:
  
               STATES(NODE,5) := IF PARTIAL THEN 1 ELSE 0 ;
               STATES(NODE,2) := 1 ;
               NODETO(NODE,0) := 0 ;
               STATES(NODE,4) := 1 ;
               PARENT(NODE) := packer*LENGTH ;
                 Comment should that be LEVEL or LENGTH ??? ;
in procedure SACR_TREE
and wonder why NODETO(NODE<0) is initialized?
See also:
PROCEDURE RESTORESTATE (INTEGER VALUE NODE) ;
BEGIN
  INTEGER J, J1 ;
  K := STATES(NODE,1) ;
  PLEX := STATES(NODE,2) ;
  CAPT_T := STATES(NODE,3) ;
  TOT_S := states(node,4) ; comment was TOT_S := NODETO(NODE,4) ;
  PART := STATES(NODE,5) ;
  A_SCR := STATES(NODE,6) ;
  UPPER := STATES(NODE,7) ;
  HASH := STATES(NODE,T_SIZE) ;
  RESTORE(NODE) ;
END OF_RESTORESTATES ;

No action taken at the moment

---------------------------------------------------------
5 Jan'09

Modified DEADTREE from
  COMMENT WRITE("DEADTREE", REPLY, SAVEL, ORIGIN, NODETO(ORIGIN,0),
                 NODETO(ORIGIN,REPLY)) ;
  PREVSCR := OLDSCR ;
  IF REPLY <= 0 OR REPLY > NODETO(ORIGIN,0)
       OR NODETO(ORIGIN,REPLY) <= 0
  THEN SAVEL := 0 ;
  IF (SAVEL > 0)
  THEN BEGIN
  
to

  WRITE("ENTER DEADTREE", REPLY, SAVEL, ORIGIN, NODETO(ORIGIN,0)) ;
  PREVSCR := OLDSCR ;
  IF REPLY <= 0 OR REPLY > NODETO(ORIGIN,0)
       OR NODETO(ORIGIN,REPLY) <= 0
  THEN begin
    SAVEL := 0 ;
    if reply > max_wid then writeon(reply, "reply > max_wid", max_wid) ;
  end ;
  IF (SAVEL > 0)
  THEN BEGIN
    writeon(NODETO(ORIGIN,REPLY)) ;
 
 and in the process noticed that REPLY had the value of WSIZE after the "PLAY" command 
 was entered.   This because NULLMOVE has been set true in order to invoke "COMPUTER" to generate 
 a move.  This has led to a change in "SEARCH" where DEADTREE and INIT_TREE are called.
 from
   IF EXAMINE OR ~CBOTH AND (WHO OR FLAG(1) = 0)
  THEN IF (ORIGIN > 0)
       THEN DEADTREE(REPLY)
       ELSE INIT_TREE ;
       
to
  IF EXAMINE OR ~CBOTH AND (WHO OR FLAG(1) = 0) and reply ~= wsize
  THEN IF (ORIGIN > 0)
       THEN DEADTREE(REPLY)
       ELSE INIT_TREE ;
       
we do not want to do either deadtree or init_tree in this forced play case.
It will be interesting to see if this has any effect on the outstanding nodecount collection
problem.
----------------------------------

5Jan'09
Error message in DEBUG mode.

Enter the board (in quasi Forsythe notation)
R1BQK1NRPP3PPP8N3P33P4888-8881P62B54P3P2N1PPPR2QK1NR-                         FTTFTTFNC3-A4            R O 22 ( 9)
 Rb ::    Qb Kb :: Nb Rb
 Pb    :: Nb :: Pb Pb Pb
    ::    :: Pb ::    ::
 ::    Bb Pw ::    ::
 Nw Pb    :: Pw ::    ::
 ::    ::    ::    ::
 Pw Pw    ::    Pw Pw Pw
 Rw    Bw QW KW    Nw Rw
Jan 05 2009 08-AP9.8 BLACK'S MOVE  9.
Entering INIT_TREE
   DEBUG     mode
Enter your move or type PLAY
BLACK'S MOVE    9 

qf6
288355120 63 No more book
Entering INIT_TREE
a4c5 d7c5 d5d6 -99999  863
New candidate PV   0    2  863  986  986
g1h3 f6g6 d1c2  862  986
PAB InfiniteError-loop in EXPAND  862  312 99999  312 -381   TRUE    2    1  FALSE   TRUE    3    7    0
New candidate PV   2    3  863  873  873
g1f3 f6g6 d5d6  862  873
PAB InfiniteError-loop in EXPAND  862  346 99999  346  293   TRUE    2    1  FALSE   TRUE    3    7    0
PAB InfiniteError-loop in EXPAND  862  627 99999  346  293   TRUE    3    2  FALSE   TRUE    3    7    0
 863  788 :  863  782  293
-99999 99999 : a4c5 g1h3 g1f3
2415 SCORED   70 /  71 POSNS.   1 /   3  DEPTH =   3   34    0
                        ..............
response:
Change error message in EXPAND to read:

            WRITE ("PAB InfiniteError-loop in EXPAND.  Inadequate nodespace. ",
                    LOWER, T_SCR, HIGHER, b_scr, l_scr, again, ip, cnt,
                    exp, princvar, level, deep, deeper) ;
                    
Special problem in Debug mode (only 10-node workspace), but could be a problem anytime.
No real resolution, and we ensure that the infinite loop itself does not occur.
--------------------------------------

12 Jan'09
In SACR_TREE have:

               STATES(NODE,5) := IF PARTIAL THEN 1 ELSE 0 ;
               STATES(NODE,2) := 1 ;
               NODETO(NODE,0) := 0 ;
               STATES(NODE,4) := 1 ;
               PARENT(NODE) := packer*LENGTH ;
                 Comment should that be LEVEL or LENGTH ??? ;

have decided to change packer*LENGTH
to packer*LEVEL

do not believe this piece of code does anything significant (if indeed the saved numbers
are used at all.

               STATES(NODE,5) := IF PARTIAL THEN 1 ELSE 0 ;
               STATES(NODE,2) := 1 ;
               NODETO(NODE,0) := 0 ;
               STATES(NODE,4) := 1 ;
               PARENT(NODE) := packer*LEVEL ;
                 Comment should that be LEVEL or LENGTH ??? ;
                 
----------------------------------                 ----------------------------
12 Jan'09
The logical procedure DUPLICATE always returns a value of TRUE.  This makes little sense.
Perhaps change:
       GO TO QUIT ;
  END ;
  FINAL := 2 ;
  DUP := DUP + 1 ;
QUIT:

to
       GO TO QUIT ;
  END ;
  duplicate := false ;     comment otherwise DUPLICATE is always TRUE ;
  FINAL := 2 ;
  DUP := DUP + 1 ;
QUIT:

Incredibly this last change has made a sigificant improvement to an endgame position
where the search found one move, but a different move was displayed.
The problem being worked on at the time was the "INCONSISTENT' node count message, and it 
remains a problem.

This is the position that is now played correctly:
badden% awit.o
SPEED defaults:  80 Node space per move   9 moves per position   3 ply per move
Jan 12 2009
Awit, a chess program,
Enter ?8 for control options, STOP to terminate.
New game? (YES or NO)
no
Enter the board (in quasi Forsythe notation)
R7881P61PP53K488+86KP888888+                                                  TFFTFFFRh1              39$L    (50)
    ::    ::    ::    ::
 ::    ::    ::    ::
    ::    KW    ::    ::
 :: Pw Pw    ::    ::
    Pw    ::    ::    ::
 ::    ::    ::    ::
    ::    ::    :: Kb Pb
 Rw    ::    ::    ::
Jan 12 2009 08-AP9.8 WHITE'S MOVE 50.
Entering INIT_TREE
   SPEED     mode
Enter your move or type PLAY
WHITE'S MOVE   50 
?lj
CONTINUE (Tracer ?LJ   exit):
play
a1a2 g2h1 b5b6 h1g1 a2h2 -99999 7895
New candidate PV   0    3 7895 8051 8051
c5c6 h2h1 a1h1 g2h1 c6c7 7894 8051
c5c6 h2h1 a1h1 g2h1 c6c7 7894 8051
8051 5754 : 7895 7853 8051 4396 3387 4276 4352 4246 4217
-99999 99999 : c5c6 a1a2 b5b6 d6d5 d6d7 d6e5 d6e6 d6e7 a1a3
3179 SCORED  176 / 177 POSNS.   3 /   9  DEPTH =   3   18    0

Awit's move is:
  50. c6                      
BLACK'S MOVE   50 
--------------------------------------------
13 Jan'09
Spent about a week trying to eliminate or understand the use of REUSE.  Only seemed to make the 
program worse.  Went back to the 3 Jan'09 version and implemented only:

dummy4 as a complementing variable

exiting as a variable that can be set to cause a quick exit

In initialize added:
  dummy4 := false ;
  write("SPEED defaults:", maxtree, "Positions per move.",
        width, "Moves per position.", maxlev, "Ply per move.") ;
  GO TO ENTER ;
ENTRY:

In valid_command added:
    end ELSE IF BUFFER(0|6) = "DUMMY4"
             THEN BEGIN
               dummy4 := ~dummy4 ;
               WRITE("dummy4", dummy4) ;
               true
    end else false
    
In procedure MAIN
added:
  INTEGER ARRAY REFTAB(0::MAX_WID+91, 1::91) ;
  logical exiting ;

In COMPUTER added:
    if exiting then tracer(2, "?GK") ;
  END ELSE WRITE("ERROR.  NUM =", NUM, REASON(KTEST)) ;
END OF_COMPUTER ;

In DEADTREE added:
    new_count := MAXTREE - NODECOUNT ;
    exiting := false ;
    
    
------------------------------------------------------
18 Jan'09
After nearly 3 months of on and off work, seem to have resolved the "INCONSISTENT" and
"Node Count Error" discrepancy in management of the GETNODE array.  The problem had many facets
from special case of Mate/Stalemate handling deep in the tree (recyling un-needed node), to
handling of node shifting of getnode--including zeroing of getnode(maxl+1) after the shift.
The main problems were in DEADTREE, TREE, MAKE_SPACE and DISCARD_SUBTREES.  The "DISASTER avoided"
problem seems to have been fixed by better handling of the deep Mate/Stalemate problem in TREE.

In MAKE_SPACE changed
  IF POINT = 0
  THEN POINT := MAXL
  ELSE BEGIN
    LX := POINT + 1 ;
    REUSE := REUSE - POINT  ;
    POINT := 0 ;
    FOR I := LX UNTIL MAXL
    DO BEGIN
      POINT := POINT + 1 ;
      GETNODE(POINT) := GETNODE(I) ;
    END ;
    MAXL := POINT ;
  END ;
to
  comment Perhaps leave getnode, maxl and reuse unchanged if point = 0 ;
  IF point > 0
  THEN BEGIN
    LX := POINT + 1 ;
    REUSE := REUSE - POINT  ;
    POINT := 0 ;
    FOR I := LX UNTIL MAXL
    DO BEGIN
      POINT := POINT + 1 ;
      GETNODE(POINT) := GETNODE(I) ;
      if i > point then
         getnode(i) := 0 ;
    END ;
    MAXL := POINT ;
    getnode(maxl+1) :=  0 ;
    point := 0 ;
    if reuse <= point
    then reuse := maxl ;
  END ;
  
In DISCARD_SUBTREES changed
    IF SAVE_P = 0
    THEN POINT := MAXL
    ELSE BEGIN
      REUSE := REUSE - POINT  ;
      POINT := 0 ;
      FOR I := SAVE_P UNTIL MAXL
      DO BEGIN
        POINT := POINT + 1 ;
        GETNODE(POINT) := GETNODE(I) ;
      END ;
    END ;
    MAXL := POINT ;
    POINT := 0 ;
to
    IF point > 0
    then BEGIN
      REUSE := REUSE - POINT  ;
      POINT := 0 ;
      FOR I := SAVE_P UNTIL MAXL
      DO BEGIN
        POINT := POINT + 1 ;
        GETNODE(POINT) := GETNODE(I) ;
      END ;
    END else point := maxl ;
    MAXL := POINT ;
    POINT := 0 ;
    if reuse <= point
    then reuse := maxl ;
 
In TREE changed from
    IF TEST
    THEN WRITE("(STALE)MATE", LEVEL, B_SCR, FINAL, KTEST, ROOT) ;
    NUM := 0 ;
    IF LEVEL = 1
    THEN GO TO QUIT ;
    POINT := POINT - 1 ;
    NODE := ROOTNODE(LEVEL-1) ;
    NODETO(NODE,NODETO(NODE,0)) := NIL ;
    NODETO(ROOT,0) := -1 ;
    GO TO QUIT ;
to
    IF TEST
    THEN WRITE("(STALE)MATE", LEVEL, B_SCR, FINAL, KTEST, ROOT) ;
    NUM := 0 ;
    IF LEVEL = 1
    THEN GO TO QUIT ;

    if root > 0 then begin
      maxl := maxl + 1 ;
      getnode(maxl) := root ;
    end ;
    getnode(maxl+1) := 0 ;
    NODE := ROOTNODE(LEVEL-1) ;
    NODETO(NODE,NODETO(NODE,0)) := NIL ;
    NODETO(ROOT,0) := -1 ;
    if dummy4 then tracer(1, "?P") ;
    GO TO QUIT 
    
In DEADTREE changed from
  IF (SAVEL > 0)
  THEN BEGIN
    POINT := 0 ;
    FOR I := SAVEL UNTIL MAXL
    DO BEGIN
      POINT := POINT + 1 ;
      GETNODE(POINT) := GETNODE(I) ;
    END ;
                  COMMENT more unused nodes ;
                  COMMENT retrieve current origin ;
    MAXL := POINT + 1 ;
    GETNODE(MAXL) := NODE := ORIGIN ;
to
  IF (SAVEL > 0)
  THEN BEGIN
    POINT := 0 ;
    FOR I := SAVEL UNTIL MAXL
    DO BEGIN
      POINT := POINT + 1 ;
      GETNODE(POINT) := GETNODE(I) ;
      if i > point then
         getnode(i) := 0 ;
    END ;
                  COMMENT more unused nodes ;
                  COMMENT retrieve current origin ;
    MAXL := POINT + 1 ;
    GETNODE(MAXL) := NODE := ORIGIN ;
    point := 0 ;

In DEBUG mode the two position sequences that were of greatest help were:
?6
10 3 0 3
no
7KP2P3P1R63N1P1Q8888-888QP62R4P8R77K-                                         TFFFFFTF4                R E 43 (44)
?lj
play
play
play

or
R4RK1P2P1PPP1P3N26Q18888+88882PB43QPP2PP5PR4R1K+                              TFFFFFTRf1-e1           13=M    (21)
?lj
play
play
play

Also COLLECT changes from
              BEGIN
                MAXL := MAXL + 1 ;
                GETNODE(MAXL) := NODE ;
                STATES(NODE,4) := -ABS(STATES(NODE,4)) ;
to
              BEGIN
                MAXL := MAXL + 1 ;
                GETNODE(MAXL) := NODE ;
                reuse := maxl ;
                STATES(NODE,4) := -ABS(STATES(NODE,4)) ;

Nevertheless node loss continues, though not in debug mode.

--------------------------  version number changed to "08-AP9.9 " -----------------------------
19 Jan'09

In speed mode (default)
no
R4RK1PP1B1PBP3Q2P13P46N1888+84N38881NPBP3PP3PPPR1BQ1RK1+                      TFFFFFTKH1               R O 17 (13)
?lj
Kh1

 
 The following code in TREE fails, as in the example above, when the statemate/mate occurs
 early in the search before any shifting operation has taken place in getnode.
 
    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
    if root > 0 and maxl < maxtree then begin
      maxl := maxl + 1 ;
      getnode(maxl) := root ;
    end ;
    getnode(maxl+1) := 0 ;

revise consistent with original form (returning the node to the front of the list, 
instead of the end) when maxl = maxtree, and root > 0.

    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
    if root > 0 then
    if maxl < maxtree then begin
      maxl := maxl + 1 ;
      getnode(maxl) := root ;
    end else
      point := point - 1 ;;
    getnode(maxl+1) := 0 ;
    NODE := ROOTNODE(LEVEL-1) ;
    
----------------------------------------------------------------------------------
20 Jan'09
Noted DIV / REM inconsistency in INVALIDATE.  Revised from:
  IF NODE > 0 AND NODE <= MAXTREE
  THEN BEGIN
    FOR I := 1 UNTIL NODETO(NODE,0)
    DO begin
      if (nodeto(node,i) <= 0)
      then write("INVALIDATE ", node, nodeto(node,i), alpha, b_scr, beta)
      else
      IF PARENT(NODETO(NODE,I)) DIV packer = NODE
      THEN INVALIDATE(NODETO(NODE,I)) ;
    end ;
    STATES(NODE,2) := 0 ;
  END ;
END OF_INVALIDATE ;

to
  IF NODE > 0 AND NODE <= MAXTREE
  THEN BEGIN
    FOR I := 1 UNTIL NODETO(NODE,0)
    DO begin
      if (nodeto(node,i) > 0) then
      IF PARENT(NODETO(NODE,I)) rem packer = NODE
      THEN INVALIDATE(NODETO(NODE,I)) 
      else
        write("INVALIDATED parent", node, parent(nodeto(node,i))) ;
    end ;
    STATES(NODE,2) := 0 ;
  END ;
END OF_INVALIDATE ;

The change is not substantive, and only affects that case when PAB is FALSE (not default).
----------------------------------------------------------------------------
22 Jan'09
Added the following to EXPAND

        I := IF AGAIN THEN IP + 1
             ELSE 1 ;
for i := nodeto(origin,0) step -1 until 1 do
MARK := MARKTREE(nodeto(origin,i), ORIGIN, packer, 0) ;
write("New Line: ") ;
        WHILE NODEX > 0
        DO BEGIN
            
      
Also revised as:
      IF TEST or dummy4
      THEN WRITE("Using node", NODE, root, old, final, nodeto(node,0),
                  nodeto(root,0), ip, t_nodes, level, point) ;
if dummy4 then write ("Base nodes 1..IP", IP, nodeto(root,0), ":") ;
if dummy4 then
for i:= nodeto(root,0) step -1 until 1 do writeon(nodeto(root,i)) ;
      PARENT(NODE) := ROOT + LEVEL*packer ;
      IF (NODETO(ROOT,0) < IP)
      THEN NODETO(ROOT,0) := IP ;
      
This shows:
that node 10 is eliminated, but not restored to getnode array

      
The following version shows no problem with this piece of code (i.e. problem is elsewhere):

      PARENT(NODE) := ROOT + LEVEL*packer ;
      IF (NODETO(ROOT,0) < IP)
      THEN NODETO(ROOT,0) := IP
      else if nodeto(root,ip) > 0 and nodeto(root,ip) ~= node
           then write("Using Error, replacing node", nodeto(root,ip), node);
      NODETO(ROOT,IP) := NODE ;
      
In MAKE_SPACE

revise test to read "maxl - point"

         THEN WRITE("FULL PURGE", ROOT, LX, MAXL) ;
       END ELSE IF (MAXL - point <= EST) AND (LX ~= REPLY) AND (LX ~= PATH)
                THEN BEGIN
                
                
  IF (IP <= MIN) AND (REPLY > 0) AND (MAXL - point <= EST)
      AND (LEVEL <= 2 OR LEVEL = 3 AND IP < 2 OR INCHECK)
  THEN IF REPLY ~= PATH

              
         IF TEMP > 0
         THEN FOR LX := NODETO(TEMP,0) STEP -1 UNTIL 1
              DO IF MAXL - point <= EST
                 THEN BEGIN
                   COLLECT(NODETO(TEMP,LX), TEMP) ;
                   NODETO(TEMP,LX) := -1 ;
                   IF TEST or dummy4
                   THEN WRITEON(LX, MAXL) ;
                 END ;
                

-------------------------------------------------------------
24 Jan'09
In Procedure TERMINATE it seems that the global variable EST is being confused with the local
variable EST_SRC, in that EST (number of nodes in subtree) is being used for EST_SCR (expected 
evaluation value).

Go through procedure and change EST to EST_scr

Now get an ALPHA_BETA error, but still the procedure-wide change seems right.
--------------------------------------------------------------------
25 Jan'09
Modified SEARCH
from
    IF LENGTH > 1 AND (WHO OR FLAG(1) = 0)
    THEN IF B_SCR ~= BEST OR B_SCR < ALPHA OR B_SCR > BETA
         THEN BEGIN
           IF B_SCR > ALPHA AND B_SCR < BETA OR REPLY <= 0
           THEN WRITE("ALPHA-BETA ERROR: reply -ve? ", B_SCR, BEST, REPLY,
             ALPHA, BETA)
           ELSE BEGIN
             GAMETREE(ORIGIN, 1, 1) ;
             COMMENT LISTMOVES ;
           END ;
to 
    IF LENGTH > 1 AND (WHO OR FLAG(1) = 0)
    THEN IF B_SCR ~= BEST OR B_SCR < ALPHA OR B_SCR > BETA
         THEN BEGIN
           IF REPLY <= 0
           THEN WRITE("ALPHA-BETA ERROR: reply -ve? ", B_SCR, BEST, REPLY,
             ALPHA, BETA)
           ELSE BEGIN
             GAMETREE(ORIGIN, 1, 1) ;
             COMMENT LISTMOVES ;
           END ;
           
           
----------------------------------
25 Jan'09
See if all following reset of nodeto(*,*) := 0/NIL are safe

badden% grep 'NODETO(.*,.*) := 0' awit.a
         THEN NODETO(NODE,I) := 0 ;

                 NODETO(ROOT, S) := 0 ;
                 NODETO(ROOT, S) := 0 ;

      NODETO(ROOT,IP) := 0 ;
      NODETO(ROOT,IP) := 0 ;

badden% grep 'NODETO(.*,.*) := NIL' awit.a
        NODETO(ROOT,1) := NIL ;

          THEN NODETO(ROOT,IP) := NIL ;
      NODETO(ROOT,MIN) := NIL ;
    NODETO(NODE,NODETO(NODE,0)) := NIL ;
    
-------------------------------------------
For consistency  set node retrieval code in TREE to:

    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
    if root > 0 then
       if maxl < maxtree then begin
         maxl := maxl + 1 ;
         getnode(maxl) := root ;
       end else begin
         getnode(point) := root ;
         point := point - 1 ;
       end ;
       getnode(maxl+1) := 0 ;
    NODE := ROOTNODE(LEVEL-1) ;
    comment if dummy4 then ;
    if root ~= nodeto(node,nodeto(node,0)) then
       write("In Tree returned root error? node/nodeto(node,0)/..>0/root", node,
             nodeto(node,0), nodeto(node,nodeto(node,0)), root, point, maxl) ;
    NODETO(NODE,NODETO(NODE,0)) := NIL ;
--------------------------------------------------------
25 Jan'09
    
In an attempt to unify self-play and repeated play modes:
In SEARCH add the lines showm in lower case (basically do INIT_TREE every 3-ply):
  IF EXAMINE OR ~CBOTH AND (WHO OR FLAG(1) = 0) and reply ~= wsize
  THEN IF (ORIGIN > 0)
       THEN DEADTREE(REPLY)
       ELSE INIT_TREE ;
  comment Kludge to help repeat outcomes in self-play mode ;
  if cboth and count rem 3 = 0
  then init_tree ;
  IF TOURNAMENT
  
           
--------------------------------saved awit.a to awit-12.a-------------------
26Jan'09
A feature of this current version is that INIT_TREE is called every 3-ply in self-play mode.
It is felt this will make it easier to repeat tests for problems identified in self-play.

However, this is not proving to be obviously the case.

Seeing message "Inconsistent" with parent(node) value of 29999
a total impossibility, since it implies a node of "9999"

Awit's move is:
  28.   ... Nc2-b4                  
Inconsistent  15 29999 20000

New Line: a5b6 b4d3 b6a7 e4e8 b2f6 -99999 1248
New candidate PV   0    2 1248 1624 1624
New Line: b2f6 b4d3 a5b6 1247 1624
New Line: b2f6 b4d3 a5b6 a7b6 b3d2 1247 1650
1650  609 : 1248 1650  223  237 -44445
-99999 99999 : b2f6 a5b6 d3d2 d3d1 d3c3
2684 SCORED   77 /  88 POSNS.   2 /   5  DEPTH =   3   34    0

26 Jan'09
In INIT_TREE change
from
    FOR L := 0 UNTIL MAXTREE
    DO BEGIN
      PARENT(L) := -1 ;
      GETNODE(L) := L ;
      NODETO(L,0) := -FIVES ;
    END ;
to
    FOR L := 0 UNTIL MAXTREE
    DO BEGIN
      PARENT(L) := 0 ;
      GETNODE(L) := L ;
      NODETO(L,0) := -FIVES ;
    END ;
    
this should overcome a problem in SEARCH where we have

      PARENT(I) := PARENT(I) + packer ;
--------------------------------------------------------------------------------
28 Jan'09
In MARKTREE don't count node ZERO as a valid parent
change
    if root ~= parent(node) rem packer
      then write("Inconsistent node/root/parent(node)/depth",
                node, root, parent(node), depth) ;
    IF PARENT(NODE) > DEPTH
    THEN BEGIN
      NODECOUNT := NODECOUNT + 1 ;
      IF TAG ~= 0
      THEN STATES(ROOT,2) := 0 ;
      FOR I := NODETO(NODE,0) STEP -1 UNTIL 1
      DO IF MARKTREE(NODETO(NODE,I), NODE, DEPTH+packer, TAG)
         THEN if nodeto(node,i) > 0 then begin
           write("marktree deletion node/i/nodeto(node,i)") ;
           write(node, i, nodeto(node,i)) ;
           NODETO(NODE,I) := 0 ;
         end ;
      PARENT(NODE) := ROOT + DEPTH ;
    END ELSE
    begin
      MARK := TRUE ;
      if node > 0 and root ~= parent(node) rem packer then begin
         write("Scrap inconsistent node", node, parent(node), root,
                nodeto(root,0)) ;
to
    if root ~= parent(node) rem packer
      then write("Inconsistent node/root/parent(node)/depth",
                node, root, parent(node), depth) ;
    IF PARENT(NODE) > DEPTH and parent(node) rem packer > 0
    THEN BEGIN
      NODECOUNT := NODECOUNT + 1 ;
      IF TAG ~= 0
      THEN STATES(ROOT,2) := 0 ;
      FOR I := NODETO(NODE,0) STEP -1 UNTIL 1
      DO IF MARKTREE(NODETO(NODE,I), NODE, DEPTH+packer, TAG)
         THEN if nodeto(node,i) > 0 then begin
           write("marktree deletion node/i/nodeto(node,i)") ;
           write(node, i, nodeto(node,i)) ;
           NODETO(NODE,I) := 0 ;
         end ;
      PARENT(NODE) := ROOT + DEPTH ;
    END ELSE
    begin
      MARK := TRUE ;
      if node > 0 and root ~= parent(node) rem packer then begin
         write("Scrap inconsistent node", node, parent(node), root,
                nodeto(root,0)) ;

The above changes corrects a speed-mode problem with

1R2R1K1P3BPPPNQ63P1P287N88-81P6888P1N2NP11PP1PPKPR2Q1R2-                      TFFFFFTRa1-b1           33+M  1 (16)
?lj4
play

and then at move 20. for black we used to get:

Inconsistent node/root/parent(node)/depth  22    3 30007 20000
Inconsistent node/root/parent(node)/depth  22    7 20000 10000
  New PV  : e7e5 h4d8 a8d8 h6g4 -99999    2
     Candidate : d8d6 a3c4 d6c6    1   86
 
 .......stuff missing
 
   2 -248 :   -2  -23 -255 -666 -372
-99999 99999 : e7e5 d8d6 d8d4 f4h5 d8d3
2470 SCORED   71 /  94 POSNS.   1 /   5  DEPTH =   3   34    0
   e5          12   -2    7    5    3 10007    5
     Qxd8        -7    2    3    5   56 20003    5
       Ra8-d8      -7   -2   56    5   61 30056    2
         Nh6-g4       0   -2   61    2

Node Count Error   -1   81    0   74   80
Dead-1   29   28   47   44   42   78   52   43   27   46   48   45   35   38   41   40   37   34    9   53
Dead-1   32   39   49   31   22    8    6   62    2    4   19   16   18   20   17   15   55   54   36   26
Dead-1   59   58   57   51   33   50   30   10   13   12   14   70    7   72   23   77   76   80   79    1
Dead-1   25   75   74   73   22   71   24   67   66   64   69   68   65   21    0
 e5          12   -2
 Qd6         -2  -23
 Qd4          0 -255
 Nh5         -2 -372
#Qd3         -2 -666
CONTINUE (Tracer ?D    exit):
Awit's move is:
  20.   ... e5           
  
but now get:

Inconsistent node/root/parent(node)/depth  22    3 30007 20000
Inconsistent node/root/parent(node)/depth  22    7 20000 10000
Scrap inconsistent node  22 20000    7    5
  New PV  : e7e5 h4d8 a8d8 h6g4 -99999    2
     Candidate : d8d6 a3c4 d6c6    1   86

.............stuff missing........

   2 -248 :   -2  -23 -255 -666 -372
-99999 99999 : e7e5 d8d6 d8d4 f4h5 d8d3
2430 SCORED   70 /  93 POSNS.   1 /   5  DEPTH =   3   34    0
   e5          12   -2    7    5    3 10007    5
     Qxd8        -7    2    3    5   56 20003    5
       Ra8-d8      -7   -2   56    5   61 30056    2
         Nh6-g4       0   -2   61    2

Awit's move is:
  20.   ... e5                      
     
-----------------------------------------
28Jan'09
In a sequence stemming from 
88881P66R183K4-8888881K68-                                                    TFFFFFTRg6              35$L    (70)
in speed mode.   Lost a node.   A fix to TREE was made

play
In Tree returned root error? node/nodeto(node,0)/..>0/root  72    2    0    1    1   61
  New PV  : d8c7 a7a8 b6a6 c7b7 e7d7 -99999 88885
88885 20466 : 88885 10847 1970  633  595
-99999 99999 : d8c7 b6a6 b6b8 b6b7 d8e7
 218 SCORED   30 /  50 POSNS.   1 /   5  DEPTH =   3    7    0

Node Count Error   -1   81    0   78   80
Dead-1   63   71   69   65    6   60   32   17   62   75   53    8   34   14   61   46   15   13   21   11
Dead-1   16   23   19   54   49   59    5   52   58   77    1   67   29   22    7   28   30   64   57   55
Dead-1    4   26   33   18   41   56   31   25   37   70   10    3   27   74   40    2   73   43   45   78
Dead-1   68   51   12   50   66   42   39   38   20   79   35    9   36   47   44   76   80   24    0
 Kc7          0 88885
 Ra6 +       40 10847
 Rb8          0 1970
 Rb7 +       40  633
#Ke7          0  595
CONTINUE (Tracer ?D    exit):
Awit's move is:
  74. Kc7 
  
In Tree changed 
    NODE := ROOTNODE(LEVEL-1) ;
    NODETO(NODE,NODETO(NODE,0)) := NIL ;
    NODETO(ROOT,0) := -1 ;

to
    NODE := ROOTNODE(LEVEL-1) ;
    for i := nodeto(node,0) step -1 until 1 do begin
           comment be sure to delete the correct pointer ;
      if nodeto(node,i) = root then
         NODETO(NODE,i) := NIL ;
    end ;

----------------------------------------
1 Feb'09
Change in TERMINATE.   Use of (PASTSCR - SCR) is suspect in mating situations.  A score of
                          -133330 = -88888 + (0 - 88884) div 2
                          the value of PASTSCR is probably confused with PREVSCORE

                       ELSE IF IP = 1 OR FINAL >= -2
                                 OR DEEPER = 0 AND FINAL > -7
                            THEN -(LASTSCR + (PASTSCR - SCR) DIV 2)
                            ELSE -AB(LEVEL) ;
temporarily to
                       ELSE IF IP = 1 OR FINAL >= -2
                                 OR DEEPER = 0 AND FINAL > -7
                            THEN -LASTSCR 
                            ELSE -AB(LEVEL) ;
                            
There is also a problem with termination at an even ply that need to be addressed.

-------------------
1 Feb'09
Consider changing BUILD_SACR_TREE.   It is possible that what we really want is -side*depth
from
  ALTERNATIVE := FALSE ;
  SCORE(TRY(1)) - DEPTH
END OF_BUILD_SACR_TREE ;

to
  ALTERNATIVE := FALSE ;
  SCORE(TRY(1)) + DEPTH
END OF_BUILD_SACR_TREE ;

----------------------------
1 Feb'09
In LOOKingAHEAD review the mechanism for increasing the depth of search to the maximum of
MAXPLIES = MAXDEPTH + MAXPLY
Do not stop on a checking move or when incheck (basically at a non-quiescent position) and do not
stop at an even-ply depth, if possible.

    INCREASE := 0 ;
    IF INCHECK OR GIVINGCH AND EXTENSION
        OR (DYNAMIC OR (NUM < 10) AND ~EARLY OR GIVINGCH
        OR SIDE < 0 AND (ALPHA < SCR + THRESHOLD OR IP = 1))
    THEN IF DEEPER <= 1 AND LEVEL + 1 < MAXDEPTH
         THEN INCREASE := IF (DEEPER > 0) AND (SIDE = -1)
                             OR DEEPER = 0 AND SIDE = 1
                          THEN 1
                          ELSE 2 ;
    IF OLD AND DYNAMIC AND DEEPER = 0 AND INCREASE = 0
       AND LEVEL < MAXDEPTH AND LEVEL > MINDEPTH
    THEN INCREASE := 1 ;
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    ELSE IF (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END
            AND PP_STATUS > 0) AND LEVEL >= MINDEPTH AND INCREASE = 0
            AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
            AND DEEPER = 0) OR EXTENSION AND LEVEL <= MAXDEPTH
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
    IF TEST AND (INCHECK OR INCREASE > 0)
    THEN WRITE("INC ", INCREASE, MINDEPTH, MAXDEPTH, DEEP, LEVEL, side,
               DEEPER, OLD, FINAL, INCHECK, LENGTH, PP_STATUS, EXTENSION) ;
               
change the portion
    IF LEVEL > LENGTH
    THEN INCREASE := 0
to
    if incheck and level < max_plies
    then increase := 1 else
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    
------------------------------------------
2Feb'09
In procedure LIMITS  declare local variable INTEGER EST ;
to distinguish it from the similar variable declared in enclosing procedure TREE.
In LIMITS replace EST by Est_scr
  PROCEDURE LIMITS ;
  BEGIN
    integer Est_scr ;
    
In procedure TREE we seem to have both EST used in comparison with REFCNT and with
MAXL - POINT in MAKESPACE, where EST is a parameter.

Create two variables EST_cnt and EST_spa to replace EST.
INTEGER PROCEDURE TREE (INTEGER VALUE  ALPHA, BETA, T_HASH, DEEPER ;
                        LOGICAL VALUE PRINCVAR ; INTEGER RESULT TYPE) ;

COMMENT generates the decision tree ;
BEGIN
  INTEGER IP, TARGET, ROOT, IDONE, LIMIT, PASTSCR, LASTSCR, INCREASE, EST_cnt,
          EST_spa, MIN, SCR, REWN, BETTER, MX, LX, FIRST, F_T, INC, INIT_T_NODES,
          CONDITION, LARGE, B_SCR, T_SCR, LOWER ;

These two changes seems to have a hugely beneficial effect of making self-play and repeated-play 
modes equivalent.  If true, this will eliminate the huge stumbling block of repeatability in
debugging.

This use of a locally global varialbe called EST in TREE has now twice caused problems, see earlier
fix to EXPAND, and correcting this error/typo has been beneficial.
---------------------------------------
2 Feb'09
Now have an example where the 5th (last) move in a list is not properly scored, in that the PV 
sequence value is not properly fed back to the root.  This leads to repeatability problems too.
1R4K1P3RPPPN6Q5P287N88-81P6888P4NP11PP1PPKPR2Q1R2-                            TFFFFFTRe1xe2           13+M    (18)
?lj5
Nh5

play
  New PV: e2b2 g7h6 b2b7 h6g7 -99999  -140
level=1/again/ip/t_scr/l_scr  FALSE     2 -1701  -139
    Candidate: b1b2 h5f4 h3f3  -141   117
In SACR_TREE Stale/Mate at level=    5 -88888
  New PV: e2b2 g7h6 b2b7 h6g7  -141   117
    Candidate: h3b3 g7h6 e2b2   116   339
  New PV: e2b2 g7h6 b2b7 h6g7   116   339
level=1/again/ip/t_scr/l_scr  FALSE     5    43   340
  339   587 :   917   117 -88884   339 -1455
-99999 99999 : e2b2 h3b3 h6f5 b1b2 h3c3
 2398 SCORED    63 /   77 POSNS.    1 /    5  DEPTH =    3    38     0
In SEARCH length/flag(1)/b_scr ~= best/alpha/beta/reply
          3     1   339   917 -99999 99999     1
 Re2xb2      -1   917
 Qb3         -2   339
 Nh6-f5 +   -40   117
 Rb1xb2      -1 -88884
#Qc3 +      -40 -1455
CONTINUE (Tracer ?D    exit):

Awit's move is:
   19. Re2xb2                  
BLACK'S MOVE    19 
?g
 Rb ::    Qb    Rb    ::
 :: Pb Pb    Pb Pb Kb Pb
 Pb ::    ::    :: Pb Nw
 ::    ::    ::    :: Nb
    ::    ::    Pw    ::
 Nw    ::    ::    :: QW
 Pw Rw    ::    Pw Pw Pw
 :: Rw ::    ::    KW
Feb 02 2009 08-AP9.9 BLACK'S MOVE 19.
 Re2xb2      -1   917     2     5     3 10002
   Kxh6         3  -917     3     5     4 20003     3
     Rb2xb7       1   917     4     3    67 30004     1
       Nh6xg7       0   917    67     1
     g4         -12   771     4     3     6 30004     1
       Qd5         -2   771     6     1
   b5          12 -1866     3     5    26 20003     0
     Na3-b5       1  1866    26     0
 Qb3         -2   339     2     5    15 10000
   Kxh6        -3  -339    15    -5    39 20000    -1
     Re2xb2      -1   339    39    -1
 Nh6-f5 +   -40   117     2     5    72 10000
   Kf6         -2 -2804    72    -2    29 20000    -3
     Re2xb2      -1  2804    29    -3    30 30000    -1
       Nxf4        -1  2804    30    -1
 Rb1-b2      -1 -88884     2     5    66 10000
   Qd1 +       40 88884    66    -5    37 20000    -1
    # e2-e1      -2 -88884    37    -1    38 30000    -1
        d1xe1 ++  -105 -88884    38    -1
#Qc3 +      -40 -1455     2     5    70 10000
   f6          -2   -43    70    -2    12 20000    -4
      e2-d2      -2    43    12    -4    45 30000    -1
       Qc8         -2    43    45    -1
       
Two problems, note that the value of Qc3+ is wrong at level 1
Also, that for even-ply terminations the 4-th ply score has wrong sign.
Unlikely these two problems are related.  Both worth looking into.

Changed "MIN" in TREE to "MIN_wid" and "min" to "min_wid"
result is now:
 Nh6-f5 +   -40  2271     1     5     2 10001
   g6xf5       -3 -2271     2     3    17 20002     5
     Qxh5        -3  2271    17     5    18 30017     1
       Qd3         -2  2271    18     1
     Qf5         -1   529    17     5    19 30017     1
       Qd6         -2   529    19     1
   Kf6         -2 -2804     2     3     3 20002     5
     Re2xb2      -1  2804     3     5     4 30003     1
       Nxf4        -1  2804     4     1
     Rb1xb2      -1  1892     3     5     5 30003     1
       Nxf4        -1  1892     5     1
 Re2xb2      -1  2154     1     5    77 10000
   Kh6          3 -2154    77    -5    76 20000    -1
     b7           1  2154    76    -1
 Rb1xb2       1  1684     1     5    79 10000
   Kh6          3 -1684    79    -1    78 20000    -1
     g4         -12  1684    78    -1
 h6xf7       -1  1391     1     5    74 10000
   Rf8-f7       3 -1391    74    -1    32 20000    -1
     Qc3 +      -40  1391    32    -1
#Qc3 +      -40   243     1     5    75 10000
   Kh6          3  -243    75    -1    34 20000    -5
     Re2xb2      -1   243    34    -5    35 30000 -55555
       Nxf4         1   243    35 -55555
CONTINUE (Tracer ?G    exit):

----------------------------------------
5-10 Feb'09
In EXPAND change:
        NODEX := ORIGIN ;
        I := IF AGAIN THEN IP + 1
             ELSE 1 ;
to
        I : = if MV > 0 and MV < IP
              then MV
              else IP ;
seems the more logical at level = 1
          
In EXPAND change
    IF (DEEPER > 0 OR INCREASE > 0 OR OLD) AND (~INCHECK
       OR LEVEL ~= DEEP OR IP < WIDTH DIV 2 OR TIME(1) - T_TIME < M_TIMES(0))
    THEN BEGIN
to
    IF (DEEPER > 0 OR INCREASE > 0 OR OLD) AND (incheck or givingch
       OR LEVEL ~= DEEP OR IP <= MIN_wid)
    THEN BEGIN

In EXPAND
Change integer variable MV to MP.  This variable is simply a pointer into the TRY() array
and is not in any way related to the similarly named variable in MOBILITYSCORE.

In EXPAND change
               FULLWIN := AGAIN := TRUE ;
               HIGHER := EIGHTS ;
               LOWER := L_SCR - 1 ;
               IP := IP - 1 ;
             END ELSE AGAIN := FALSE ;
to
               FULLWIN := AGAIN := TRUE ;
               HIGHER := EIGHTS ;
               LOWER := L_SCR - 1 ;
             END ELSE AGAIN := FALSE ;
and also change
  EXP
END OF_EXPAND ;
to
  if again
  then ip := ip -1 ;
  EXP
END OF_EXPAND ;
---------------------------------------
10 Feb'09
BEST is a variable that is local to SEARCH, but global to TREE, TERMINATE, LIMITS, EXPAND and 
LOOKingAHEAD.  Make sure it is only set when LEVEL = 1.   Given this, one has to wonder why it is 
being reset so often.  Nevertheless it does seem to be set only when LEVEL = 1.

Change in SEARCH  etc. the variable BEST to MOST (and similarly the lower case variants).

In EXPAND change
          IF LEVEL = 1 AND MX > MOST
          THEN BEGIN
            REPLY := PATH ;
            MOST := MAXSC(PATH) := MX ;
          END ;
to
          IF LEVEL = 1 AND MX > MOST
          THEN BEGIN
if ip > 1 and ~again
then again := true else again := false ;
write("Save new EXPAND most/mx/path/again", most, mx, path, again) ;
            REPLY := PATH ;
            MOST := MAXSC(PATH) := MX ;
          END ;
          
The purpose of the change is to ensure that AGAIN is true and that a new candidate is established.

In SEARCH change
  LEVEL := IF POINT = 0 AND DEEP >= 3 AND MAX_WID ~= w_size
           THEN 3
           ELSE 1 ;
  PLY := LEVEL ;
to
  PLY := IF POINT = 0 AND DEEP >= 3 AND MAX_WID ~= w_size
         THEN 3
         ELSE 1 ;
LEVEL is not used until TREE is called, and is reset to 1 before that point.  Also, setting it to
3 make no rational sense.

In DESCRIBEMOVE change
      J := IF OUT(0|1) = "P" OR COKO 
to
      comment J := IF OUT(0|1) = "P" OR COKO ;
      J := IF COKO
      
In TREE change
  INTEGER IP, TARGET, ROOT, IDONE, LIMIT, PASTSCR, LASTSCR, INCREASE, EST_spa
          EST_cnt, MIN_wid, SCR, REWN, BETTER, MX, LX, FIRST, F_T, INC,
to
  INTEGER IP, TARGET, ROOT, IDONE, LIMIT, PASTSCR, LASTSCR, INCREASE,
          EST_cnt, MIN_wid, SCR, REWN, BETTER, MX, LX, FIRST, F_T, INC_wid,
and also
change INCREASE to INC_wid in TREE (two locations).  Basically change INC to INC_wid, local to TREE.

In EXPAND
change
      T_SCR := - TREE(-HIGHER, -LOWER, NEW_HASH, DEEPER+INCREASE-1,
                       PRINCVAR AND FULLWIN, F_T) ;
to 
      T_SCR := - TREE(-HIGHER, -LOWER, NEW_HASH, DEEPER+INCREASE,
                       PRINCVAR AND FULLWIN, F_T) ;
and explore
what happens when search depth is increased.

In LOOKingAHEAD
examine whether setting of INCREASE is right.  The code is a real mess and needs simplification.
    INCREASE := 0 ;
    IF INCHECK OR GIVINGCH AND EXTENSION
        OR (DYNAMIC OR (NUM < 10) AND ~EARLY OR GIVINGCH
        OR SIDE < 0 AND (ALPHA < SCR + THRESHOLD OR IP = 1))
    THEN IF DEEPER <= 1 AND LEVEL + 1 < MAXDEPTH
         THEN INCREASE := IF (DEEPER > 0) AND (SIDE = -1)
                             OR DEEPER = 0 AND SIDE = 1
                          THEN 1
                          ELSE 2 ;
    IF OLD AND DYNAMIC AND DEEPER = 0 AND INCREASE = 0
       AND LEVEL < MAXDEPTH AND LEVEL > MINDEPTH
    THEN INCREASE := 1 ;
    if incheck and level < max_plies
    then increase := 1 else
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    ELSE IF (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END
            AND PP_STATUS > 0) AND LEVEL >= MINDEPTH AND INCREASE = 0
            AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
            AND DEEPER = 0) OR EXTENSION AND LEVEL <= MAXDEPTH
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
    IF (true or TEST) AND (INCHECK OR INCREASE > 0)
    THEN WRITE("INC increase/deep/deeper/side/level/dynamic/scr/alpha",
               scr, alpha, INCREASE, DEEP, DEEPER, SIDE, LEVEL) ;
    IF (true or TEST) AND (INCHECK OR INCREASE > 0)
    then write("  mindepth/maxdepth/givingch/ip/length/pp_status/extension/m14",
         MINDEPTH, MAXDEPTH, givingch, ip, LENGTH, PP_STATUS, EXTENSION, m14) ;
         
change to
    INCREASE := 0 ;
    IF INCHECK OR GIVINGCH or EXTENSION OR DYNAMIC
       OR (NUM < 10) AND ~EARLY
       OR SIDE < 0 AND (IP = 1 or scr > alpha - threshold)
    THEN IF DEEPER <= 1 AND LEVEL + 1 < MAXDEPTH
         THEN INCREASE := IF (DEEPER > 0) AND (SIDE = -1)
                             OR DEEPER = 0 AND SIDE = 1
                          THEN 1
                          ELSE 2 ;
    IF INCREASE = 0 AND OLD AND DYNAMIC AND DEEPER = 0
       AND LEVEL < MAXDEPTH AND LEVEL > MINDEPTH
    THEN INCREASE := 1 ;
if increase > 0 then write ("INC1 ", increase) ;
       comment rarely is increase > 0 at this point ;

    if (incheck or givingch) and level < max_plies
    then increase := 1 else
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    ELSE IF (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END
            AND PP_STATUS > 0) AND LEVEL >= MINDEPTH AND INCREASE = 0
            AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
            AND DEEPER = 0) OR EXTENSION AND LEVEL <= MAXDEPTH
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;

    IF (true or TEST) AND (INCHECK OR INCREASE > 0)
    THEN WRITE("INC increase/deep/deeper/side/level/length/scr/alpha",
               INCREASE, DEEP, DEEPER, SIDE, LEVEL, LENGTH, scr, alpha) ;
               
------------------------------------
14 Feb'09
In LOOKingAHEAD change
    THEN IF DEEPER <= 1 AND LEVEL + 1 < MAXDEPTH ;
         THEN INCREASE := IF (DEEPER > 0) AND (SIDE = -1)
                             OR DEEPER = 0 AND SIDE = 1
                          THEN 1
                          ELSE 2 ;
to
    THEN IF DEEPER <= 1 AND LEVEL + 1 < max_plies        comment MAXDEPTH ;
         THEN INCREASE := IF (DEEPER > 0) AND (SIDE = -1)
                             OR DEEPER = 0 AND SIDE = 1
                          THEN 1
                          ELSE 2 ;
    IF (true or TEST) AND (INCHECK OR INCREASE > 0)
    then write("  mindepth/maxdepth/givingch/ip/pp_status/extension/m14/dynamic",
         MINDEPTH, MAXDEPTH, givingch, ip, PP_STATUS, EXTENSION, m14, dynamic) ;
         
-------------------------------------
14 Feb'09
In LOOKingAHEAD change
    ELSE IF (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END
            AND PP_STATUS > 0) AND LEVEL >= MINDEPTH AND INCREASE = 0
            AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
            AND DEEPER = 0) OR EXTENSION AND LEVEL <= MAXDEPTH
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
to
    ELSE IF EXTENSION AND LEVEL <= MAXDEPTH 
           OR (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END AND PP_STATUS > 0) 
             AND LEVEL >= MINDEPTH AND INCREASE = 0
             AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
                  AND DEEPER = 0)
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
--------------------------------------------
15 Feb'09
There is a problem in LOOKingAHEAD.  The mechanism for extending the search in the region
MINDEPTH < LEVEL < MAXDEPTH < MAX_PLIES sometimes has problems, in that even-ply searches are
done and the score returned is compared to an odd-ply search.  An adjustment is made to the score
but possibly it is not accurate enough, since it commonly leads to a search anomaly with the 
message: "In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply"

One solution is to force only odd-ply searches to depth max_plies, but this is expensive.  Another 
is to be more selective about when extensions are done, but the existing code is already 
extremely complex.

Separately, the variable MX seems to be trying to handle even-ply terminations, but not clear enough 
exactly how it is accomplishing that.  It is used in conjunction with AB(level) and MAXSC(PATH).
--------------------------------------------
16 Feb'09  Testing, the following simplification not found satisfactory

increase := 0 ;

if level >= mindepth and level < max_plies then
if (givingch or incheck or expansion or dynamic or m14 ~= 0 or pp_status >= 10 or late_end and pp_status > 0)
then increase := if side = -1
                 then 2
                 else 1 ;
---------------------------------
16 Feb'09
badden% grep 'DISAST' *16Feb*
badden% grep 'EMERG' *16Feb*
badden% grep SERIO *16Feb*
badden% grep PRUNE *16Feb*
badden% grep INCON *16Feb*
INCONSISTENT maxl=   80   599   600 lost=     1     0     0    80
badden% grep CHECK *16Feb*
badden% 
To correct the above inconsistency, in LOOKingAHEAD change
    END ELSE
    begin
      if nodeto(root,ip) > 0 and ip <= nodeto(root,0)
      then begin
        write("LOOKing delete node", nodeto(root,ip), ip, "<=", nodeto(root,0)) ;
        write("Should we return", nodeto(root,ip), " to getnode list?") ;
      end ;
      NODETO(ROOT, IP) := 0 ;
    end ;
    SEEN := QUIES(TRY(IP)) ;
to
    END ELSE
    begin
      if nodeto(root,ip) > 0 and ip <= nodeto(root,0)
      then begin
        write("LOOKing delete node", nodeto(root,ip), ip, "<=", nodeto(root,0)) ;
        write("Should we return", nodeto(root,ip), " to getnode list?, Yes!") ;
        if maxl < MAXTREE then begin
          maxl := maxl + 1;
          getnode(maxl) := nodeto(root,ip) ;
        end ;
      end ;
      NODETO(ROOT, IP) := 0 ;
    end ;
    SEEN := QUIES(TRY(IP)) ;
--------------------------------------
17 Feb'09
Continuing problem with comparion of even and odd-ply length searches, resulting in warning message:
In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply

Try to force more uniformity with odd-ply searches by changing LOOKingAHEAD
from

    if (incheck or givingch) and level < max_plies
    then increase := 1 else
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    ELSE IF EXTENSION AND LEVEL <= MAXDEPTH
           OR (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END AND PP_STATUS > 0)
             AND LEVEL >= MINDEPTH AND INCREASE = 0
             AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
                  AND DEEPER = 0)
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
to
if increase = 0 then
begin
    if (incheck or givingch) and level < max_plies
                     or side = 1 and level = max_plies - 1
    then increase := 1 else
    IF LEVEL > LENGTH
    THEN INCREASE := 0
    ELSE IF EXTENSION AND LEVEL <= MAXDEPTH
           OR (INCHECK OR PP_STATUS >= 10 OR M14 ~= 0 OR LATE_END AND PP_STATUS > 0)
             AND LEVEL >= MINDEPTH AND INCREASE = 0
             AND (LEVEL + DEEPER < MAXDEPTH OR LEVEL <= 3 AND LEVEL = MAXDEPTH
                  AND DEEPER = 0)
         THEN INCREASE := (IF SIDE = -1
                            THEN 2
                            ELSE 1) ;
.......
end ;
---------------------------------
17 Feb'09 B-K test
badden% grep DISAST *17F*
badden% grep EMERG *17F*
EMERGENCY setting IP to Zero    2   684   779
EMERGENCY setting IP to Zero    2   700   779
EMERGENCY setting IP to Zero    2   424   431
badden% grep SERIO *17F*
badden% grep INCON *17F*
INCONSISTENT maxl=  362   598   600 lost=     2     0     0   362
badden% grep CHECK *17F*
badden% grep PRUNE *17F*

-------------------------------------
17 Feb'09
The following change was made to TREE at some time in the past, but the MIN_wid <= IDONE prevented
the write statement.
from
    IF IDONE < MIN_wid AND IDONE >= LX
    THEN BEGIN
      if nodeto(root,min_wid) > 0 and MIN_wid <= IDONE then
        write("In TREE delete", nodeto(root,min_wid), min_wid, idone) ;
      NODETO(ROOT,MIN_wid) := NIL ;
      IDONE := IDONE + 1 ;
    END ;
    
it should be 
    IF IDONE < MIN_wid AND IDONE >= LX
    THEN BEGIN
      if nodeto(root,min_wid) > 0 then
        write("Warning: In TREE delete", nodeto(root,min_wid), min_wid, idone) ;
      NODETO(ROOT,MIN_wid) := NIL ;
      IDONE := IDONE + 1 ;
    END ;
    
------------------
In INSERT_NEW we have:
               IF S > IDONE
               THEN BEGIN
                 IF IN <= IDONE
                 THEN BEGIN
                   DISCARD_SUBTREES(IN) ;
                   IDONE := IDONE + 1 ;
                   NODETO(ROOT, 0) := IDONE ;
                 END ;
                 if nodeto(root,s) > 0 and s <= idone then
                    write("INSERT_NEW deleting nodeto(root,s)/s/idone",
                             nodeto(root,s), s, idone) ;
                 NODETO(ROOT, S) := 0 ;
               END ;
it should be
               IF S > IDONE
               THEN BEGIN
                 IF IN <= IDONE
                 THEN BEGIN
                   DISCARD_SUBTREES(IN) ;
                   IDONE := IDONE + 1 ;
                   NODETO(ROOT, 0) := IDONE ;
                 END ;
                 if nodeto(root,s) > 0 then
                    write("Warning: INSERT_NEW deleting nodeto(root,s)/s/idone",
                             nodeto(root,s), s, idone) ;
                 NODETO(ROOT, S) := 0 ;
               END ;
 -------------------------
 In TREE change from
     IF TEST or dummy4
    THEN WRITE("(STALE)MATE level/b_scr/mx/side/final", LEVEL, B_SCR, mx, side, FINAL) ;
    NUM := 0 ;
    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
    if false and root > 0 then
       if maxl < maxtree then begin
         maxl := maxl + 1 ;
         getnode(maxl) := root ;
       end else begin
         getnode(point) := root ;
         point := point - 1 ;
       end ;
to
    IF TEST or dummy4 or true
    THEN WRITE("(STALE)MATE level/b_scr/mx/side/final", LEVEL, B_SCR, mx, side, FINAL) ;
    NUM := 0 ;
    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
            comment don't return "root" to available, need it on exit to TREE ;
    if false and root > 0 then
       if maxl < maxtree then begin
         maxl := maxl + 1 ;
         getnode(maxl) := root ;
       end else begin
         getnode(point) := root ;
         point := point - 1 ;
       end ;
-----------------------------
In TREE omit recapture of "ROOT" node, since needed upon exit to TREE change:
    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;

    if root > 0 then
       if maxl < maxtree then begin
         maxl := maxl + 1 ;
         getnode(maxl) := root ;
         getnode(maxl+1) := 0 ;
       end else begin
         getnode(point) := root ;
         point := point - 1 ;
       end ;
    NODE := ROOTNODE(LEVEL-1) ;

    if root ~= nodeto(node,nodeto(node,0)) then begin
      write("In Tree, returned root fixed? node/nodeto(node,0)/..>0/root", node,
             nodeto(node,0), nodeto(node,nodeto(node,0)), root) ;
      for i := nodeto(node,0) step -1 until 1 do
        writeon(nodeto(node,i)) ;
    end ;

    for i := nodeto(node,0) step -1 until 1 do begin
           comment be sure to delete the correct pointer ;
      if nodeto(node,i) = root then
         NODETO(NODE,i) := NIL ;  comment detach the root node ;
    end ;
    if dummy4 then tracer(1, "?P") ;
    GO TO QUIT ;
to
    IF LEVEL = 1
    THEN GO TO QUIT ;

            comment don't return "root" to available, need it on exit to TREE ;
    NODE := ROOTNODE(LEVEL-1) ;

    if root ~= nodeto(node,nodeto(node,0)) then begin
      write("In Tree, root node not fixed? node/nodeto(node,0)/..>0/root", node,
             nodeto(node,0), nodeto(node,nodeto(node,0)), root) ;
      for i := nodeto(node,0) step -1 until 1 do
        writeon(nodeto(node,i)) ;
    end ;

    if dummy4 then tracer(1, "?P") ;
    GO TO QUIT ;
    
--------------------------------------
17 Feb'09
It would seem there is a problem with varialble AGAIN.  It is local to TREE and global to
LOOKingAHEAD and LIMITS and also EXPAND.   It is reset in EXPAND.  It probably should be used 
only when LEVEL = 1, since it is tracking whether the current PV should be (is being) re-expanded.
change
  IDONE := NODETO(ROOT,0) ;
  AGAIN := FALSE ;
  MX := AB(LEVEL) := SIDE*EIGHTS ;
to
  IDONE := NODETO(ROOT,0) ;
if path = 1 then
  AGAIN := FALSE ;
  MX := AB(LEVEL) := SIDE*EIGHTS ;
-------------------------------------
18 Feb'09
In TREE restore the node reclamation code after MATE/STALEMATE detection to:
    IF LEVEL = 1
    THEN GO TO QUIT ;
            comment return "root" node to available nodes list ;
            comment don't return "root" to available, need it on exit to TREE ;
    if root > 0 then begin
       if maxl < maxtree then begin
         maxl := maxl + 1 ;
         getnode(maxl) := root ;
         getnode(maxl+1) := 0 ;
       end else if point > 0 then begin
         getnode(point) := root ;
         point := point - 1 ;
       end else write("TREE not returning", root, " to getnode list") ;
    end ;
    NODE := ROOTNODE(LEVEL-1) ;
    for i := nodeto(node,0) step -1 until 1 do begin
           comment be sure to delete the correct pointer ;
      if nodeto(node,i) = root then
         NODETO(NODE,i) := NIL ;
    end ;
----------------------------
18 Feb'09
The following is a sample position (under 20,3,0,3 mode) which shows consequence of SEARCH failure,
in that last move considered is a rejected candidate PV, but is played instead of the best move.
R1BQK1NRPPP2PPP2N53P41B2P3888+8881B63P42N1P3PPPB1PPPR2QK1NR+                  FTTFTTFPa3              55$E    ( 6)
SHALL I CONTINUE (Yes or No)?
y
  New PV: i/ip/level    1     1     1 b5c6 b4c3 b2c3 d7c6 a1b1 -99999  -426
Warning: In TREE delete   15     3     2
New candidate PV    0     2   TRUE     0  -426  -308  -308  -425  -426
    Candidate: i/ip/level    2     2     1 c1f4 c6e5 f4e5  -427  -308
  New PV: i/ip/level    1     2     1 c1f4 c6e5 f4e5 b4c3 b2c3  -427  -328
  Next Line: i/ip/level    3     3     1 h2h4 c6e5 c1g5  -328 -1289
  Next Line: i/ip/level    3     4     1 c1e3 c6e5 a2a3  -328 -1138
New candidate PV    2     5   TRUE     0  -328  -122  -122  -327  -328
    Candidate: i/ip/level    5     5     1 a2a3 b4c3 d1d2  -329  -122
Candidate Rejected  TRUE     1     2     5  -328  -328 -1117
  Next Line: i/ip/level    1     5     1 a2a3 b4c3 e1e2  -329 -1117
 -328  -721 :  -426  -328 -1289 -1138  6982
-99999 99999 : a2a3 c1f4 b5c6 c1e3 h2h4
 3992 SCORED   125 /  133 POSNS.    5 /    5  DEPTH =    3    31     0
In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply
          3     1  -328  6982 -99999 99999     5

Awit's move is:
    6. Pa3  
    
another example:
?6
10 3 0 3
yes
Pc3
Pd5
?lj5
play
play
play

PC3              4B*E  5 ( 1) Pd5              0B*E
Pd4              13-E    ( 2) Bg4              13-E
Qa4 +            33=E    ( 3)
  New PV: i/ip/level    1     1     1 c1g5 g8f6 g1f3 f6e4 b1a3 -99999  -294
New candidate PV    0     2   TRUE     0  -294  -280  -280  -293  -294
    Candidate: i/ip/level    2     2     1 g1f3 b8d7 g2g3  -295  -280
  New PV: i/ip/level    1     2     1 g1f3 b8d7 c1g5  -295    21
New candidate PV    2     3   TRUE     0    21   531   531    22    21
    Candidate: i/ip/level    3     3     1 d1a4 b8c6 g1f3    20   531
Candidate Rejected  TRUE     1     2     3    21    21   -41
  Next Line: i/ip/level    1     3     1 d1a4 b8c6 g1f3 e7e6 f3e5    20   -41
   21  -129 :  -294  -207   -41
-99999 99999 : d1a4 g1f3 c1g5
 2163 SCORED    70 /   72 POSNS.    3 /    3  DEPTH =    3    30     0
In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply
          3     1    21   -41 -99999 99999     3

Awit's move is:
    3. Qa4 +  
    
and another, although here is plays the right move, while indicating another as better.
  New PV: i/ip/level    1     1     1 b1a3 f8d6 f4d6 -99999    54
New candidate PV    0     2   TRUE     0    54   190   190    55    54
    Candidate: i/ip/level    2     2     1 e2e3 f6e4 f3e5    53   190
  New PV: i/ip/level    1     2     1 e2e3 f6e4 f3e5 d8h4 e5c6    53    93
New candidate PV    2     3   TRUE     0    93   103   103    94    93
    Candidate: i/ip/level    3     3     1 b1d2 f6h5 f4g5    92   103
  New PV: i/ip/level    2     3     1 b1d2 f8d6 f4d6    92   143
  143    23 :    54   181   143
-99999 99999 : e2e3 b1d2 b1a3
 3206 SCORED    80 /   82 POSNS.    2 /    3  DEPTH =    3    40     0
In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply
          3     1   143   181 -99999 99999     2
---------------------------------------
20 Feb'09
Look carefully at COLLECTDATA procedure to see if it can be generalized and improved to embrace
some of the "special case" node recapture code in other routines (e.g. TREE).


PROCEDURE COLLECT (INTEGER VALUE NODE, ROOT) ;
COMMENT    collects nodes from discarded tree. ;
BEGIN
  INTEGER L ;
  IF NODE > 0
  THEN IF NODE > MAXTREE
       THEN WRITE("ERROR COLLECT", NODE)
       ELSE IF (ROOT = PARENT(NODE) REM packer)
            THEN BEGIN
              if dummy4 then write("Entering COLLECT node/root", node, root) ;
                       COMMENT retrieve least significant node of most extreme
                               subtree ;
                              COMMENT gametree not want PARENT(NODE) := 0 ;
              L := NODETO(NODE,0) ;
              FOR I := L STEP -1 UNTIL 1
              DO COLLECT(NODETO(NODE,I), NODE) ;
                              COMMENT display retrieved nodes ;
              IF MAXL >= MAXTREE THEN BEGIN
                WRITE("COLL", MAXL, NODE, L, PARENT(NODE)) ;
                FOR I := 1 UNTIL 10 DO WRITEON(GETNODE(I)) ;
              END ELSE
              BEGIN
                if dummy4 then writeon("storing node", node) ;
                MAXL := MAXL + 1 ;
                GETNODE(MAXL) := NODE ;
                reuse := maxl ;
                STATES(NODE,4) := -ABS(STATES(NODE,4)) ;
                PARENT(NODE) := packer*(PARENT(NODE) DIV packer) ;
                NODETO(NODE,0) := IF L = 0
                                  THEN -FIVES
                                  ELSE -ABS(L) ;
                COMMENT IF MONITOR THEN WRITEON(NODE, ROOT, PARENT(NODE)) ;
             END ;
  END ;
END OF_COLLECT ;
---------------------------------
20 Feb'09
In TREE change by adding warning message

    for i := nodeto(node,0) step -1 until 1 do begin
           comment be sure to delete the correct pointer ;
      if nodeto(node,i) = root then
         NODETO(NODE,i) := NIL ;
    end ;
    
to
    for i := nodeto(node,0) step -1 until 1 do begin
           comment be sure to delete the correct pointer ;
      if root > 0 then
      for j := nodeto(root,0) step -1 to 1 do
      if nodeto(root,j) > 0 then
      write("TREE-1 Will lose node", nodeto(root,j)) ;
      if nodeto(node,i) = root then
         NODETO(NODE,i) := NIL ;
    end ;
    
and also add warning to LOOKingAHEAD in attempt to further resolve node-loss matter.

      NODETO(ROOT, IP) := 0 ;
    end ;
    SEEN := QUIES(TRY(IP)) ;
to
      if (nodeto(root,ip) > 0) then
      for j := nodeto(nodeto(root,ip),0) step -1 to 1 do
      if nodeto(nodeto(root,ip),j) > 0 then
      write("LOOKing-2 Will lose node", nodeto(nodeto(root,ip),j)) ;
      NODETO(ROOT, IP) := 0 ;
    end ;
    SEEN := QUIES(TRY(IP)) ;
-------------------------------
?6
0 0 0 0
no
R1B2RK1PPB1QP22N2N1P2P1P1P13P4-88884P3P2P1NB11PPNBPPPR2Q1RK1-                FFFFFFF                          (35)
?lj
play

and another example is:
?6
20 3 0 3
yes
?f
Pc3
.        Pd5
?lj5
play
.        Pd4
play
.        Pe6
?r0
Bg4
play
.        Nf3
play


In INSERT_NEW replace
                 IF NODETO(ROOT,0) >= S
                 THEN COLLECT(NODETO(ROOT,S), ROOT)
                 else write("INSERT_NEW nodeto(root,0)/s/nodeto(root,s) lost", nodeto(root,0), s, nodeto(root,s)) ;
with
                 IF NODETO(ROOT,0) >= S
                 THEN COLLECT(NODETO(ROOT,S), ROOT)
                 else if nodeto(root,s) > 0 then
write("INSERT_NEW nodeto(root,0)/s/nodeto(root,s) lost", nodeto(root,0), s, nodeto(root,s)) ;


      write("LOOKing-2 Will lose node", ip, nodeto(root,0), root, parent(nodeto(nodeto(root,ip),j)),
            parent(nodeto(root,ip)), nodeto(nodeto(root,ip),j), j, nodeto(nodeto(root,ip),0)) ;
            
--------------------------------------
21 Feb'09
Found an example where MARKTREE loses nodes.  Replace

      FOR I := NODETO(NODE,0) STEP -1 UNTIL 1
      DO IF MARKTREE(NODETO(NODE,I), NODE, DEPTH+packer, TAG)
         THEN if nodeto(node,i) > 0 then begin
           write("marktree deletion node/i/nodeto(node,i)/nodeto(node,0)") ;
           write(node, i, nodeto(node,i), nodeto(node,0)) ;
           NODETO(NODE,I) := 0 ;
         end ;
         
with
      FOR I := NODETO(NODE,0) STEP -1 UNTIL 1
      DO IF MARKTREE(NODETO(NODE,I), NODE, DEPTH+packer, TAG)
         THEN if nodeto(node,i) > 0 then begin
           write("marktree deletion node/i/nodeto(node,i)/nodeto(node,0)") ;
           write(node, i, nodeto(node,i), nodeto(node,0)) ;
           COLLECT(NODETO(NODE,I), NODE) ;
           NODETO(NODE,I) := 0 ;
         end ;
-------------------------------
23 Feb'09
Create Procedure Reclaim_Node and use it in EXPAND, TREE and LOOKingAHEAD

PROCEDURE Reclaim_Node (integer root; string(7) value location) ;
begin
  if root > 0 then begin
     if maxl < maxtree then begin
       maxl := maxl + 1 ;
       getnode(maxl) := root ;
       getnode(maxl+1) := 0 ;
     end else if point > 0 then begin
       getnode(point) := root ;
       point := point - 1 ;
     end else write("RECLAIM_NODE not returning", root, " to getnode list") ;
     if warning then
       write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
     for i := nodeto(root,0) step -1 until 1 do
     if nodeto(root,i) > 0 then
       Reclaim_Node(nodeto(root,i), "RECLAIM") ;
  end ;
END OF_Reclaim_Node ;
  -------------------------------
23 Feb'09
In TREE consider making limit/try(0)/try(wsize) more consistent, after VARS(.,.) setting.   
Replace

  IF (LEVEL = 1)
  THEN FIRSTENTRY(ROOT)
  ELSE
  begin
    IF (LEVEL = 2)
    THEN LIMIT := IF ~OPENING AND ~ENDGAME AND TRY(0) > WIDTH DIV 2
                  THEN TRY(0)
                  ELSE LIMIT
    ELSE LIMIT := VARS(LEVEL, LENGTH) ; comment LIMIT is set when LEVEL >= 3 ;
    if limit < try(0) then
    write("Question width limit/try(0)/try(wsize)/level/vars/length",
           limit, try(0), try(wsize), level, vars(level,length), length) ;
  end ;
  
with
  IF (LEVEL = 1)
  THEN FIRSTENTRY(ROOT)
  ELSE
  begin
    IF (LEVEL = 2)
    THEN LIMIT := IF ~OPENING AND ~ENDGAME AND TRY(0) > WIDTH DIV 2
                  THEN TRY(0)
                  ELSE LIMIT
    ELSE LIMIT := VARS(LEVEL, LENGTH) ; comment LIMIT is set when LEVEL >= 3 ;
    if try(0) > limit then
      try(0) := limit ;
    if limit > try(wsize) then
      limit := try(wsize) ;
  end ;
--------------------------------------------
23 Feb'09
Here is an example of "SEARCH" error message
?6
30 3 0 3
no
83K487P5P21R688-88RP682P4P85PK18-                                             TFFFFFTRb6              13-L    (50)
?lj
warning
play

PAB    1  FALSE 99999 -99999 -99999  2410  FALSE   TRUE 99999 -88888 -99998  FALSE
  New PV: i/ip/level    1     1     1 c5c4 d2c3 a3a4 b6d6 a4a5 -99999  2410
PAB    2  FALSE  2411  2410  2410  2607  FALSE   TRUE  2411 -88888  2410  FALSE
New candidate PV    0     2   TRUE     0  2410  2607  2607  2411  2410
    Candidate: i/ip/level    2     2     1 f7f6 b6b8 c5c4 d2c3 a3a4  2409  2607
PAB    2   TRUE 99999  2409  2607  2510  FALSE   TRUE  2410 -88888  2410  FALSE
  New PV: i/ip/level    1     2     1 f7f6 b6b8 c5c4 d2c3  2409  2510
PAB    3  FALSE  2511  2510  2510  2367  FALSE   TRUE  2511 -88888  2607  FALSE
  Next Line: i/ip/level    3     3     1 g7h7 d2c1 c5c4 c1b2  2510  2367
PAB    4  FALSE  2511  2510  2510  2384  FALSE   TRUE  2511 -88888  2607  FALSE
  Next Line: i/ip/level    3     4     1 a3a2 d2c3 a2f2 c3b3 f2f4  2510  2384
PAB    5  FALSE  2511  2510  2510  2181  FALSE   TRUE  2511 -88888  2607  FALSE
  Next Line: i/ip/level    5     5     1 g7f8 b6h6 a3a2 d2c3 b3b2  2510  2181
 2510  2605 :  2410  2607  2367  2384  2181
-99999 99999 : f7f6 c5c4 a3a2 g7h7 g7f8
 1766 SCORED   131 /  132 POSNS.    2 /    5  DEPTH =    3    13     0
In SEARCH length/flag(1)/best_scr ~= most/alpha/beta/reply
          3     1  2510  2607 -99999 99999     2

Awit's move is:
   50.   ... Pf6  
   
Note the small patch on 28 Feb of AB(LEVEL) := SIDE*B_SCR ; seems to fix this problem.
---------------------------------
24 Feb'09
In the following sequence
?6
20 3 0 3
?f
yes
pc3
.        Pd5
?lj5
play
play
?r0
Bg4
play
play

a node is lost.  The suggested fix is to change TERMINATE from:
        IF IP > 1 AND (LEVEL > 1 OR MX > MOST)
        THEN BEGIN
          NODETO(ROOT,0) := IP ;
to
        IF IP > 1 AND (LEVEL > 1 OR MX > MOST)
        THEN BEGIN
          if ip >= idone
          then NODETO(ROOT,0) := IP ;
          
only rarely was this a problem, so the fundamental issue may well be eslewhere.
The earlier code in TERMINATE where we see:
      IF IP > IDONE      
      THEN begin      
        if partial and nodeto(root,ip) > 0 then  
          write("TERMINATE May be losing nodeto(root,0)/IP/root/nodeto(root,ip)",
                nodeto(root,0), IP, root, nodeto(root,ip)) ;        
        NODETO(ROOT,0) := IF PARTIAL                          
                          THEN IP - 1                          
                          ELSE IP ;      
      end ;
appears to be OK.
-----------------------------   
        
27 Feb'09
In TERMINATE consider one condition test change from

comment this next small block questionable.  Already ip > 0, so only enter if level = 1
        but is that possible in TERMINATE? ;
          IF LEVEL = 1 AND IP > 0
          THEN BEGIN
            write("In TERMINATE mx/most/score(try(ip))/ip", mx, most, score(try(ip)), ip) ;
            REPLY := 1 ;
            MOST := MAXSC(PATH) := MX ;
          END ;
to
          comment this next small code segment is questionable.
                  Already ip > 0, so only enter if level = 1
                  but is that possible in TERMINATE? ;
          comment IF LEVEL = 1 AND IP > 0 ;
          IF LEVEL = 1 AND mx > most
          THEN BEGIN
            comment doubt if this block is ever executed ;
            write("In TERMINATE mx/most/score(try(ip))/ip",
                   mx, most, score(try(ip)), ip) ;
            REPLY := 1 ;
            MOST := MAXSC(PATH) := MX ;
          END ;
------------------------
28 Feb'09
In TREE change initialization of AB(LEVEL) from
  SIDE := -SIDE ;
  IF TEST
  THEN WRITEON(REASON(FINAL), PLEX, TYPE) ;
  AB(LEVEL) := MX ;
to
  SIDE := -SIDE ;
  IF TEST
  THEN WRITEON(REASON(FINAL), PLEX, TYPE) ;
  AB(LEVEL) := side*b_scr ;
-------------------------------------
28 Feb'09
In MARKTREE look at the node reclamation mechanism of
         for i := nodeto(root,0) step -1 until 1 do
             if node = nodeto(root,i) then begin
               Reclaim_Node(node, "MARKTRE") ;
                 comment collect(node, root) ;
                 comment nodeto(root,i) := 0 ;
             end ;
consider replacement by:
         for i := nodeto(root,0) step -1 until 1 do
             if node = nodeto(root,i) then begin
                 comment Reclaim_Node(node, "MARKTRE") ;
               collect(node, root) ;
               nodeto(root,i) := 0 ;
             end ;
latter mechanism seems to work better and is consistent with scheme elsewhere in that procedure.
------------------------
28 Feb'09

badden% grep SERIOU *28Feb*
badden% grep DIS *28Feb*
badden% grep CHECK *28Feb*
badden% grep EMER *28Feb*
EMERGENCY setting IP to Zero    2 -66666  1137
EMERGENCY setting IP to Zero    2   424   431
badden% grep INCON *28Feb*
----------------------------------
1Mar'09
Speed mode (80, 3, 0, 5)
no
5R1K6PP85P1Q5B285N28+884Q382P5P71P2B1P1R4RK1+                                 TFFFFFTQH7+              R M 33 (26)
?lj
 Rb ::    ::    Rb Kb ::
 :: Pb ::    Bb Nw Pb
 Pb ::    ::    ::    ::
 ::    Pb    :: Bw ::
    ::    ::    Pw    QW
 ::    ::    Qb    ::
    ::    ::    :: Pw Pw
 ::    ::    :: Rw :: KW
Mar 01 2009 09-MH1.0 WHITE'S MOVE 26.
.   Qh7+ forces a quick draw by repetition Kxf7, Qg6+, kg8, qh7+, kf7 Kg6+ draw  Kg8 Qh7+ Kf7 (perhaps too deep).
Even better is
qh5, any followed by Bg6 with forced mate.  Study of this position led to the following change.
------------------------------
3 Mar'09

Proposed change to OPPONENT includes reclaiming the discarded tree when both CBOTH and BOTH are
TRUE, and also REPLY <= NODETO(ORIGIN,0)
replace
        END ;
        write("Near end OPPO lastorigin/origin/reply/nodeto(origin,reply)",
        lastorigin, origin, reply) ;
        if reply <= nodeto(origin,0) then write(nodeto(origin,reply)) ;
      END ELSE REPLY := 0 ;
with
        END ;
        write("Opponent both/cboth/lastorigin/origin/reply/nodeto(origin,0)",
              both, cboth, lastorigin, origin, reply, nodeto(origin,0)) ;
        if BOTH and ~CBOTH and origin > 0 then
        if reply <= nodeto(origin,0) and nodeto(origin,reply) > 0 then begin
          for i := 1 until nodeto(origin,0)
          do if i ~= reply then Reclaim_Node(nodeto(origin,i), "OPPON-1") ;
          lastorigin := origin ;
          origin := nodeto(origin,reply) ;
          nodeto(lastorigin,0) := -1 ;
          Reclaim_Node(lastorigin, "OPPON-2") ;
          nodeto(lastorigin,0) := reply ;
        end else INIT_TREE ;
        end ;
      END ELSE REPLY := 0 ;
move the above insert into the location where "PLAY" is invoked, or rather after the move is recognized
and played.   Probably leave exactly where it is.

The sequence that was used to track down the above problem was:
NO
5R1K6PP85P1Q5B285N28+884Q382P5P71P2B1P1R4RK1+                                 TFFFFFTQH7+              R M 33 (26)
?LJ5
Qh5
play
.        Qg1+
Rxg1
play
.           not a white move like Bh7+, but Rxf7 for Black and no other problems.

Another useful sequence (case when move is not a natural sequence) is
NO
R2Q1RK15PPPP2BPN23P48883B4-8884N1B13Q42N5PP3PPP4R1K1-                         TFFFFFTBxd8             15>M    (15)
?lj5
warning
Nxd8
play
.         Qa4
kf8
.            not another Black move
-------------------------------
Speed mode
no
R4RK1P3QPP15N1PN2P46B184P38-88Q788P1N2PP11P1N2BPR3R1K1-                       TFFFFFTQe2              45-M  1 (18)
?lj4
warning
play
.		Qxa4
.	Qe6
.		Kh8
.      segmentation fault at white's move 20 
.      NOT REPEATABLE.
.	Bf4
             
-------------------------------------------
10 Mar'09
Again seeing PAB Infinite-Error-Loop message in EXPAND.  Add a CNT < 3 test and make exisiting tests
on CNT consistent with CNT < 3 (i.e., will print the PAB message twice before giving up.
change
        IF AGAIN        
        THEN EXP := TRUE        
        ELSE BEGIN
to
        if CNT < 3 then
        IF AGAIN        
        THEN EXP := TRUE        
        ELSE BEGIN
--------------------------------------------
10 Mar'09
The following sequence leads to a PAB Infinite-Lopp error avoidance
?f6
20 5 0 3
?f
no
R2QKB1RPP1NPPPP8N1P2B22P5888-8883P4Q72N1PN1PPP3PP1R1B1KB1R-                   FTTFTTFNf3-d2           13=O  1 ( 9)
?lj
warn
play
.		Pe5
play
.	Bg3
play
.		Bf5
play
.	Qb3
play
.		Bxc5
play
.	Qxb7
-------------------------------------------
13 Mar'09
Am looking at a couple of examples where the same node appears in the game tree at two locations, 
one for Black and one for White!!  Have no idea how this could possibly come about,  Nevertheless,
can recognize the inconsistency and am working to delete such nodes and return them to the
GETNODE() free workspace.  The suggested changes here are along those lines.
The problem shows itself with a pair of messages like:
Inconsistent root ~= parent node/root/parent(node)/depth   27    20 40017 20000
Inconsistent root ~= parent node/root/parent(node)/depth   27    17 20020 40000
Sent subtree root/i/node for collection   17     2    27

In MARKTREE revise the criteria for collecting an inconsistent node.

13 Mar'09
In MARKTREE chnage handling of the "Inconsistent" message case.
      if ROOT ~= PARENT(NODE) rem packer
        then write("Inconsistent root ~= parent node/root/parent(node)/depth",
                  NODE, ROOT, PARENT(NODE), DEPTH) ;
to
      if ROOT ~= PARENT(NODE) rem packer
      then begin
        write("Inconsistent root ~= parent node/root/parent(node)/depth",
                  NODE, ROOT, PARENT(NODE), DEPTH) ;
        if GETNODE(MAXL) ~= NODE and GETNODE(POINT+!) ~= NODE then
          Reclaim_Node(NODE, "MARK-1") ;
        for i := 1 until NODETO(ROOT,0)
        do if NODETO(ROOT,i) = NODE
           then NODETO(ROOT,i) := 0 ;
      end ;
----------------------------------------------------------------
14 Mar'09
Revised Reclaim_Node procedure to read:
PROCEDURE Reclaim_Node (integer root; string(7) value location) ;
begin
  if root > 0 then begin
     if maxl < maxtree then begin
       maxl := maxl + 1 ;
       getnode(maxl) := root ;
       getnode(maxl+1) := 0 ;
     end else if point > 0 then begin
       getnode(point) := root ;
       point := point - 1 ;
     end
     else begin
       write("RECLAIM_NODE cannot return", root, " to getnode list") ;
       goto OUT ;
     end ;
     if warning then
       write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
     for i := nodeto(root,0) step -1 until 1 do
     if nodeto(root,i) > 0 then
       Reclaim_Node(NODETO(root,i), "RECLAIM") ;
OUT:
  end ;
END OF_Reclaim_Node ;
------------------------------
Have hit upon a segmentation fault and infinite loop problem with very small tree.  Will temporarily 
prevent the infinite loop with a protective patch to COLLECT
from
         ELSE IF (ROOT = PARENT(NODE) REM packer)
              THEN BEGIN
                if dummy4 then write("Entering COLLECT node/root", NODE, ROOT) ;
to
         ELSE IF (ROOT = PARENT(NODE) REM packer) and ROOT ~= NODE
              THEN BEGIN
                if dummy4 then write("Entering COLLECT node/root", NODE, ROOT) ;
------------------------------------
14 Mar'09
In INSERT_NEW_MOVES try to simplify the effect of move insertion
replace

                   FOR I := IN UNTIL S-1
                   DO SHIFT(I+1, I, ROOT) ;
                 END ;
                 GOTO INSERTED ;
by

                   SHIFT(S, IN, ROOT) ;
                 END ;
                 GOTO INSERTED ;
--------------------------
15 Mar'09 
Obscure error in handling blocked passed pawns is emerging.   Perhaps better to change size of SEC
array to   INTEGER ARRAY SEC(-1::1, 0::99) ;
In PP_BLOCK change
  V := 0 ;
  L := K*SEC(0,SQ+INC) ;

to
  V := 0 ;
if SQ < 81 and inc > 0 or sq > 18 and inc < 0 then begin
  L := K*SEC(0,SQ+INC) ;
  .....
end ;

Similar problem in POTENTIAL
In speed mode
no
81K68888P71Q6-8N7882K52Q1P388-                                                TFFTFFFPa7              15$E    (77)
?lj5
.	77.	Qg2+
play
.	Ka1
play
.	78.	Qf1+
play
.	Kxa2
play
.	79.	Qc4+
play
.	Kb2
play

  New PV: c4d4 b2c2 d4f2 c2d1 f2f1 -99999 -1231
awit.a:2565:26: array subscript error: subscript 1 of 'cols' = 91, outside the range (10::89)

In Main declarations change:
  INTEGER ARRAY COLS, ROWS (10::89) ;

to
  comment INTEGER ARRAY COLS, ROWS (10::89) ;
  INTEGER ARRAY COLS, ROWS (0::99) ;

Change INITIALIZE from
    COLS(10) := 0 ;
    FOR I := 1 UNTIL 8
    DO FOR J := 0 UNTIL 9
       DO BEGIN
         FILL := BRDWIDTH*I + J ;
         ROWS(FILL) := I ;
         COLS(FILL) := J ;
    END ;
    
to
    FOR I := 0 UNTIL 9
    DO FOR J := 0 UNTIL 9
       DO BEGIN
         FILL := BRDWIDTH*I + J ;
         ROWS(FILL) := I ;
         COLS(FILL) := J ;
    END ;
------------------------------
Another problem with lack of node space leading to "CHECK" error
?f6
32 5 0 8
?f
y
?lj5
Pd4
Nf6
Pg3
Pg6
Bg2
Bg7
Bg5
o-o
Pc4
warning
play
.       Nc6
play
.       6. Na3
play
.       Rf8-e8
play
.       7. Pd5
play
.       Ne5
play
.       8. Pc5
play
.       Ph6
play
.       9. Bh4
play
.       Pd6
play
.       10. Qd4
play

No resolution to this problem yet.  Simply cannot hold enough positions when MAXTREE is 32, 
but need to do so.  The 5-ply and 8-move width simply too great.  Great stress test, though.
---------------------------
15 Mar'09
A draw by repetition example - small glitch in original file.
no
888884K3P71Q6-88882K4Q888-                                                   TFFTFFFK e6 15>E                 (96)
?flj5
warn
Qg6+
Ke7
Qg7+
Ke8
Qg8+
Kd7
Qf7+
play
.		100		Kc8
?p
play
.       100             Qe8+
?p
play
.       101     Kc7
?p
play
.       101             Qe7+
?sg
play
.       102     Kc8
?p
----------------------------------------------
16 March'09
                            
In TERMINATE revise EST_scr calculation for draw score
from
      EST_scr := IF FINAL = 3
                 THEN IF ENDGAME AND ~DRAWS(K) AND DRAWS(-K)
                      THEN SIDE*3*DRAW
                      ELSE IF ENDGAME AND ~DRAWS(-K) AND DRAWS(K)
                           THEN -SIDE*3*DRAW
                           ELSE -SIDE*(DRAW -(IF EXPECT > 0
                                        THEN LEVEL
                                        ELSE -LEVEL))
to
      EST_scr := IF FINAL = 3
                 THEN IF ENDGAME AND ~DRAWS(K) AND DRAWS(-K)
                      THEN SIDE*3*DRAW
                      ELSE IF ENDGAME AND ~DRAWS(-K) AND DRAWS(K)
                           THEN -SIDE*3*DRAW
                           ELSE -SIDE*(DRAW -(IF EXPECT > 0
                                        THEN LEVEL
                                        ELSE LEVEL))
                                                        
Still chasing the DRAW by REPETITION example.  In NODAL change
    FINAL := 0 ;
    OLD := FALSE ;
FOUNDUPLICATE:

to
    FINAL := 0 ;
    OLD := FALSE ;
    if NODE = 0 then 
      goto EXIT ;
FOUNDUPLICATE:

-------------------------------------------------------------------------
17 Mar'09
Change Marktree and Reclaim_Node to check that a node is only reclaimed once.
from
      if ROOT ~= PARENT(NODE) rem packer
      then begin
        write("Inconsistent root ~= parent node/root/parent(node)/depth",
                  NODE, ROOT, PARENT(NODE), DEPTH) ;
        if GETNODE(MAXL) ~= NODE and GETNODE(POINT+!) ~= NODE then
          Reclaim_Node(NODE, "MARK-1") ;
        for i := 1 until NODETO(ROOT,0)
        do if NODETO(ROOT,i) = NODE
           then NODETO(ROOT,i) := 0 ;
      end ;
to
      if ROOT ~= PARENT(NODE) rem packer
      then begin
        write("Inconsistent root ~= parent node/root/parent(node)/depth",
                  NODE, ROOT, PARENT(NODE), DEPTH) ;
                  
          Reclaim_Node(NODE, "MARK-1") ;
        for i := 1 until NODETO(ROOT,0)
        do if NODETO(ROOT,i) = NODE
           then NODETO(ROOT,i) := 0 ;
      end ;
      
also Reclaim_Node from
PROCEDURE Reclaim_Node (integer root; string(7) value location) ;
begin
  if root > 0 then begin
     if maxl < maxtree then begin
       maxl := maxl + 1 ;
       getnode(maxl) := root ;
       getnode(maxl+1) := 0 ;
     end else if point > 0 then begin
       getnode(point) := root ;
       point := point - 1 ;
     end
     else begin
       write("RECLAIM_NODE cannot return", root, " to getnode list") ;
       goto OUT ;
     end ;
     if warning then
       write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
     for i := nodeto(root,0) step -1 until 1 do
     if nodeto(root,i) > 0 then
       Reclaim_Node(NODETO(root,i), "RECLAIM") ;
OUT:
  end ;
END OF_Reclaim_Node ;

to
PROCEDURE Reclaim_Node (integer root; string(7) value location) ;
begin
  if root > 0 then begin
     for i := POINT+1 until MAXL do
     if ROOT = GETNODE(i)
     then goto OUT ;
     if maxl < maxtree then begin
       maxl := maxl + 1 ;
       getnode(maxl) := root ;
       getnode(maxl+1) := 0 ;
     end else if point > 0 then begin
       getnode(point) := root ;
       point := point - 1 ;
     end
     else begin
       write("RECLAIM_NODE cannot return", root, " to getnode list") ;
       goto OUT ;
     end ;
     if TEST then
       write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
     for i := nodeto(root,0) step -1 until 1 do
     if nodeto(root,i) > 0 then
       Reclaim_Node(NODETO(root,i), "RECLAIM") ;
OUT:
  end ;
END OF_Reclaim_Node ;

Am designating this version as MH1.1      17 March 2009
----------------------------------------------------------------
?f6
600 7 0 12
yes
?flj4
warning
play
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
yes
?sg
yes
---------------------------------------------
18 Mar'09
Changing optional rate of play statistics from
          WRITE("CPU, ELAPSE, ELA/MOVE, LEFT(time, moves), LIMBS/SEC") ;
          WRITE(CT, ELAPSEDTIME DIV 60, CTIME, TIME_LEFT DIV 3600,
            MOVES_LEFT+1, (LIMBS*60) DIV CPU) ;
to
          I_W := 3 ;
          WRITE("CPU=", CT, " ELAPSE=", ELAPSEDTIME DIV 60, " ELA/MOVE=", CTIME, " LEFT(time=", 
                TIME_LEFT DIV 3600, " moves=", MOVES_LEFT+1, ") LIMBS/SEC=", (LIMBS*60) DIV CPU) ;
          I_W := 5 ;
--------------------------------------------
21 March'09
Still a small problem with lost nodes.   Study LOOKIngAHEAD code section:
        if NODETO(ROOT,IP) > 0 then
        if IP <= NODETO(ROOT,0)
        then begin
          if warning then
            write("LOOKing delete node", NODETO(ROOT,IP), IP, "<=", NODETO(ROOT,0)) ;
          if dummy4 then
            write("Look level/root/point/maxl/ip/limit/nodeto(root,ip)/nodeto(root,0)") ;
          if dummy4 then
            write(LEVEL, ROOT, POINT, MAXL, IP, limit, NODETO(ROOT,IP), NODETO(ROOT,0)) ;
          if warning then
            write("Should we return", NODETO(ROOT,IP), " to getnode list? ",
                  if IP > NODETO(ROOT,0) then "Yes!" else "No!", POINT, MAXL) ;
          if IP > NODETO(ROOT,0) then
            Reclaim_Node(NODETO(ROOT,IP), "LOOKin") ;
        end else begin
            comment here we know that IP > NODETO(ROOT,0) and therefore that
                  NODETO(ROOT,IP) has not yet been linked into the tree ;

          if dummy4 and NODETO(ROOT,0) > 0 then
            for j := NODETO(NODETO(ROOT,IP),0) step -1 until 1 do
              if NODETO(NODETO(ROOT,IP),j) > 0 then
                if PARENT(NODETO(ROOT,IP)) rem packer = ROOT then
                  write("LOOKing-2 Will lose node",
                         NODETO(ROOT,IP), IP, NODETO(ROOT,0), ROOT,
                         PARENT(NODETO(NODETO(ROOT,IP),j)),
                         PARENT(NODETO(ROOT,IP)), NODETO(NODETO(ROOT,IP),j),
                         j, NODETO(NODETO(ROOT,IP),0)) ;
        end ;
        NODETO(ROOT, IP) := 0 ;
        
try replacing with
        if NODETO(ROOT,IP) > 0 then
        if IP <= NODETO(ROOT,0)
        then begin
          if warning then
            write("LOOKing delete node", NODETO(ROOT,IP), IP, "<=", NODETO(ROOT,0)) ;
          if dummy4 then
            write("Look level/root/point/maxl/ip/limit/nodeto(root,ip)/nodeto(root,0)") ;
          if dummy4 then
            write(LEVEL, ROOT, POINT, MAXL, IP, limit, NODETO(ROOT,IP), NODETO(ROOT,0)) ;
          if warning then
            write("Not returning", NODETO(ROOT,IP), " to getnode list? ") ;
        end else begin
            comment here we know that IP > NODETO(ROOT,0) and therefore that
                  NODETO(ROOT,IP) has not yet been linked into the tree ;

          if warning and NODETO(ROOT,0) > 0 then
            for j := NODETO(NODETO(ROOT,IP),0) step -1 until 1 do
              if NODETO(NODETO(ROOT,IP),j) > 0 then
                if PARENT(NODETO(ROOT,IP)) rem packer = ROOT then
                  write("LOOKing-2 Will lose node", NODETO(ROOT,IP)) ;
        end ;
        NODETO(ROOT, IP) := 0 ;

                                
Also in Reclaim_Nodes
    if TEST then
      write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
replace by
    if warning then
      write(location, " reclaimed node", root, "p=", point, "maxl=", maxl) ;
      
In LOOKingAhead
          if IP > NODETO(ROOT,0) then
            Reclaim_Node(NODETO(ROOT,IP), "LOOKin")
          else if warning
               then write("May be losing node", nodeto(root,ip)) ;
-------------------------
22 March'09
Found a new sequence leaqding to "DISASTER avoided"
Speed mode (the default)
yes
?lj5
warn
Pc3
play
.		Pd5
play
.	Pd4
play
.		Pe6
play
.	Pe3
play
.		Bd6
play
.	Nf3
play
.		Nf6
.	?m
.	dummy4
play
.	Bd3
play
.		o-o
?spg
----------------------------
22 March'09
Revise FindLostNode and Treverse from:
PROCEDURE FindLostNode ;
begin
  for i := 1 until maxtree do
    holding(i) := 0 ;
  for i := point+1 until maxl do
    holding(getnode(i)) := getnode(i) ;
    TraverseTree(origin) ;
  write("The lost node(s) is(are)") ;
  for i := 1 until maxtree do if holding(i) = 0 then writeon(i) ;
END OF_FindLostNode ;


PROCEDURE TraverseTree (integer node) ;
begin
if node > 0 then begin
  for i := nodeto(node,0) step -1 until 1 do
    TraverseTree(nodeto(node,i)) ;
  holding(node) := node ;
end ;
END OF_TraverseTree ;

to
PROCEDURE FindLostNode ;
begin
  for i := 1 until maxtree do
    holding(i) := 0 ;
  for i := point+1 until maxl do
    holding(getnode(i)) := getnode(i) ;
    TraverseTree(origin) ;
  write("The lost node(s) is(are)") ;
  for i := 1 until maxtree do 
    if holding(i) = 0 or holding(i) > i then writeon(i) ;
END OF_FindLostNode ;

PROCEDURE TraverseTree (integer node) ;
begin
if node > 0 then begin
  for i := nodeto(node,0) step -1 until 1 do
    TraverseTree(nodeto(node,i)) ;
  holding(node) := holding(node) + node ;
end ;
END OF_TraverseTree ;

In DEADTREE a change in the Node Count Error section becomes:
      IF new_count < 0 then begin
        write("Node Count Error ", new_count, nodecount, POINT, MAXL, MAXTREE) ;
        iocontrol(2) ;
        new_count := 0 ;
        FindLostNode ;
        iocontrol(2) ;
      end else
----------------------------------------
22 Mar'09
Created new version of awit.alg at this point.  Deleted all output with dummy4/5/6
Version MH1.2
Changed name of FindLostNode to DisplayLostNodes
-------------------------------------------------
22 Mar'09
Decided to revise COLLECT along the lines of Reclaim_Nodes, so that the overflow condition
MAXL >= MAXTREE is ruled out.
In COLLECT replace
                IF MAXL >= MAXTREE THEN BEGIN
                  WRITE("COLL", POINT, MAXL, NODE, L, PARENT(NODE)) ;
                  FOR I := 1 UNTIL 10 DO WRITEON(GETNODE(I)) ;
                END ELSE
                BEGIN
                  if dummy4 then writeon("storing node", NODE) ;
                  MAXL := MAXL + 1 ;
                  GETNODE(MAXL) := NODE ;
                  REUSE := MAXL ;
with
                ptr := POINT ;
                IF MAXL < MAXTREE THEN
                  ptr := MAXL := MAXL + 1
                else if POINT > 0 then begin
                  POINT := POINT - 1 ;
                end else WRITE("COLLect", ptr, POINT, MAXL, NODE, L, PARENT(NODE)) ;
                  if dummy4 then writeon("storing node", NODE) ;
                  GETNODE(ptr) := NODE ;
                  REUSE := MAXL ;
-------------------------------
Study reason for LOOKing-2 message.  Replace "warning" with "TEST" to control output.

In COLLECT change
                ptr := POINT ;
                IF MAXL < MAXTREE THEN
                  ptr := MAXL := MAXL + 1
                else if POINT > 0 then
                  POINT := POINT - 1
                else begin
                   WRITE("COLLect", ptr, POINT, MAXL, NODE, L, PARENT(NODE)) ;
                end ;
 to
                ptr := POINT ;
                IF MAXL < MAXTREE THEN
                  ptr := MAXL := MAXL + 1
                else if POINT > 0 then
                  POINT := POINT - 1
                else begin
                  WRITE("COLLect", ptr, POINT, MAXL, NODE, L, PARENT(NODE)) ;
                  DisplayLostNodes ;
                  iocontrol(2) ;
                  for i := point+1 step 1 until maxl do begin
                    writeon(holding(i)) ;
                    if i rem 20 = 0 then iocontrol(2) ;
                  end ;
                  iocontrol(2) ;
test := true ;
if marktree(origin, lastorigin, 0, 0) then ;
test := false ;
                  tracer(2, "?9K") ;
                end ;
so that more to look at should a COLLect failure occur again.
-----------------------
1-12 April'09 
There continues to be an inconsistency between self-play mode and manual-play mode.
The following script illustrates the problem and in self-play mode the program terminates with a
very unusual error (never seen before), in which all the node space is distributed into the
game tree, and yet the program believes that all those nodes are available for use!
?6
100 5 0 8
yes
?flj5
warn
Pc3
.       Pc3              0B*E    ( 1)
Pd5
?44
play
yes
yes
yes
yes
?sp
yes
.            This script does work, in contrast with the user forces both sides version,
.            and yet the user forcing version yields a better move for White at move 24.
With the above script or variations of it we get:l
23:48:13    Apr 02 2009
            Awit                      PLYR
REAL mins:     2                         0
CPU  secs:   117                         0
                    INTERMEDIATE

PC3              9B-E    ( 1) PD5              3B=E
Ng1-f3           28-E  1 ( 2) Nb8-c6           18=E  1
Pd3              18=E  1 ( 3) Pe5              18=E  1
Pg3              38-E  2 ( 4) Ng8-f6           18=E  1
Bg2              18=E  1 ( 5) Bd6              58=E  2
O-O              18=E  3 ( 6) O-O              18=E  2
Nb1-d2           48-E  2 ( 7) Rf8-e8           48=E  2
Nf3-e1           38-E  2 ( 8) Pa6              48=E  2
Nd2-b3           18=O  1 ( 9) Bf5              48=O  1
Bg5              18=O  1 (10) Ph6              88=O  2
Bxf6             18=O  1 (11) Qxf6             28=O  1
Bxd5             18=O  1 (12) Pe4              58=O  3
Bxc6             18=O  2 (13) Pb7xc6           18=O  2
Nb3-a5           28=O  1 (14) Ra8-b8           18=O  3
Qd2              18=O  2 (15) Bh3              28+O  5
Ne1-g2           18=O  3 (16) Pe4xd3           38+O  6
Na5xc6           18=M  4 (17) Rb8-b6           18+M  5
Nc6-d4           18-M  3 (18) Pc5              18+M  4
Qxd3             18=M  3 (19) Pc5xd4           48+M  5
Rf1-b1           18-M  3 (20) Re8-b8           18>M  3
Pc3xd4           18-M  3 (21) Pa5              18+M  2
Pb3              18-M  2 (22) Rb6-c6           18+M  2
Pe4              18=M  1 (23) Rb8-d8           68+M  4
Rb1-c1           18=M  2 (24) Ba3              68+E  4

if ?G is executed at this point then the continuation is below
Rc1xc6           18>M  1 (25) Qxc6             18+M  1
Kf1              18-E  1 (26) Bxg2 +           78+E  2
Kxg2             14+E  2 (27) Qc7         DRAW 28=E  2

if the ?G is not executed the program plays:
Awit's move is:
   25. Kf1   
   
and a couple of moves later fails with a full get node list, but the program thinks it is empty!
Suggestion, do a MARKTREE after each move, or something else that might be equivalent to the 
effect that ?G produces.

Hard to imagine how such a traversal, and restorestates it calls has any significant effect.

After much work, and requiring the self-play confirmation check be made every 3 or 4 moves 
(instead of the standard 5 moves) found that by issuing a ?G after Black's move 24 the 
problem went away.   After more study realized that ?G invokes STARTTHISPROBLEM at the end of its
script.   Ultimately found that the re-initialization done by STARTTHISPROBLEM is beneficial, 
although in principal should not be necessary after every move.   Since it does not affect 
the stored game tree decided to make this re-initialization an essential component of HUB.
Thus in HUB changed 
from
    END ;
    VALUES(BISHOP) := VALUES(KNIGHT)
to
    END ;
    if STARTTHISPROBLEM(TRUE) then ; 
       comment the above is a safety precaution and an attempt
               to make self-play mode consistent with manual play mode ;
    VALUES(BISHOP) := VALUES(KNIGHT)
    
This version is designated MH1.4
----------------------------------------------------
12 Apr'09
To protect against VARS array overflow with 9-ply searches make following change in TREE
from
    ELSE LIMIT : = VARS(LEVEL, LENGTH) ;   comment LIMIT is set when LEVEL >= 3 ;
to
    ELSE LIMIT : = if level > 10 or length > 10
                   then 1 else VARS(LEVEL, LENGTH) ;
                   comment LIMIT is set when LEVEL >= 3 ;
                   
undid the above change and decided to increase size of VARS array with
comment
  INTEGER ARRAY VARS(1::vars_depth, 1::vars_depth) ;
  INTEGER ARRAY VARS(1::15, 1::15) ;
comment    raising VARS limit to 15 on 12 April 2009 ;

and with the following insert in INITIALIZE
    for i := 1 until 15 do
      for j := 1 until 15 do
        vars(i,j) := 1 ;
    comment 12 April'09 increase to VARS array, endabling 13-ply search depth ;
    FOR I := 1 UNTIL 10
    DO BEGIN
      IOCONTROL(1) ;
      FOR J := 1 UNTIL 10
      DO READON(VARS(I,J)) ;
    END ;
    
also change MAIN program default settings from
  MAXLEV := CONVERTS(U, INERR) ;
  IF INERR
  THEN GO TO ENTRY ;

to
  MAXLEV := CONVERTS(U, INERR) ;
  IF INERR
  THEN GO TO ENTRY ;
  if MAXLEV > vars_depth - MAXPLY then begin
    write("MAXLEV restricted to:", vars_depth-maxply) ;
    write("Increase size of VARS array to", MAXLEV+MAXPLY) ;
    MAXLEV := vars_depth - MAXPLY ;
  end ;
  
also add:
  E_Depth := 91 ;       comment generalizing Carey Bloodworth suggestion ;
  vars_depth := 15 ;

and in main declarations:
          DEPTH_LIMIT, WIDTH_LIMIT, packer, new_count, old_count, vars_depth ;
  LOGICAL REVERSIBLE, PPIN, ENDGAME, OPENING, LOG1, LOG2, MONITOR,
------------------------------------------------------
13 April'09
Unit 3 used to input initialization data arrays
and then later was used to exchange information via the COKO flag.  Disabled via COMMENT.

Unit 9 used to write the HISTORY file in procedure GAMERECORD
Unit 7 used to output move under control of the COKO flag.
Unit 4 used to output debug information under control fo the MONITOR flag.
Also used to output the board in procedure REFLECT, but that procedure is no longer used!
Unit 5 is standard input
Unit 6 is standard output



13 Apr'09
Considering turning on the COKO flag to see if I can make Awit play against another computer,
in this case awit itself.


---------------------------------------------------------------------------
16 April'09
Again seeing "Parent mismatch" infinite loop with simple script.  This situation arises when
Awit is run from a directory where the book is not present, that is where the book does not exist.
Note also the robustness of this failure, since program fails in similar way if MAXTREE is increased
from 100 to 200 (i.e., the problem is not just one of shortage of node space)

?f6
100 3 0 30
?f
yes
?lj5
Na3
?44
warning
Pg5
?sp
?44
no
play
play
play
play
play
?sp
play

Change the location in COLLECT where the loop is detected to limit the length of the loop and
provide so debugging data.
Change from:
              else begin
                if warning
                then write("Not stored. Parent mismatch root/parent/node",
                            root, parent(node), node, nodeto(root,0),
                            point, maxl);
comment
Not stored. Parent mismatch root/parent/node   65 30000    29
Not stored. Parent mismatch root/parent/node   65 30000    78
Not stored. Parent mismatch root/parent/node   65 30000    23
Not stored. Parent mismatch root/parent/node   65 30000    43
Not stored. Parent mismatch root/parent/node   65 30000    29
    leads to infinite loop ;
              end ;

change to
              else begin
                if warning
                then write("Not stored. Parent mismatch root/parent/node",
                            root, parent(node), node, nodeto(root,0),
                            point, maxl);
                tracer(3, "?SPK") ;
                  comment avoids potential infinite loop ;
              end ;

The above is probably not the best fix, since it avoids the problem instead of addressing it.

23:06:05    Apr 17 2009
            PLYR                      Awit
REAL mins:     0                         1
CPU  secs:     0                        20
                       SPEED

NA3              9B=E    ( 1) PG5              1B-E
Pe4             .28=E  1 ( 2) Pd5             .61-E  1
Qh5             .75=E  2 ( 3) Ng8-f6          .19-E  1
Qxg5            .15=E  1 ( 4) Rh8-g8          .14=E  1
Qe3             .25-E  1 ( 5) Pd5xe4          .15-E  1
Pb3             .31-E  2 ( 6) Nb8-c6          .45=E  2
Ng1-h3          .25-E  2 ( 7) Pe5             .35=E  2
Bb2             165-E  4 ( 8)
NODES  4274 TERMINAL  1066 DYNAMIC   147 CAPTURE  1485
SALVAGE   669 DUPLIC    39 RECLAIM    65 BRANCH 149820
DUP_TREE    10 REC_TREE   100 BRAN_SCORED 93162

------------------------------------------------------------------
17 Apr'09
In DEADTREE remove any duplicated node from the getnode list 
by replacing
        write("Node Count Error ", new_count, nodecount, POINT, MAXL, MAXTREE) ;
        iocontrol(2) ;
        new_count := 0 ;
        DisplayLostNodes ;

with
        write("Node Count Error ", new_count, nodecount, POINT, MAXL, MAXTREE) ;
        iocontrol(2) ;
        new_count := 0 ;
        DisplayLostNodes ;
        for i := 1 until maxtree do
          if holding(i) > i then
          for j := point+1 step 1 until maxl
          do if getnode(j) = i then begin
            getnode(j) := getnode(point+1) ;
            point := point + 1 ;
          end ;
          
The above insert seems to correct the problem identified by test position "17Apr'09B Test.txt"
---------------------------------------------------------------------
18 Apr'09
Working with back-up version of Awit (awit.obj).  Add infinite loop breaking code to COLLECT
    INTEGER L, ptr ;
    counter := NodeSequence(0) ;
    IF NODE > 0
and
              else begin
                if warning
                then write("Not stored. Parent mismatch root/parent(node)/node",
                root, parent(node), node) ;
                if warning
                then write("nodeto(r,0)/counter/NodeSequence(c)", nodeto(root,0),
                counter, NodeSequence(counter));
                for i := 1 until counter do
                if node = NodeSequence(i)
                then counter := 20 ;
                counter := counter + 1;
                if counter > 20 then begin
                  comment DisplayLostNodes ;
                  tracer(4, "?SPGK") ;
                end ;
                NodeSequence(0) := counter ;
                NodeSequence(counter) := node ;
                  comment avoids infinite loop ;
              end ;
and global declaration
  integer counter ; integer array NodeSequence(0::20) ;

but did not include the "double-dipping" cleanup from DEADTREE.
Removed the above data-gathering patch in version MH1.5 below and reconciled the two versions
--------------------------------------
19 Apr'09
Added labels to the Awit_Table.txt file and read and print those labels by replacing all
IOCONTROL(1) in procedure INITIALIZE with

IOCONTROL(1) ;
readcard(BUFFER) ;
comment writecard(BUFFER) ;

everywhere.

Changed version number to MH1.5 to reflect the need for edited Awit_Table.txt file
----------------------------------------------
13 July 2009
Generalized Algebraic so that it can accept more general move descriptions beyond
simple pawn move like ed (pawn on e file captures "something" on d file).  Moves accepted now
include ed5 (pawn on e file captures on d5), Rfe1 (Rook on f1, or f file,  moves to e1) and also
R8e4 (Rook on e8, or on row 8, moves to e4).  New generalized forms include
<man><row><to-square>  and <man><col><to-square>

@TITLE, "ALGEBRAIC"

................common code ommitted..................

comment TAM July 2009.  Code generalised to handle abreviated notation.
            Possible formats remaining for <move> are:
  <move> :== <to-sq> | <man><to-sq> | <man><from-sq><to-sq> | <man><col><to-sq>
                     | <man><row><to-sq>
  <to-sq> :== <oper><col><row>
  <oper> :== NIL | - | * | : | X
  <from-sq> :== <col><row>
  <col> :== 1 .. 8              mapped from A .. H
  <row> :== 1 .. 8
  <man> := P | R | N | B | Q | K | NIL
;
.................... details of actual changes omitted................
ERROR:
  NULLMOVE := TRUE ;
QUIT:
END OF_ALGEBRAIC ;
----------------------------------------------------------------
7 September 2009  Version number changed to 09-MH1.6
There appears to be a genuine bug in Awit in Early Opening mode where the
program sometimes does not find a book move, so generates a tree.  Subsequently, 
should Awit re-enter the book it then has problems when leaving the book for a 
second time, becuse it tries to search the previously generagted tree!

In USEBOOK replace (this addition fixes the above problem)
           LISTMOVES ;
           BOOK := -1 ;
           REPLY := 0 ;
           IF ~GETMOVE(U)
with
           LISTMOVES ;
           BOOK := -1 ;
           INIT_TREE ;   Comment added 7 September 2009.  Book enter, exit,
                                 re-enter problem ;
           REPLY := 0 ;
           IF ~GETMOVE(U)
The following is the test sequence that identifies the problem in versions 09-MH1.5
and earlier.   
?6
600 5 0 15
yes
tournament
?o
?lj
play
.            expect Pb3    if not then retract and force
d5
.            should leave the book at this point
.            computer plays Ng1-f3
nf6
.            computer re-enters book and plays Pe3  from book
e6
.            computer plays Bb2 from book
bd6
.            computer plays Pc4 from book
o-o
.            computer plays Nb1-c3 from book
c5
.            no more book
.            get error: "DISASTER, bad HASH AVOIDED" and search failure.

--------------------------------------------------------------------------------
18 Sept'09
Discovered that the commands BLITZ, INTERmediate, TOURNament and EXPERimental
do not work properly.  The idea behind these commands was that one would start
Awit with the "?6" command and enter numbers like "1500 9 0 25" to set the
workspace size to 1500, the search depth to 9 ply and width to 25 moves, and then 
use the BLITZ, INTERmediate, TOURNAMENT and EXPERimental commands to select a mode 
of play.  Actually doing so causes index errors!  Although these procedures existed
in the 1986 version of Awit, they must have been new and not tried in the general 
case of a mode changed after a game starts.

Problem solved by modifying the procedures BLITZ, INTERMEDIATE, TOURNAMENTS and
EXPERIMENTAL along the same lines, as indicated by changes to BLITZ
from
PROCEDURE BLITZ ;
BEGIN
  MODE := 3 ;
  MAXLEV := 3 ;
  MAX_PLIES := MAXLEV + MAXPLY ;
  MAX_WID := WIDTH := 9 ;
  INIT_TREE ;
  WRITE("BLITZ mode: ", "maxlev=", MAXLEV,
        "max_plies=", MAX_PLIES, "max_wid=", MAX_WID) ;
END OF_BLITZ ;

to
PROCEDURE BLITZ ;
BEGIN
  MODE := 3 ;
  MAXLEV := 3 ;
  MAX_PLIES := MAXLEV + MAXPLY ;
  MAX_WID := WIDTH := 9 ;
  INIT_TREE ;
  WRITE("BLITZ mode: ", "maxlev=", MAXLEV,
        "max_plies=", MAX_PLIES, "max_wid=", MAX_WID) ;
  write("Re-starting.  Type REPEAT followed by either PLAY or a move") ;
  goto starts ;
END OF_BLITZ ;
------------------------------version changed to 09-MH1.7-------------------
3 Oct'2009
Have noted that although Awit accepts a checking move of the form Qe1+, it cannot
accept a move of the form Qe1++ (i.e. checkmate).  This rejection seems unduely 
restrictive.  The following change in ALGEBRAIC should suffice:
replace
         IF T = "+"
         THEN BEGIN
           REW(0) := REW(0) + CHECKING ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
         END ;

with
         while T = "+"
         do BEGIN
           REW(0) := REW(0) + CHECKING ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
         END ;

--------------------------------------------------------------------------- 
5 Oct'09
Create version 09-MH1.8
Experiment with restoration of "COKO" flag to enable play with another computer.
Basically take opponent move from unit 3 and send move to rival on unit 7. 
In COMPUTER replace
    IF COKO AND FALSE
    THEN BEGIN
                      COMMENT switch i-o units ;
      PUT(7) ;
                      COMMENT switch o-p to unit 7 ;
with
    IF COKO
    THEN BEGIN
                      COMMENT switch i-o units ;
      PUT(3) ;
                      COMMENT switch o-p to unit 3 ;

In OPPONENT replace
    IF COKO AND FALSE
    THEN GET(3) ;
                        COMMENT take input from unit 3 ;
with
    IF COKO
    THEN GET(7) ;
                        COMMENT take input from unit 7 ;
                        
The trouble with the above is that unit 3 seems to be attached to the file
Awit_Table.txt
Note, according to support.c
** Awit uses the following ports / channels.
**
** 1: R text for making book.   CREATEBOOK reads AwitBook.txt
** 2: R/W opening book.     The transposition style book AwitBook.dat
** 3: G read precomputed data file.    Awit_Table.txt
** 3: P Send commands/moves to CoKo, but looks disabled. Awit_Printer.txt
** 4: P optional output.  debugging etc.  Awit_Debug.txt
** 5: G standard input.
** 6: P standard output.
** 7: G Take input from CoKo.  Looks disabled.  Awit_Printer.txt
** 8: R/W History file.  Logs positions in Awit_History.txt   For ?R# command.
** 9: P Game record.    Records moves made in Awit_Game.txt before exiting program.
** G=Get P=Put (Algolw i/o)    R=Read W=Write (MTS i/o)

This fix does not work, because unit 3 is still attached to Awit_data.txt which
is still open.   Possible improvement would be to split the functionality of 
INITIALIZE into two components.  One component is called only once and initializes
long term constants and reads in the data from Awit_Table.txt, the other component
is called on first entry and whenever the ?6 command is used.  A kind of per game
initialization (i.e., proper re-setting to start a new game with new workspace and 
game-tree parameters) instead of a per execution initialization (i.e., the setting 
of defined constants).

The real difficulty is that upon executing GET(3) support.c ensures that
Awit_Table.txt is always attached to that channel.  Thus one can no longer use 
channel 3 to communicate with another program via the COKO flag.  Some thought is
required here, perhaps dedicate a different channel to Awit_Table.txt, or perhaps
also modify Awit as described above so that Awit_Table.txt not attached on a
second use of channel 3.  Could one use channel 7 for Awit_Table.txt input, releasing 
the file once it has been read in so that the channel can be reused? Then use 
channel 7 for input under the COKO flag and channel 3 for output under the COKO flag.
Better might be to use channel 3 for input and COKO output, and channel 7 for COKO
input (instead of output as at present).

See that support.c writes to Awit_Printer.txt but seemingly only one move.  Are 
the moves written on top of each other, perhaps? 

Saved support.c in supportSave.c and Awit_Table.txt in Awit_SaveTable.txt
and modified support.c to accept get(7) and put(3), using Awit_Printer.txt as
the intermediary i/o file.   The mechanism has some potential, but perhaps 
running Awit under and execution monitor is a better bet.

--------------------------------------------------------------------------
18 Oct'09
Decided to force Awit to flush its output buffer immediately after displaying a move.
This flushing may help with output control when Awit is run under the control of
an execution monitor.  In practice made no difference.  Buffering in support.c ?
In COMPUTER change
    FOR I := 0 UNTIL 23
    DO WRITEON(MC(I)) ;
    WRITEON(BELL) ;
    IF COKO AND FALSE
to
    FOR I := 0 UNTIL 23
    DO WRITEON(MC(I)) ;
    WRITEON(BELL) ;
    iocontrol(2) ;         comment this line deleted on 5 November ;
    IF COKO AND FALSE
----------------------------------------------------------------------------
5 Nov'09
The 18 Oct'08 modification did not solve the buffering problem, so deleted it.
Decided instead to modify Carey Bloodworth's support.c by changing
  else if (Channel == 6)^M
    {^M
      alw_active_printer = &alw_stdout_printer;^M
    }^M

to 
  else if (Channel == 6)^M
    {^M
        setbuf(stdout, NULL);
      alw_active_printer = &alw_stdout_printer;^M
    }^M

This modification, reasonably enough, solved the buffering problem in Awit-Awit monitor.
-------------------------------------------------------
6 Nov'09
Using the new Awit-Awit move exchange monitor, find that when White generates a move 
of say PD4 or d2d4  The opposing program that is playing Black cannot accept the 
incoming move as valid (GETMOVE() responds "Try Again PD4").  Initially, not at all clear what 
the problem might be, since Pd4 is accepted by Awit running alone.  Problem persists
even if the COKO flag is set to force full move description.  It seems that any non-printable 
charcter in the move string causes failure.

The <bell> is a non-printing character and is appened to every outgoing move to alert the
operator that a move has been made.  On the recipient side all trailing blanks are stripped from
the input move, but this action does not remove the <bell> character that is present in computer
to computer games.  What is worse, if the question ".DRAW?" or termination ".RESIGN" is 
added to the move string, then the <bell> precedes these comments.

Simply deleting the sending of a <bell> character after every move would get round this problem in
Awit v Awit games. As far as alerting the operation, a double <bell> prompt is given in OPPONENT 
anyway.  The fix, below, solves the Awit v Awit monitor problem directly

In COMPUTER replace
    FOR I := 0 UNTIL 23
    DO WRITEON(MC(I)) ;
    WRITEON(BELL) ;
with
    FOR I := 0 UNTIL 23
    DO WRITEON(MC(I)) ;

As an additional safeguard, the READU procedure in Awit contains script to strip 
trailing blanks.  That is being changed to strip non-printable characters,
including BLANK.  
                       COMMENT strip trailing blanks ;
    WHILE (CHARCOUNT >= 0) AND (BUFFER(CHARCOUNT|1) = BLANK)
        DO CHARCOUNT := CHARCOUNT - 1 ;

this is being changed to
                       COMMENT strip trailing blanks and non-printing chars;
    WHILE (CHARCOUNT >= 0) AND (BUFFER(CHARCOUNT|1) <= BLANK)
        DO CHARCOUNT := CHARCOUNT - 1 ;

which is very ASCII-specific but may help with input from other computers.
------------------------------------------------------------------------------
7 Nov'09
Achieved the first successful match between two versions of Awit playing
against each other under an execution monitor that my son, Ian, and I put 
together.  The intent was to play a 25-move match, but after 14 moves both sides
transmitted an EOF mark on their output stream and both versions of Awit terminated
normally with a "STOP" command from the monitor.  The reason for the early
termination is because Awit was just transitioning from the Opening to
the Middlegame phase, and the following lines were output:
A: START MIDDLE GAME BLACK
A: START MIDDLE GAME WHITE
The "ST" in START was interpreted as part of a "STOP" command.  A small change
to the monitor will solve this problem.
-------------------------------------------------------------------------------
10 Nov'09
With the following example, Awit is not recognizing the notation for a discovered check.

Enter the board (in quasi Forsythe notation)
1R1K2N15PP17P882P588-881N6B5P1P2P45P22P4K1R6-                                 TFFFFFTPH3               R E  7 (34)
    Rb    ::    ::    ::
 ::    Pb    ::    :: Kb
    :: Pw ::    Pb    ::
 Pb    :: Pb ::    ::
 Bb ::    ::    :: Pb ::
 :: Nb ::    ::    :: Pw
    ::    ::    Pw Pw ::
 :: Rw :: KW ::    Nw
Nov 10 2009 09-MH1.8 BLACK'S MOVE 34.

BLACK'S MOVE    34 

Nc5 -+*

 TRY AGAIN NC5-+*

Problem seems to be in ALGEBRAIC
change
         while T = "+"
         do BEGIN
           REW(0) := REW(0) + CHECKING ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
         END ;
to
         while (T = "+") or (T = "-") or (T = "*") 
         do BEGIN
           REW(0) := REW(0) + CHECKING ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
         END ;
------------------------------------------------------
10-15 Nov'09
New verion 09-MH1.9 reflecting better discovered check handling in INSERT_NEW_MOVES.

In the following the move Bf3 +-  (double check) is initially #2 on the list, and 
it is not searched as part of the 3-ply tree.  Why?  It is dropped in favour of the 
discovered check moves.  Probably something to do with move re-ordering where there
are several moves with the same piece.  Double check more powerful than Discovered
Check.

Problem with the insertion of sacrificial checking moves, causing other good 
(checking) moves to be pushed out of sight (out of tree width).  Issue is only with 
use of ?J flag (Capture_tree).  

Problem seems to be in BUILD_SACR_TREE or lower.  One apparent problem is that sacrificial
checking moves replace other checking moves.  Especially problem when discovered checks are
present.  They could even replace a double check!

replace in INSERT_NEW_MOVES
               IF SCR >= SCORE(TRY(J))
                     AND (SCR > TOP OR J > J_MAX OR J > BEST_J)
                  OR ~NEW AND J = TW
               THEN BEGIN
with
               if abs(reward(try(j))) >= twocheck
               then begin
                 if warning then
                   write("Don't replace double check moves") ;
               end else
               IF SCR >= SCORE(TRY(J))
                     AND (SCR > TOP OR J > J_MAX OR J > BEST_J)
                  OR ~NEW AND J = TW
               THEN BEGIN
               
 Another issue is that "sacrificial" moves are not inserted within 5 moves of the best one.
 This means no insertions on narrow searches.  Probably OK, but could allow one, perhaps.
 
 Simplify INSERT_NEW_MOVES by 
 changing from
                 IF ~SHUFFLE
                 THEN SHIFT(S, IN, ROOT)
                 ELSE BEGIN
                   IF S <= IDONE AND IN > IDONE
                   THEN BEGIN
                     COLLECT(NODETO(ROOT,S), ROOT) ;
                     NODETO(ROOT,S) := -1 ;
                     IDONE := IDONE - 1 ;
                     IF MONITOR or dummy4 THEN WRITE("REDUCE ", ROOT, S, IDONE) ;
                   END ;
                 comment
                   FOR I := IN UNTIL S-1
                   DO SHIFT(I+1, I, ROOT) ;
                   shift(s, in, root) ;
                 END ;
                 GOTO INSERTED ;
to
                 IF SHUFFLE
                 THEN
                   IF S <= IDONE AND IN > IDONE
                   THEN BEGIN
                     COLLECT(NODETO(ROOT,S), ROOT) ;
                     NODETO(ROOT,S) := -1 ;
                     IDONE := IDONE - 1 ;
                   END ;
                 SHIFT(S, IN, ROOT) ;
                 GOTO INSERTED ;

Another discovered check position which seemed problematic now retains the double-check move

3K1B2PPP2B24Q38886R18-88883BP33Q2PPPP61K1R4-                                  TFFFFFT    ....                 (19)
?k
FAILURE.  Either type REPEAT, or
New game? (YES or NO)
rep
    Kb    Rb    ::    ::
 Pb Pb ::    ::    Rw
    ::    Qb    :: Pb Pb
 ::    :: Bb Pb    ::
    ::    ::    ::    ::
 ::    ::    QW    ::
 Pw Pw Pw ::    Bw    ::
 ::    :: KW :: Bw ::
Nov 11 2009 09-MH1.8 BLACK'S MOVE 19.

Added print statements to SACR_TREE like:
IF TEST or warning and level < 3

delete all similar temporary "warning and level < 2" inserts
----------------------------------------------------------
18 Nov'09
Added a print stmt in ALGEBRAIC-- for Awit-Awit monitor
replace
           IF NEXT(T) AND T = "D"
           THEN IF (SCORE(RTMV) < + PAWNVALUE)
             THEN BEGIN
               WRITE("DRAW ACCEPTED") ;
               GO TO STARTS ;
             END ELSE MESSAGE1 := "DRAW NOT ACCEPTED AT THIS TIME" ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
 with
            IF NEXT(T) AND T = "D"
           THEN begin
             IF (SCORE(RTMV) < + PAWNVALUE)
             THEN BEGIN
               WRITE("DRAW ACCEPTED") ;
               comment tracer(2, "?SP") ;
               GO TO STARTS ;
             END ELSE MESSAGE1 := "DRAW NOT ACCEPTED AT THIS TIME" ;
             write("Draw was offered") ;
           end ;
           IF ~NEXT(T)
           THEN GO TO ERROR ;
------------------------------------------
18 Nov'09
Output game score when terminating in HUB (e.g. resigns) -- for Awit-Awit monitor
replace
QUITting:  comment KTEST ~= 0 ;
  WRITE(REASON(KTEST)) ;
  PRINTSHORTBRD(1) ;
  TRACER(3, "?DGD") ;
END OF_HUB ;
with
QUITting:  comment KTEST ~= 0 ;
  WRITE(REASON(KTEST)) ;
  PRINTSHORTBRD(1) ;
  TRACER(5, "?SPDGD") ;
END OF_HUB ;
------------------------some small changes lost here, when files transferred-------------
------------------------the changes are cosmetic, as below, and formed version 09-MH2.0--
22 November'09
In GAMERECORD replace
  WRITE("DUP_TREE ", DUP_S, "REC_TREE ", REC_S, "BRAN_SCORED ", BRAN_S)
   ;
by
  WRITE("DUP_TREE ", DUP_S, "REC_TREE ", REC_S, "BRAN_SCORED ", BRAN_S)
   ;
  write("maxtree = ", maxtree, " maxlevel = ", maxlev, " maxwidth  = ", width) ;
In INIT_TREE replace
    write("Entering INIT_TREE ");
by 
  if warning then
    write("Entering INIT_TREE ");
In INITIALIZE replace
   write("        Awit_Hist.txt LineCount =", COUNT) ;
with
   write("        Awit HistoryFile  LineCount =", COUNT) ;
------------------------------------------------------------------------------------------
