# Testing Multiple Conditions

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-20-2002
Captain Penguin
Quote:

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.
• 10-20-2002
vasanth
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...
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12