winning.boards[i] o.score

Aim
To explore and research how the new components in Occam-Pi can
be used in realising algorithms based on zero-sum perfectinformation games such as Chess, Checkers and Tic-Tac-Toe.
The first two ply of the game tree for tic-tac-toe.
Game Algorithms
Replicated from http://en.wikipedia.org/wiki/Image:Tic-tac-toe-game-tree.png
The moves of a zero-sum (the gains of one player result in losses to
the other) perfect-information (games in which all players know the
moves previously made by all other players) game, can be
represented with a game tree which is a directed graph where the
nodes are positions in the game, and the edges are moves.
The game tree can then be searched to find the best move to make
using algorithms such as the minimax algorithm.
Games such as Tic-Tac-Toe have relatively small game trees which
can be fully evaluated, whereas games like Chess have incredibly
large game trees which would take far too long to fully evaluate and
require great amounts of processing power to be able to produce
good results.
Why occam-pi?
As game algorithms require vast amounts of processing power
being able to run them in parallel on multiple processors allows for
faster game tree searching, so a language such as occam seems
perfect for this type of problem.
However the original occam lacked certain features such as
recursion, which game algorithms heavily rely on. occam-pi solves
this problem as recursion is fully implemented as well as other
extensions such as run-time sized PAR replicators, barriers, variable
sized arrays and safe shared channels, which also aid in the
implementation of game algorithms.
INT FUNCTION static.evaluator (VAL INT
available.moves, VAL BOOL x.move, VAL INT x.board, VAL
INT o.board)
INT score, x.score, o.score:
VALOF
SEQ
x.score, o.score := 0, 0
SEQ i = 0 FOR SIZE winning.boards
IF
((available.moves \/ x.board) /\
winning.boards[i]) = winning.boards[i]
x.score := x.score + 1
TRUE
SKIP
SEQ i = 0 FOR SIZE winning.boards
IF
((available.moves \/ o.board) /\
winning.boards[i]) = winning.boards[i]
o.score := o.score + 1
TRUE
SKIP
IF
x.move
score := x.score - o.score
TRUE
score := o.score - x.score
RESULT score
:
Above: Sample code of a function to
return the score of a move
Left: occGame playing tic-tac-toe
(and winning!)
Third year research project by Kevin Morgan ([email protected])