#I think I might've made a race condition in a single threaded program????

14 messages · Page 1 of 1 (latest)

lilac ocean
#

Ok, so I am trying to make an engine to calculate chess moves. I've already got the chess game, so the first step for the engine would be calculating all possible moves. So, i did that, but each time i run my program, it gives a different output. I've spent the whole day trying to debug this, but i cant. Here are some of my observations:

  • Some moves always show 0 for how many moves there are down the line, such as h2h4
  • Others just float around the expected number, sometimes a bit lower, sometimes on the expected number. It increases or decreases by around 20, indicating some branches are probably being cutoff
  • when I try to debug something by, say, only generating the moves down the line for h2h4, it magically works and outputs the expected number

I am 99.9% sure the problem is in the search.rs file, but i dont even know anymore.
The project is available at https://github.com/LeandroVandari/Chess.git

Any help would be much appreciated, even if it is a suggestion on why i should scrape and rewrite the whole thing :p, i just wanna get this solved

GitHub

Chess coded in rust :). Contribute to LeandroVandari/Chess development by creating an account on GitHub.

leaden folio
#

Have you looked at that yet?

lilac ocean
#

i thought of that, but it shouldn't matter, as i was specifically trying to make it work to multi-thread it later. Also, wouldn't explain why, for example, h2h4 always is 0, unless i only do its moves

leaden folio
#

the easiest way to check if that's the problem is to just find/replace every HashSet/HashMap in your program with BTreeSet/BTreeMap to rule that out

lilac ocean
#

at least the program will be consistent

leaden folio
#

If that's not it, then I'd have to look a bit more closely

lilac ocean
#

ok so now it's consistent

#

but the result is always

b1c3: 400
g1f3: 380
g1h3: 320
a2a3: 320
a2a4: 0
b2b3: 320
b2b4: 0
c2c3: 320
c2c4: 0
d2d3: 400
d2d4: 0
e2e3: 440
e2e4: 0
f2f3: 220
f2f4: 0
g2g3: 220
g2g4: 0
h2h3: 180
h2h4: 0```
#

(expected):

b2b3: 420
c2c3: 420
d2d3: 539
e2e3: 599
f2f3: 380
g2g3: 420
h2h3: 380
a2a4: 420
b2b4: 421
c2c4: 441
d2d4: 560
e2e4: 600
f2f4: 401
g2g4: 421
h2h4: 420
b1a3: 400
b1c3: 440
g1f3: 440
g1h3: 400```
#

it's always the pawns 2 moves forward that don't work, but i've already checked some stuff and they should be treated equally

#

again, filtering just h2h4 makes it work

#

(also, i've just realized i didn't update the github repo, i'll do that real quick, it'll be on the dev branch)