Explanation: Apparently in my boolean function check() I was allowing the condition for if a knight was threatening a king to search "off the board" or outside the field of the original matrix. I'm still unsure why the exhistence of a 2nd 2d matrix caused this problem to surface only after I had filled it with numbers. I'm assuming somehow the computer is storing the data positions near each other so if I tried to access int cboard at a position off its board say row 8 col 5 itsomehow "spills over" into checking int
nextmovecboard at location nextmovecboard and finding that peice to be a threat.
Sorry to any who wasted time trying to solve this and thnx again for you time.
Hi I've started making a chess game. My overall goal is to make a 3d chess game. My friend who is an artist is working on creating a chess set with his own art form and I'm trying to get a chess engine down without stealing anyone elses code. This project is to help us understand the games we love to play day and night.
I started with an int array "cboard" to be my chess board. Then I associated the pictures of the chess peices with a numberical value in the array chessboard. Using a event handler created a set of coordinates from 2 clicks. Starting coords and finishing coords. Next comes boolean that checks if the move is legal or not depending on the value of cboard[startrow][startcol] ie what piece it is.
After that was functioning I added end game conditions. To do this I defined another int array "peices lost". When a piece is taken the int changes from 0 to 1. (I know this could be done as a boolean.. I just lean towards math over logic most of the time). Of course if the king is lost at any time the event handling loop ends and it displays a winner based on which king is lost.
Once I had this capabilty I added a check function. This function decides if the location of the king (whitekingloc, whitekingloc) is in a threatened(int row, int col) position. Once I had this fully working and played a few practice games I decided it would be time to set governing legal moves for while a peice is in check or if it is moving into check or creating a check (ie you move your own bishop out from between a king and the opponnents queen.
It took me a while to decide how I could see if the next move made would be check. I finally decided upon creating a second int array nextmovecboard.
Then inside my boolean legal(int peice, int startr, int startc, int endr, int endc)
I placed this line of code
suddenly I am in check as soon as I load up the game. If I put a comment /* that code snippet */ and compile everything runs fine again. I've spent the last 2 hours changing and modifying the way I run my threatened() and check() functions, but everytime I add those 8 lines of code it thinks the king is in check at the very beginning of the game. And ANY time he is in pos cboard,
int rows, cols;
for(rows = 0; rows < 8; rows ++)
for(cols = 0; cols < 8; cols++)
nextmovecboard[rows][cols] = cboard[rows][cols];
cboard, and cboard he is in check. There might be other positions on the board that are also glitched that I haven't found since i haven't taken every peice other than the king the board and physically moved the king to all 64 spaces.
How could a 2d array copying onto another 2d array cause a boolean that accesses the first array but not the copy to incorrectly prove true (and inconsistently).
The program is 1200 lines of code so I didn't want to post if you need to see more just ask. Thank you for your time in reading and possibly helping me think through this challenge.