Thread: Testing Multiple Conditions

  1. #16
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Originally posted by Sebastiani
    Arrays come to mind...
    Arrays? Not sure what you're meaning is here.

    My program is very simple.. a class consisting of an 8x8 char array with '_''s as blank spaces and letters for pieces. The class has a Move() function which takes 4 arguments, x1, y1, x2, and y2. x1,y1 is the starting piece and x2,y2 is the destination. The function checks the coordinates to make sure it is a valid move, and in the if() statement I posted above, those are when the move is valid for a knight.

  2. #17
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well i have also implemented the game in C... I used an array of 64 to make it simpler.. 8 x 8 has a problem of manuplating validity..



    this is how i dod it.. conside there is an array of array[64].. now consider that the king is in the array[40] position.. no to get a valid move i check the move made like this...


    consider i = 40;


    now valid moves are

    array[i+1];
    array[i-1];
    array[i-8];
    array[i+8];
    array[i-9];
    array[i-7];
    array[i+9];
    array[i+7];

    that is |'''''''|''''''''|'''''''''|
    '''''''''''''x'''''''''''''''' |'''''''|''''''''|'''''''''|
    ''''''''''''''''''''''''''''''
    where x is the king.. But this algorithm has a problem.. now conside that the king is in the 8th A8 then the position b1 also become a valid move.. i check this inside the loop... so instead of considering the blocks in this order

    1 2 3 4 5 6 7 8
    A ------------------------------>--------->
    B--------------------------->----------->


    i made it as
    1 2 3 4 5 6 7 8
    A ------------------------------>--------->|
    B ---<---------------------<-------------<-|


    so that problem is eliminated.. and for example if an component is above to move to a valid position say array[40]. then i check if there is any other pawns in that block.. i stored the position of all the pieces in an array called component[64]; so this holds the entire state of the chess board...



    so if any doubts u r free to ask questions.... My game is not yet ready.. i am still workong on it.. i have problems in pecial moves like castling etc etc.. and my game is a 2 player game.. so no AI involved,, i am planin to implement one later.. for this i have thought of a pointing system where i can back track 2 levels(not that intlegent program but still...) and then allocating points to the white and black side.. but i will have to improve this...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple conditions - if statement
    By dibble in forum C Programming
    Replies: 8
    Last Post: 03-28-2009, 12:41 PM
  2. Replies: 1
    Last Post: 09-22-2008, 01:38 PM
  3. checking inputs meets multiple conditions
    By 60beetle60 in forum C Programming
    Replies: 5
    Last Post: 04-19-2008, 08:25 AM
  4. Multiple conditions for the while loop?
    By Olidivera in forum C++ Programming
    Replies: 6
    Last Post: 04-24-2005, 03:47 AM
  5. tips for testing conditions
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 04-10-2003, 01:42 PM