Common Lisp Package: REVERSI

README:

FUNCTION

Public

ALPHA-BETA-SEARCHER (DEPTH EVAL-FN)

A strategy that searches to DEPTH and then uses EVAL-FN.

ALPHA-BETA-SEARCHER2 (DEPTH EVAL-FN)

Return a strategy that does A-B search with sorted moves.

ALPHA-BETA-SEARCHER3 (DEPTH EVAL-FN)

Return a strategy that does A-B search with killer moves.

COUNT-DIFFERENCE (PLAYER BOARD)

Count player's pieces minus opponent's pieces.

HUMAN (PLAYER BOARD)

A human player for the game of Reversi

IAGO (DEPTH)

Use an approximation of Iago's evaluation function.

MODIFIED-WEIGHTED-SQUARES (PLAYER BOARD)

Like WEIGHTED-SQUARES, but don't take off for moving near an occupied corner.

RANDOM-REVERSI-SERIES (STRATEGY1 STRATEGY2 N-PAIRS &OPTIONAL (N-RANDOM 10))

Play a series of 2*n games, starting from a random position.

REVERSI-SERIES (STRATEGY1 STRATEGY2 N-PAIRS)

Play a series of 2*n-pairs games, swapping sides.

ROUND-ROBIN (STRATEGIES N-PAIRS &OPTIONAL (N-RANDOM 10) (NAMES STRATEGIES))

Play a tournament among the strategies. N-PAIRS = games each strategy plays as each color against each opponent. So with N strategies, a total of N*(N-1)*N-PAIRS games are played.

WEIGHTED-SQUARES (PLAYER BOARD)

Sum of the weights of player's squares minus opponent's.

Undocumented

REVERSI (BL-STRATEGY WH-STRATEGY &OPTIONAL (PRINT T) (MINUTES +DEFAULT-MAX-MINUTES+))

TEXT-REVERSI

Private

88->H8 (NUM)

Convert from numeric to alphanumeric square notation.

ALPHA-BETA (PLAYER BOARD ACHIEVABLE CUTOFF PLY EVAL-FN)

Find the best move, for PLAYER, according to EVAL-FN, searching PLY levels deep and backing up values, using cutoffs whenever possible.

ALPHA-BETA-SEARCHER3W (DEPTH EVAL-FN)

Return a strategy that does A-B search with killer moves.

ALPHA-BETA2 (PLAYER NODE ACHIEVABLE CUTOFF PLY EVAL-FN)

A-B search, sorting moves by eval-fn

ALPHA-BETA3 (PLAYER BOARD ACHIEVABLE CUTOFF PLY EVAL-FN KILLER)

A-B search, putting killer move first.

ALPHA-BETA3W (PLAYER BOARD ACHIEVABLE CUTOFF PLY EVAL-FN KILLER)

A-B search, putting killer move first.

COMBINE-EDGE-MOVES (POSSIBILITIES PLAYER)

Combine the best moves.

CONCAT-SYMBOL (&REST ARGS)

Concatenate symbols or strings to form an interned symbol

COUNT-EDGE-NEIGHBORS (PLAYER BOARD SQUARE)

Count the neighbors of this square occupied by player.

CROSS-PRODUCT (FN XLIST YLIST)

Return a list of all (fn x y) values.

EDGE-INDEX (PLAYER BOARD SQUARES)

The index counts 1 for player; 2 for opponent, on each square---summed as a base 3 number.

EDGE-MOVE-PROBABILITY (PLAYER BOARD SQUARE)

What's the probability that player can move to this square?

EDGE-STABILITY (PLAYER BOARD)

Total edge evaluation for player to move on board.

FINAL-VALUE (PLAYER BOARD)

Is this a win, loss, or draw for player?

FINAL-VALUE-WEIGHTED (PLAYER BOARD)

Is this a win, loss, or draw for player?

FIND-BRACKETING-PIECE (SQUARE PLAYER BOARD DIR)

Return the square number of the bracketing piece.

GET-MOVE (GAME STRATEGY PLAYER BOARD PRINT CLOCK)

Call the player's strategy function to get a move. Keep calling until a legal move is made.

H8->88 (STR)

Convert from alphanumeric to numeric square notation.

IAGO-EVAL (PLAYER BOARD)

Combine edge-stability, current mobility and potential mobility to arrive at an evaluation.

INIT-EDGE-TABLE

Initialize *edge-table*, starting from the empty board.

INITIAL-BOARD

Return a board, empty except for four pieces in the middle.

MAKE-FLIPS (MOVE PLAYER BOARD DIR)

Make any flips in the given direction.

MAKE-MOVE (MOVE PLAYER BOARD)

Update board to reflect move by player

MAP-EDGE-N-PIECES (FN PLAYER BOARD N SQUARES INDEX)

Call fn on all edges with n pieces.

MAPPEND (FN LIST)

Append the results of calling fn on each element of list. Like mapcon, but uses append instead of nconc.

MAXIMIZE-DIFFERENCE (PLAYER BOARD)

A strategy that maximizes the difference in pieces.

MAXIMIZER (EVAL-FN)

Return a strategy that will consider every legal move, apply EVAL-FN to each resulting board, and choose the move for which EVAL-FN returns the best score. FN takes two arguments: the player-to-move and board

MINIMAX (PLAYER BOARD PLY EVAL-FN)

Find the best move, for PLAYER, according to EVAL-FN, searching PLY levels deep and backing up values.

MINIMAX-SEARCHER (PLY EVAL-FN)

A strategy that searches PLY levels and then uses EVAL-FN.

MOBILITY (PLAYER BOARD)

Current Mobility is the number of legal moves. Potential mobility is the number of blank squares adjacent to an opponent that are not legal moves. Returns current and potential mobility for player.

MOBILITY-SIMPLE (PLAYER BOARD)

The number of moves a player has.

NEGATE-VALUE (NODE)

Set the value of a node to its negative.

NEIGHBORS (SQUARE)

Return a list of all squares adjacent to a square.

NEXT-TO-PLAY (BOARD PREVIOUS-PLAYER &OPTIONAL (PRINT NIL))

Compute the player to move next, or NIL if nobody can move.

NODE-BOARD (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

NODE-SQUARE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

NODE-VALUE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

POSSIBLE-EDGE-MOVE (PLAYER BOARD SQ)

Return a (prob val) pair for a possible edge move.

POSSIBLE-EDGE-MOVES-VALUE (PLAYER BOARD INDEX)

Consider all possible edge moves. Combine their values into a single number.

PUT-FIRST (KILLER MOVES)

Move the killer move to the front of moves, if the killer move is in fact a legal move.

RANDOM-NTH (LIST)

Pick a random element out of a list.

RANDOM-STRATEGY (PLAYER BOARD)

Make any legal move.

STATE-BOARD (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STATE-CLOCK (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STATE-MOVE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STATE-PLAYER (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STATIC-EDGE-STABILITY (PLAYER BOARD)

Compute this edge's static stability

SWITCH-STRATEGIES (STRATEGY1 M STRATEGY2)

Make a new strategy that plays strategy1 for m moves, then plays according to strategy2.

TIME-STRING (TIME)

Return a string representing this internal time in min:secs.

VALID-P (MOVE)

Valid moves are numbers in the range 11-88 that end in 1-8.

WOULD-FLIP? (MOVE PLAYER BOARD DIR)

Would this move result in any flips in this direction? If so, return the square number of the bracketing piece.

Undocumented

AB3-DF (PLY)

AB3-MD-WT (PLY)

AB3-WT (PLY)

AB3W-DF (PLY)

AB3W-MD-WT (PLY)

AB3W-WT (PLY)

COPY-BOARD (BOARD)

COPY-NODE (INSTANCE)

COPY-STATE (INSTANCE)

CORNER-FOR (XSQ)

CORNER-P (SQ)

LIST-TO-DELIMITED-STRING (LIST &OPTIONAL (SEPARATOR ))

LOAD-EDGE-TABLE (&OPTIONAL (PATH *ET-PATH*))

MAKE-EDGE-TABLE

MAKE-GAME (BL-STRATEGY WH-STRATEGY &KEY (PRINT T) (MINUTES +DEFAULT-MAX-MINUTES+) (RECORD-GAME NIL))

MAKE-GAME-MOVE (GAME MOVE PLAYER)

MAKE-MOVES

MAKE-NODE (&KEY ((SQUARE DUM218) (MISSING-ARGUMENT)) ((BOARD DUM219) (MISSING-ARGUMENT)) ((VALUE DUM220) (MISSING-ARGUMENT)))

MAKE-STATE (MOVE PLAYER CLOCK BOARD)

MAKE-STATE-STRUCT (&KEY ((MOVE DUM218) NIL) ((PLAYER DUM219) NIL) ((BOARD DUM220) NIL) ((CLOCK DUM221) NIL))

MM-DF (PLY)

MM-MD-WT (PLY)

MM-WT (PLY)

MOVES-TO-STRING (MOVES)

MX-DF

MX-MD-WT

MX-WT

NAME-OF (PIECE)

SETFNODE-BOARD (NEW-VALUE INSTANCE)

NODE-P (OBJECT)

SETFNODE-SQUARE (NEW-VALUE INSTANCE)

SETFNODE-VALUE (NEW-VALUE INSTANCE)

PIECE-STABILITY (BOARD SQ)

PLAY-GAME (GAME)

REPLACE-BOARD (TO FROM)

RESET-GAME (GAME &OPTIONAL (MOVE-NUMBER 1))

RR (PLY N-PAIRS)

SOME-NEIGHBORS (BOARD OPP NEIGHBORS)

SETFSTATE-BOARD (NEW-VALUE INSTANCE)

SETFSTATE-CLOCK (NEW-VALUE INSTANCE)

SETFSTATE-MOVE (NEW-VALUE INSTANCE)

STATE-P (OBJECT)

SETFSTATE-PLAYER (NEW-VALUE INSTANCE)

STORE-EDGE-TABLE (ET &OPTIONAL (PATH *ET-PATH*))

TITLE-OF (PIECE)

X-SQUARE-FOR (CORNER)

X-SQUARE-P (SQ)

MACRO

Private

Undocumented

AIF (TEST THEN &OPTIONAL ELSE)

AWHEN (TEST-FORM &BODY BODY)

AWHILE (EXPR &BODY BODY)

BREF (BOARD SQUARE)

MISSING-ARGUMENT

OPPONENT (PLAYER)

UNTIL (TEST &BODY BODY)

WHILE (TEST &BODY BODY)

GENERIC-FUNCTION

Private

Undocumented

MAKE-CLOCK (CLOCK)

SLOT-ACCESSOR

Private

BL-STRATEGY (OBJECT)

Strategy function for black

BOARD (OBJECT)

The board configuration

CLOCK (OBJECT)

An array of time-units left

SETFCLOCK (NEW-VALUE OBJECT)

An array of time-units left

FINAL-RESULT (OBJECT)

Final count, is NIL while game in play

SETFFINAL-RESULT (NEW-VALUE OBJECT)

Final count, is NIL while game in play

MAX-MINUTES (OBJECT)

Maximum minites for each player

MOVE-NUMBER (OBJECT)

The number of the move to be played

SETFMOVE-NUMBER (NEW-VALUE OBJECT)

The number of the move to be played

MOVES (OBJECT)

An array of moves played in the game

SETFMOVES (NEW-VALUE OBJECT)

An array of moves played in the game

PLAYER (OBJECT)

ID of next player to move

SETFPLAYER (NEW-VALUE OBJECT)

ID of next player to move

PRINT? (OBJECT)

Whether to print progress of this game

RECORD-GAME? (OBJECT)

Whether to record moves and clcck of this game

WH-STRATEGY (OBJECT)

Strategy function for white

VARIABLE

Private

*BOARD*

A copy of the game board

*CLOCK*

A copy of the game clock

*EDGE-AND-X-LISTS*

The four edges (with their X-squares).

*EDGE-TABLE*

Array of values to player-to-move for edge positions.

*MOVE-NUMBER*

The number of the move to be played

ALL-SQUARES

A list of all squares

Undocumented

*ET-PATH*

*PLY-BOARDS*

*STATIC-EDGE-TABLE*

*TOP-EDGE*

*WEIGHTS*

+ALL-DIRECTIONS+

CLASS

Private

Undocumented

NODE

REVERSI-GAME

STATE

CONSTANT

Private

BLACK

A black piece

EMPTY

An empty square

OUTER

Marks squares outside the 8x8 board

WHITE

A white piece

Undocumented

+DEFAULT-MAX-MINUTES+

LOSING-VALUE

WINNING-VALUE