Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Connect 4 modified

  1. Aug 6, 2010 #1
    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 (Text):

    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;
        }

    }
     
     
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted