bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnubg] Anomolous looking code in eval.c


From: Jim Segrave
Subject: [Bug-gnubg] Anomolous looking code in eval.c
Date: Mon, 15 Jul 2002 16:06:14 +0200
User-agent: Mutt/1.2.5i

This is a miscellenay of things:

First - has something happened to alpha.gnu.org? I haven't been able
to connect to it for a while now to see if there are later snapshots?

Second:

I was looking at the code in eval.c (I'm looking at a variant of a
teaching mode; see below if interested) to see how cube decisions are
evaluated. In the source from gnubg-020701.tar.gz, I find the
following, which may be unreachable code, but...

GetCubeActionSz() 
  calls FindBestCubeDecision () to get an enum of the best cube
  decision. From examining the code, FindBestCubeDecision can return
  any of:

  NODOUBLE_DEADCUBE       
  NO_REDOUBLE_DEADCUBE    
  NOT_AVAILABLE
  DOUBLE_BEAVER           
  DOUBLE_TAKE             
  REDOUBLE_TAKE           
  DOUBLE_PASS             
  REDOUBLE_PASS           
  TOOGOOD_PASS            
  TOOGOODRE_PASS          
  TOOGOOD_TAKE            
  TOOGOODRE_TAKE          
  NODOUBLE_BEAVER             
  NO_REDOUBLE_BEAVER      
  NODOUBLE_TAKE           
  NO_REDOUBLE_TAKE        
  TOOGOOD_PASS            
  TOOGOODRE_PASS          

It then goes through a switch statement, where every one of the above
except NOT_AVAILABLE is accounted for. NOT_AVAILABLE reaches the
'default' case label which does (line 4207..4209)
    4207     iOptimal = OUTPUT_OPTIMAL;
    4208     iOptimal = OUTPUT_OPTIMAL;
    4209     iOptimal = OUTPUT_OPTIMAL;

Nowhere are the the local variables iBest or iWorst set in this case.
But shortly afterwards, 
    4244               gettext ( aszCubeString[ iBest ][
        pci->fCubeOwner != -1 ]
    4244  ),
    4245               arDouble[ iBest ],
    4246               arDouble [ iBest ] - arDouble [ iOptimal ] );
and then:
    4258   pc = strchr ( pc, 0 );
    4259   if ( ! pci->nMatchTo || ( pci->nMatchTo && ! fOutputMWC ) )
    4260     sprintf ( pc, "%-20s: %+6.3f   (%+6.3f)\n\n",
    4261               gettext ( aszCubeString[ iWorst ][
        pci->fCubeOwner != -1 
    4261 ] ),

I don't know if you can ever manage to get to GetCubeActionSz() when
FindBestCubeDecision would return NOT_AVAILABLE, but if you can, bad
things can happen, as the array indices used above will be random and
unlikely to lie in the range 0..2. I suspect that lines 4207-4209
should be:

    4207     iOptimal = OUTPUT_OPTIMAL;
    4208     iBest    = OUTPUT_OPTIMAL;
    4209     iWorst   = OUTPUT_OPTIMAL;

=============================

As to what I was looking for in a Teaching mode:

1) A setting flag fTutor which can be toggled off or on.

2) If fTutor is set, then at certain points throughout the game, a
   check is made on a move (or lack thereof):

a) when a human player give a Roll command. Before rolling the die,
   evaluate potential cube action. If failing to double/redouble would 
   lose equity, warn the user that they are doing somethnig
   'doubful/bad/very bad' - in gtk, with a popup window offering a
   'do it anyway' (= roll dice) or Cancel. This should happen before
   the dice are rolled. In gtk, Cancelling simply puts gtk back to
   waiting for a user action, text mode is perhaps messier, although I
   guess just re-prompting will do.

b) whenever a human player gives an accept or pass to a
   double/redouble. Same evaluation of cube equity.

c) when a human player tries to offer to resign.

d) when a human player completes a move, before it's added to the game
   list and the board is updated. Calculate the move equities in the
   same way the Hint command would do and check that the move is
   legal. If it is legal, and it appears in the list of candidates (if
   it's not listed, assume it's a very bad move), then compare the
   equity with the best moves. Give a warning if the move loses
   sufficient equity over the best move on offer.

The idea, particularly with chequer play, is to warn the student that
they are making a mistake without showing them the best answer. They
can always use the eval or hint commands, but they can also try to
work out for themselves what they've done incorrectly. Of course, with
missed doubles, it's obvious  - how else could you be making a
mistake. It would be better if the warning did not come until the roll
was executed, but that also changes the evaluation of the doubling
decision.

I've done the easy bits - adding a Tutor setting and re-using the
GetYN() routines. I'm now looking at how the evaluations can be done. 
I'm struggling my way through the code which does cube decisions,
trying to see what I can use and how I can ensure that I won't
inadvertantly alter the game state. Then I need to do the same to get
the equity values for a move before it's committed and entered into
the list of moves. I have to admit, although it's hardly surprising,
that the cube equity calculation routines seem difficult to
disentagle. 

Anyone who can give me pointers on the best way to use the existing
routines to:

Decide if cube action is called for and what the equity loss of not
doubling/redoubling is.

Decide if a Take/Pass/Resign is a reasonably good choice

Get a hint list in the form of the raw numeric data for equities.

And of course any warnings about things like 'calling this routine
will screw up the game/match state, so you'll need to copy it and work
n a copy' or similar caveats. 

Also warnings about unexpected and unpleasant interactions - it would
not be good for instance to have pop-ups appear while stepping through
an annotaion window or simply revieing a move list of a completed
game.

And finally - a minor wish-list/suggestion.

I'd like it if it were possible to possble to select a level
(doubtful/bad/vary bad) for cube and chequer play lines in the
annotation window, such that all moves worse than the chosen threshold
were highlighted (perhaps by a different background in that side of
the play list. On those rare occasions when I manage to get through a
lengthy game with gnubg without making too many errors, I may want to
review the analysis and quickly skip to the moves which were
notable. I already know from the show statistics game that there are
only a couple of moves which were marked, but there are 54 unmarked
ones that I don't want to re-examine. Even better would be if the
highlighting could be different for: 

bad cube decisions 
bad chequer play 
both in one move

-- 
Jim Segrave           address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]