- #1
magnifik
- 360
- 0
i am trying to write a program that is similar to connect four, but it also gives you the option of removing a piece from the bottom of the board. in this case, if there are any pieces on top of it, they will each fall down 1 row. below is my code for the process of adding a piece to the top. any suggestions on how to modify it or write a function for the opposite process would be helpful. thanks.
Code:
int drop(int b, char player){ // indicates where the piece stops at
if(b >=0 && b<= 6) // ensure that the user chooses a column in bounds
{
if(place[0][b] == ' '){
int i;
for(i = 0;place[i][b] == ' ';i++)
if(i == 5){ // if it hits the bottom row
place[i][b] = player;
return i;}
i--; // if it doesn't hit the bottom row it goes to the next open row
place[i][b] =player;
return i;
}
else{
return -1;
}
}
else{
return -1;
}
}