Thread: SDL Chess Game problem

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Tomball, TX

    SDL Chess Game problem


    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[8][8] at a position off its board say row 8 col 5 itsomehow "spills over" into checking int
    nextmovecboard[8][8] at location nextmovecboard[0][5] 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[8][8]" 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[15] "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[0], whitekingloc[1]) 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[8][8].
    Then inside my boolean legal(int peice, int startr, int startc, int endr, int endc)
    I placed this line of code
         int rows, cols;
         for(rows = 0; rows < 8; rows ++)
           for(cols = 0; cols < 8; cols++)
             nextmovecboard[rows][cols] = cboard[rows][cols];
    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[7][3],
    cboard[7][4], and cboard[7][5] 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.
    Last edited by Lesshardtofind; 07-02-2010 at 07:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 10-20-2009, 10:39 AM
  2. Hangman game problem
    By piradie in forum C Programming
    Replies: 9
    Last Post: 12-30-2008, 04:29 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  5. Win32 tetris game problem
    By Finchie_88 in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2004, 10:15 AM

Tags for this Thread

Website Security Test