how to make a minimax function (chess engine)

edited April 2018 in Questions about Code

I am making a chess engine, and I am currently working on the minimax function( the depthvalue int) but it is not working, and I don't know why. It still sacrifices pieces for no reason. Help is appreciated. This is a challenge, so please don't give me the code, just tell me what went wrong. thank you!

link for all the code and data files are at: https://drive.google.com/open?id=16rXtPHM-3PmtOitzRWh121kf82GBM_Ok

Tagged:

Answers

  • edited April 2018

    Without looking at your code: my intuition tells me you forgot to swap the sign before the value.

    You need to do this so when the other player looses a figure (negative) it’s counted as positive (positive). This I mean with swap sign.

  • edited April 2018

    It still sacrifices pieces for no reason

    And again: To test certain situations like Castling or your current issue "it still sacrifices pieces for no reason" you should have a tool to take back 1-2 moves and to save a position on the chess board. Then you can change your program and just load the situation on the chess board and check the new AI move.

    Later the player anyway would like to be able to save and load a game so he can continue a game the next evening.

    There are also files on the net providing tens or hundreds of position on the chess board and the advisable move (ai result). If you where able to load and run those, you could auto-test your program (your ai). But that's for later...

  • I did not forget to swap the sign, it simply calculates the position, and if the position is worse than before, it rejects that move. I also don't know how to do what you said, to take back.

  • it simply calculates the position, and if the position is worse than before, it rejects that move

    Yes. understood

    But don't you have one move made by ai and one by the player?

    when you calculate the values on the board, one should be counted as positive values, one as negative values. That's the approach I know of

  • yeah ,that's how I'm doing it

  • but it's not working

  • did you check the signs?

  • I checked the signs, I found the problem, sorry for not updating you guys, but I made a valuenull boolean, and forgot to set it to false, making it always move the last piece on the board.

  • Great that you found your error!

Sign In or Register to comment.