# Chess Engine in FORTRAN 90

**URL:** <https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715>\
**Category:** Uncategorized\
**Created:** [May 11, 2025, 4:35am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715 "2025-05-11T04:35:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmenezes](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dmenezes](https://fortran-lang.discourse.group/u/dmenezes)\
**Post date:** [May 11, 2025, 4:35am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/1 "2025-05-11T04:35:11Z")

</div>

> **[GitHub - menezesd/FortranChess](https://github.com/menezesd/FortranChess)**
>
> Contribute to menezesd/FortranChess development by creating an account on GitHub.

I’m excited to share **[FortranChess](https://github.com/menezesd/FortranChess)**, a chess engine entirely written in modern Fortran. This project demonstrates Fortran’s capabilities beyond scientific computing, tackling a complex problem like chess with clean, efficient code.

While chess engines are often written in C/C++, this project explores Fortran’s strengths in structured programming and performance optimization—even for non-numerical tasks.

---

<div class="post-metadata">

**Author:** ![waleedmebane](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@waleedmebane](https://fortran-lang.discourse.group/u/waleedmebane)\
**Post date:** [May 11, 2025, 5:46am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/2 "2025-05-11T05:46:37Z")

</div>

Do you use any of Fortran’s parallel features in this project?

---

<div class="post-metadata">

**Author:** ![dmenezes](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dmenezes](https://fortran-lang.discourse.group/u/dmenezes)\
**Post date:** [May 11, 2025, 5:46pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/3 "2025-05-11T17:46:14Z")

</div>

no I do not

---

<div class="post-metadata">

**Author:** ![suprit05](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@suprit05](https://fortran-lang.discourse.group/u/suprit05)\
**Post date:** [May 11, 2025, 6:07pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/4 "2025-05-11T18:07:30Z")

</div>

Welcome! This is great, I played a quick match and it was pretty good! Have you tried estimating it’s Elo at different depths? and how they compare to other engines?

And also do you plan on adding more features? I think adding primary support for [Algebraic notation](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) and also implementing [UCI](https://en.wikipedia.org/wiki/Universal_Chess_Interface) would be great additions to the project.

---

<div class="post-metadata">

**Author:** ![R\_cubed](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/r_cubed/32/263_2.png) [@R\_cubed](https://fortran-lang.discourse.group/u/R_cubed)\
**Post date:** [May 11, 2025, 6:15pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/5 "2025-05-11T18:15:20Z")

</div>

Maybe

> [@suprit05](#):
>
> And also do you plan on adding more features? I think adding primary support for [Algebraic notation](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) and also implementing [UCI](https://en.wikipedia.org/wiki/Universal_Chess_Interface) would be great additions to the project.

With enough work, maybe it could be entered into some computer chess tournaments.

> **[Tournaments and Matches - Chessprogramming wiki](https://www.chessprogramming.org/Tournaments_and_Matches#Various_Tournaments)**

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [May 12, 2025, 1:21am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/6 "2025-05-12T01:21:00Z")

</div>

One of the Founding Fathers of scientific computing, John von Neumann stated " Chess is not a game. Chess is a well-defined form of computation" so its only natural that Chess and Fortran are a good match. The complete quote is [here](https://www.goodreads.com/quotes/12248293-no-no-he-said-chess-is-not-a-game-chess)

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [May 12, 2025, 7:59am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/7 "2025-05-12T07:59:19Z")

</div>

> [@waleedmebane](#):
>
> Do you use any of Fortran’s parallel features in this project?

The only built-in Fortran parallel feature is `do concurrent`. More generally, regular loops or array syntax statements can possibly be parallelized by an optimizing compiler. But I think that task based parallelism is better suited for this kind of algorithm that explores a tree. Fortran doesn’t have tasks yet, but OpenMP can be used for that.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [May 12, 2025, 5:18pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/8 "2025-05-12T17:18:58Z")

</div>

> [@PierU](#):
>
> The only built-in Fortran parallel feature is `do concurrent`.

There are also the coarray features.

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [May 12, 2025, 6:53pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/9 "2025-05-12T18:53:09Z")

</div>

…And asynchronous I/O.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [May 12, 2025, 6:59pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/10 "2025-05-12T18:59:39Z")

</div>

> [@RonShepard](#):
>
> There are also the coarray features.

Of course… Shame on me 🫣…

---

<div class="post-metadata">

**Author:** ![tyranids](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tyranids](https://fortran-lang.discourse.group/u/tyranids)\
**Post date:** [May 13, 2025, 4:05am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/11 "2025-05-13T04:05:29Z")

</div>

> [@PierU](#):
>
> Fortran doesn’t have tasks _ **yet** _, but OpenMP can be used for that.

Emphasis mine, I’d love a native way to do asynchronous, parallel tasks. Something like that would be very useful for more computation-engine-type programs.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [May 13, 2025, 6:30am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/12 "2025-05-13T06:30:10Z")

</div>

There has been some discussions at the commitee level, but it doesn’t seem to be part of F202Y.  
[https://j3-fortran.org/doc/year/23/23-246.txt](https://j3-fortran.org/doc/year/23/23-246.txt)

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [May 13, 2025, 12:13pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/13 "2025-05-13T12:13:24Z")

</div>

@PierU I thought [this one (23-174.pdf)](https://j3-fortran.org/doc/year/23/23-174.pdf) was the one under consideration, isn’t it?

The one you pointed to has the “pure procedures only” restriction, which limits its usefulness when compared to asynchronous implementations in other languages.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [May 13, 2025, 12:31pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/14 "2025-05-13T12:31:26Z")

</div>

Maybe… But this one is from 2023 as well, and I can’t see any recent formal proposal (these one are labelled as “info”).

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [May 13, 2025, 12:49pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/15 "2025-05-13T12:49:38Z")

</div>

The one I mentioned is in this list of accepted items: [https://j3-fortran.org/doc/year/24/24-167.txt](https://j3-fortran.org/doc/year/24/24-167.txt)

Hopefully they won’t drop it.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [May 13, 2025, 5:10pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/16 "2025-05-13T17:10:39Z")

</div>

> [@tyranids](#):
>
> Emphasis mine, I’d love a native way to do asynchronous, parallel tasks.

In addition to OpenMP, which was mentioned previously, one can also do asynchronous tasks using coarray features. Of course, in both cases, OpenMP and coarrays, the compiler plays an essential role. If you want to avoid that compiler participation requirement, then MPI is implemented just through library calls, and it can also do asynchronous task programming.

---

<div class="post-metadata">

**Author:** ![wspector](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@wspector](https://fortran-lang.discourse.group/u/wspector)\
**Post date:** [May 13, 2025, 5:31pm UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/17 "2025-05-13T17:31:04Z")

</div>

> [@PierU](#):
>
> The only built-in Fortran parallel feature is `do concurrent`. More generally, regular loops or array syntax statements can possibly be parallelized by an optimizing compiler.

Array syntax is an expression of SIMD parallelism. It was based on extensions used in a number of Fortran compilers for various parallel and vector machines in the 1970s/1980s. On machines such as the Connection Machines and the CDC CYBER-205, array syntax almost directly translated into machine instructions.

(Though lowly BASIC had array syntax back in the 1960s.)

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [May 14, 2025, 3:28am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/18 "2025-05-14T03:28:00Z")

</div>

@dmenezes great job, and welcome to the forum!

I played a quick game: [chess.txt · GitHub](https://gist.github.com/certik/cdff29033cf885f8cf6c3a81b260df26), it leaves pieces hanging, so I am guessing it is not searching many moves ahead yet.

You might consider implementing the UCI interface, so that you can use it with GUI chessboards.

---

<div class="post-metadata">

**Author:** ![waleedmebane](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@waleedmebane](https://fortran-lang.discourse.group/u/waleedmebane)\
**Post date:** [May 14, 2025, 4:54am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/19 "2025-05-14T04:54:10Z")

</div>

Thanks, I haven’t written any Fortran, but I bought the book _Modern Fortran: building efficient parallel applications_.

I wrote a checkers/draughts playing program using C++ for an AI course in graduate school. I don’t think I tried parallelizing the search, but I tried to make it explore possible moves in the background while waiting for the user to make a move. I believe I used the pthreads library for that, but I’m pretty sure I could have done it with OpenMP.

OpenMP doesn’t seem to be used as much in C++ (I could be wrong), maybe because often the actions are conceptually tasks, but I think OpenMP would be able to handle a lot of that nicely with code that is higher-level and easier to read and program.

I wrote the program quickly because I was so busy in graduate school. I never worked out all of its bugs, and from time to time, I think about re-writing it, maybe not in C++ this time.

---

<div class="post-metadata">

**Author:** ![suprit05](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@suprit05](https://fortran-lang.discourse.group/u/suprit05)\
**Post date:** [May 14, 2025, 5:35am UTC](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715/20 "2025-05-14T05:35:24Z")

</div>

> [@certik](#):
>
> I played a quick game: [chess.txt · GitHub](https://gist.github.com/certik/cdff29033cf885f8cf6c3a81b260df26), it leaves pieces hanging, so I am guessing it is not searching many moves ahead yet.

I played the exact same opening too and after `exd5` the engine played `Qe7+` which is fine, instead of `Bb7+` (the move in your case) which is straight up losing for black… Did you change the depth level in the source code? Or any other possible reason?

[Next page](https://fortran-lang.discourse.group/t/chess-engine-in-fortran-90/9715.md?page=2)
