SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.07k forks source link

System.IndexOutOfRangeException is thrown unexpectedly #426

Closed Staicu-Ciprian-Stefan closed 11 months ago

Staicu-Ciprian-Stefan commented 11 months ago

Repository is up to date.

Error message

This exception was originally thrown at this call stack: MyBot.DeepThink(ChessChallenge.API.Board, ChessChallenge.API.Timer, double, double, int, int) in MyBot.cs MyBot.DeepThink(ChessChallenge.API.Board, ChessChallenge.API.Timer, double, double, int, int) in MyBot.cs MyBot.DeepThink(ChessChallenge.API.Board, ChessChallenge.API.Timer, double, double, int, int) in MyBot.cs MyBot.DeepThink(ChessChallenge.API.Board, ChessChallenge.API.Timer, double, double, int, int) in MyBot.cs MyBot.Think(ChessChallenge.API.Board, ChessChallenge.API.Timer) in MyBot.cs ChessChallenge.Application.ChallengeController.GetBotMove() in ChallengeController.cs [External Code] ChessChallenge.Application.ChallengeController.Update() in ChallengeController.cs ChessChallenge.Application.Program.Main() in Program.cs

Command window error message

An error occurred while bot was thinking. System.IndexOutOfRangeException: Index was outside the bounds of the array. at MyBot.DeepThink(Board board, Timer timer, Double alfa, Double beta, Int32 player, Int32 depth) in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs:line 59 at MyBot.DeepThink(Board board, Timer timer, Double alfa, Double beta, Int32 player, Int32 depth) in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs:line 32 at MyBot.DeepThink(Board board, Timer timer, Double alfa, Double beta, Int32 player, Int32 depth) in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs:line 32 at MyBot.DeepThink(Board board, Timer timer, Double alfa, Double beta, Int32 player, Int32 depth) in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs:line 32 at MyBot.Think(Board board, Timer timer) in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs:line 8 at ChessChallenge.Application.ChallengeController.GetBotMove() in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\Framework\Application\Core\ChallengeController.cs:line 150 Illegal move: Null in position: r1bqk2r/pppp1ppp/2n1p3/8/3Pn3/P1PB1N2/2P2PPP/R1BQK2R b KQkq - 1 7 Game Over: BlackIllegalMove

reproduce exception depth 4

I also tried debugging my code in case this error originates there, but while stepping through the code, debug mode gets suddenly cancelled. No move was made and no move can be made, but timer goes on.

Staicu-Ciprian-Stefan commented 11 months ago

after more investigation it seems like the behavior described during my previous debug session is because my bot suddenly gets much slower. I don't understand how with no breakpoints the exception is reached instantly, but while debugging it is taking literally minutes.

ryanheath commented 11 months ago

On line 59 in D:\MyDesktop\SebLague\Chess-Challenge\Chess-Challenge\src\My Bot\MyBot.cs your bot code is accessing memory (an array?) out of bounds.

Staicu-Ciprian-Stefan commented 11 months ago

you are right, it was a mistake on my part it is fixed now