Difference between revisions of "Fortran"

From Chessprogramming wiki
Jump to: navigation, search
Line 62: Line 62:
 
=See also=
 
=See also=
 
* [[Basic]]
 
* [[Basic]]
 +
* [[:Category:Fortran|Fortran Chess Programs]]
 
* [[IBM 704]]
 
* [[IBM 704]]
  

Revision as of 23:15, 6 November 2019

Home * Programming * Languages * Fortran

Fortran, (FORTRAN)
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

FortranCardPROJ039.agr.jpg

Punched card from a Fortran program: Z(1) = Y + W(1) [1]

Sample Chess Code

A recursive Fortran 90 Alpha-Beta search routine [2]:

RECURSIVE FUNCTION EVALUATE (ID, PRUNE) RESULT (RES) 
  USE GLOBALS 
  IMPLICIT INTEGER(A-Z) 
  DIMENSION XX(0:26), YY(0:26), CC(0:26) 
  LEVEL=LEVEL+1 
  BESTSCORE=10000*ID 
  DO B=7,0, -1 
     DO A=7,0, -1 
        ! generate the moves for all the pieces 
        ! and iterate through them 
        IF (SGN(BOARD(B,A))/=ID) CYCLE 
        CALL 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))) 
           END IF 
           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 
                 RETURN 
              END IF 
           END IF 
           BOARD(B,A)=MOVER; BOARD(Y,X)=TARG; SCORE=OLDSCORE 
        END DO 
     END DO 
  END DO 
  LEVEL=LEVEL-1 
  RES=BESTSCORE 
  RETURN 
END FUNCTION EVALUATE 

See also

Publications

Forum Posts

External Links

References

Up one Level