Page 1 of 3

Any Fortran coder ?

Posted: Thu Nov 15, 2018 7:52 pm
by ker2x
Friendly greetings !

I'm writing a chess engine (my 1st engine ! yay !), using fortran.

I'm not sure which board representation would be a best fit for this language.

Techincally, fortran doesn't have uint64_t (only signed) but it should be a very major problem if the bitfield is only used for bit manipulation, and not math.
Another option could be a logical matrix (a 2d array of boolean) but it may kind of defeat the effectiveness of a bitboard.
Or it could be any other board representation, probably.

i don't know. Any idea ?

The source code is here https://github.com/ker2x/fortiche but it doesn't do anything at all, for now.

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 8:15 pm
by maksimKorzh
Congratulations with your first attempt! Just curious - why Fortran?

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 8:47 pm
by Dann Corbit
I did Fortran in the 70's and 80's. All the sample programs and stuff you can find will be quite old and out of date as far as the latest techniques go.
There is a guy here who wrote "Six_Fortran_95_tools" and he is probably much more helpful for Fortran stuff.
Robert Hyatt, who wrote Crafty certainly knows a lot about Fortran.

Here is a Fortran chess program:
https://github.com/arbolis/fortranchess ... /chess.f90

There is a thread here about it:
https://groups.google.com/forum/#!topic ... IGLGF3CdMY

I added the sample fortran77 program from f77bench (kind of old) as an attachment.

The Fortran source for Cray Blitz is still around. I have several versions of it.

I had a Fortran95 chess program at one time, but I don't remember where I put it.

I am doing a disk grep for it now, and I will see if I can find it.

Since integers are signed in Fortran, bitwise operations would be a problem, but some Fortran compilers allow inline assembly.
You could also do an interface to C++ for that bit.

If you want it all in portable Fortran code, then one of the mailbox/array techniques is probably best.

I found a project that looks interesting called sigma chess which has some of the code in Fortran:

Code: Select all

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine

2013-08-29  05:27 PM             4,677 Engine.f
               1 File(s)          4,677 bytes

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine\Data Structures

2013-08-29  05:27 PM             2,092 Attack.f
2013-08-29  05:27 PM             2,216 Board.f
2013-08-29  05:27 PM             2,066 Move.f
               3 File(s)          6,374 bytes

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine\Evaluation

2013-08-29  05:27 PM             1,999 Evaluate.f
2013-08-29  05:27 PM             1,923 Mobility.f
2013-08-29  05:27 PM             1,969 PieceVal.f
               3 File(s)          5,891 bytes

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine\Misc

2013-08-29  05:27 PM             1,889 EndgameDB.f
2013-08-29  05:27 PM             2,070 HashCode.f
2013-08-29  05:27 PM             2,041 Time.f
               3 File(s)          6,000 bytes

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine\Move Generation

2013-08-29  05:27 PM             2,335 MoveGen.f
2013-08-29  05:27 PM             1,958 PerformMove.f
               2 File(s)          4,293 bytes

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine\Searching

2013-08-29  05:27 PM             1,896 MateSearch.f
2013-08-29  05:27 PM             2,200 Search.f
2013-08-29  05:27 PM             2,035 SearchMisc.f
2013-08-29  05:27 PM             1,924 Selection.f
2013-08-29  05:27 PM             1,886 Threats.f
2013-08-29  05:27 PM             2,022 TransTables.f
               6 File(s)         11,963 bytes

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 9:06 pm
by ker2x
@maksimKorzh : thank you. i do it in fortran because i can and fortran is awesome. No real practical reason.

@dann : Thank you for the code and info, i'll take a look.

Btw, any idea how i can do multi-threading working on both windows and linux ?
I also considered multiprocessing + MPI but i don't see how i can make it works on both plateform again.

i'm using gfortran (and the simply fortran IDE). My main development plateform is windows (at home) but i'm a linux sysadmin, so... i want both and windows is a pain to deal with.

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 9:31 pm
by hgm
I think I never got beyond Fortran 60 (or something like that), before I switched to other programming languages. Fortran 77 already appeared 'after my time'... Problem used to be that you couldn't do recursion; I don't know if later Fortrans fixed that.

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 10:06 pm
by ker2x
Fortran changed, you can still do old fashined fixed form fortran and stuff but you can also do freeform fortran, or Object Oriented Fortran :roll:

Modern compiler even have auto vectorization and auto parallelization, so loop can run on mutiple core without having to write a single line of additional code, i'm pretty sure it's inherited from cray fortran compiler.

But i wish it had intrinsic for multithreading however :(

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 10:11 pm
by Dann Corbit

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 10:50 pm
by ker2x
Yes, i know this one. but i don't want to do SIMD (well, i'll also do it but it's a different problem) so openmp, coarray, cuda, isn't a solution for this case (i already planned to use openmp for the computation part).

From this list only MPI could do the job and i don't know if i can use openmpi on both windows and linux without having to write tons of #ifdef windows/linux to make it portable.

Re: Any Fortran coder ?

Posted: Thu Nov 15, 2018 10:57 pm
by ker2x
and running open mpi app is a bit of a pain for the user :mrgreen:

Re: Any Fortran coder ?

Posted: Fri Nov 16, 2018 12:31 am
by brianr
hgm wrote: Thu Nov 15, 2018 9:31 pm I think I never got beyond Fortran 60 (or something like that), before I switched to other programming languages. Fortran 77 already appeared 'after my time'... Problem used to be that you couldn't do recursion; I don't know if later Fortrans fixed that.
Tinker's great grandfather started in Fortran. I did recursion just fine with an explicit stack. It was pretty straightforward, as I recall.