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? | |
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.
|
|
Size of n_table[] - (# of plains) x (# of permutations per trap).
|
|
|
Polynomial limit.
|
|
|
Add an entry to n_table[].
|
|
|
Add entries in n_table[] to MEM_FILE.
|
|
|
Find move that results in a trap.
|
|
|
Perform initialization for learn_1().
|
|
||||||||||||||||||||
|
Generate all valid trap permutations from a given trap.
|
|
|
Determine if a win is present in a plain.
|
|
|
Replay the game withing a plain.
|
|
|
Learn from a loss.
|
|
|
A stones.
|
|
|
Table for new traps.
|
|
|
Was addentry() called?
|
|
|
W count.
|
1.4.5