Learn from a loss

Learn from a loss. More...


Files

file  learn.c
 Learn from a loss - source file.
file  learn.h
 Learn from a loss - header file.

Defines

#define P_LIMIT   0x8000
 Polynomial limit.
#define NTAB_SIZE   (NUM_PLAINS * 9)
 Size of n_table[] - (# of plains) x (# of permutations per trap).

Functions

static void _addentry (W_ENTRY *word)
 Add an entry to n_table[].
static void _exit (void)
 Add entries in n_table[] to MEM_FILE.
static int _find_c_move (short plain)
 Find move that results in a trap.
static void _init (void)
 Perform initialization for learn_1().
static void _permutations (int plain, W_ENTRY *word, int offset, int c_offset)
 Generate all valid trap permutations from a given trap.
static int _plain_win (short plain)
 Determine if a win is present in a plain.
static int _replay (W_ENTRY *word)
 Replay the game withing a plain.
void learn_1 (void)
 Learn from a loss.

Variables

static W_ENTRY n_table [NTAB_SIZE+1]
 Table for new traps.
static int w_count
 W count.
static int a_stones
 A stones.
static int trap_found
 Was addentry() called?

Detailed Description

Learn from a loss.

This routine is called when a computer loses a game. The idea is to see whay we loast and store that info for later use. First the plain is found in which the win was made, that is, the plain that has 4-in-a-row and 3-in-a-row for the opponent. Then all of the computer's mvoes are removed from that plain. Then each opponent's move is removed from the plain, checking to see if a win still results. If so, continue. Otherwise replace the move. Then, computer moves ared added to the plain if the don't affect the outcome of a win. The result is that we have a plain which indicates opponent moves that must be present, a plain which indicates spaces that must be blank, and a plain which indicates the last move that resulted in the trap.

Each line in MEM_FILE is in the following format:

a_plain b_plain

where a_plain = stones that must be present for a first level trap. where b_plain = stones that must be empty for a first level trap.


Define Documentation

#define NTAB_SIZE   (NUM_PLAINS * 9)
 

Size of n_table[] - (# of plains) x (# of permutations per trap).

#define P_LIMIT   0x8000
 

Polynomial limit.


Function Documentation

static void _addentry W_ENTRY word  )  [static]
 

Add an entry to n_table[].

Parameters:
word W_ENTRY * : trap to add to n_table[].
Returns:
void.

static void _exit void   )  [static]
 

Add entries in n_table[] to MEM_FILE.

Returns:
void.

static int _find_c_move short  plain  )  [static]
 

Find move that results in a trap.

Returns:
int : the offset in plain that resulted in a trap.

static void _init void   )  [static]
 

Perform initialization for learn_1().

Returns:
void.

static void _permutations int  plain,
W_ENTRY word,
int  offset,
int  c_offset
[static]
 

Generate all valid trap permutations from a given trap.

Parameters:
plain int : plain.
word W_ENTRY * : trap.
offset int : position to start making moves.
c_offset int : move that results in a trap.
Returns:
void.

static int _plain_win short  plain  )  [static]
 

Determine if a win is present in a plain.

Parameters:
plain int : input plain.
Returns:
int.
Return values:
TRUE - a win is present.
FALSE - a win is not present.

static int _replay W_ENTRY word  )  [static]
 

Replay the game withing a plain.

Parameters:
word W_ENTRY * : plain, moves already taken by Alpha and beta.
Returns:
int.
Return values:
TRUE - Alpha wins.
FALSE - Alpha does not win.

learn_1 void   ) 
 

Learn from a loss.

Returns:
void.


Variable Documentation

a_stones [static]
 

A stones.

n_table [static]
 

Table for new traps.

trap_found [static]
 

Was addentry() called?

w_count [static]
 

W count.


Generated on Sat Sep 24 09:00:12 2011 for ScoreFour by  doxygen 1.4.5