waseem1345 0 Light Poster

hello, this is the part of the code I'm having a problem with

if(a1==r1a || a2==r1b)
               {//REPLACING

                       for(p=0;p<8;p++)
                       {
                           for(r=0;r<8;r++)
                           {

                               if( i[p][r]==1)
                               {

                                   i[p][r]=0;
                               }
                               if(p==a1 && r==a2)
                               {
                                   i[p][r]=1;
                                   r1a=p;
                                   r1b=r;
                               }
                           }
                       }

                }

I have only 2 units in the board of my chess game, intiger i is a 2D array (which is the board), there are unit 1 and unit 2 on it, unit 2 is placed in i[r2a][r2b].
and unit 1 previous position is in i[r1a][r2b]
this code change the position of rook 1 from place to another if there are no units in the new place, and if the new place is in a straight line. But I don't know how to make it not pass other units.. Can you show me a small code to let it not pass the unit 2 which is positioned in i[r2a][r2b]?

Thanks in advance :)

P.S: if the position = 0 then it's empty. if it's =1 then it contains the rook, if it's = other number then it contains another unit.
[a1][a2] is the new position which the user entered.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.