A recursive Fortran 90 Alpha-Beta search routine [2]:
RECURSIVEFUNCTION EVALUATE (ID, PRUNE)RESULT(RES)USE GLOBALS
IMPLICITINTEGER(A-Z)DIMENSION XX(0:26), YY(0:26), CC(0:26)
LEVEL=LEVEL+1
BESTSCORE=10000*ID
DO B=7,0, -1DO A=7,0, -1! generate the moves for all the pieces ! and iterate through them IF(SGN(BOARD(B,A))/=ID)CYCLECALL MOVELIST (A, B, XX, YY, CC, NDX)DO I=0,NDX,1
X=XX(I); Y=YY(I); C=CC(I)
OLDSCORE=SCORE; MOVER=BOARD(B,A); TARG=BOARD(Y,X)! make the move and evaluate the new position ! recursively. Targ holds the relative value of the piece ! allowing use to calculate material gain/loss CALL MAKEMOVE (A, B, X, Y, C)IF(LEVEL<MAXLEVEL)THEN
SCORE=SCORE+EVALUATE(-ID, &
BESTSCORE-TARG+ID*(8-ABS(4-X)-ABS(4-Y)))ENDIF
SCORE=SCORE+TARG-ID*(8-ABS(4-X)-ABS(4-Y))! we want to minimize the maximum possible loss ! for black IF((ID<0.AND. SCORE>BESTSCORE).OR.&(ID>0.AND. SCORE<BESTSCORE))THEN
BESTA(LEVEL)=A; BESTB(LEVEL)=B
BESTX(LEVEL)=X; BESTY(LEVEL)=Y
BESTSCORE=SCORE
IF((ID<0.AND. BESTSCORE>=PRUNE).OR.&(ID>0.AND. BESTSCORE<=PRUNE))THEN
BOARD(B,A)=MOVER; BOARD(Y,X)=TARG; SCORE=OLDSCORE
LEVEL=LEVEL-1
RES = BESTSCORE
RETURNENDIFENDIF
BOARD(B,A)=MOVER; BOARD(Y,X)=TARG; SCORE=OLDSCORE
ENDDOENDDOENDDO
LEVEL=LEVEL-1
RES=BESTSCORE
RETURNENDFUNCTION EVALUATE
Table of Contents
Fortran is a general purpose, procedural and imperative programming language. Fortran was proposed and designed by John W. Backus as alternative for the IBM 704 assembly language. A draft specification for the IBM mathematical Formula Translating System was completed by mid 1954. The first Fortran compiler appeared in 1957 and was the first widely used high-level programming language. Successive versions have added varios features over the years, such as recursive routines and dynamic memory allocation in Fortran 90. Many early chess programs were written in Fortran.
Punched card
Sample Chess Code
A recursive Fortran 90 Alpha-Beta search routine [2]:See also
Publications
External Links
References
What links here?
Up one Level