Modifying Connect 4: Adding/Removing Pieces

  • Thread starter magnifik
  • Start date
In summary, the conversation discusses the process of creating a program similar to Connect Four that allows for removing a piece from the bottom of the board. The code for adding a piece to the top is provided and there is a suggestion for a function to handle the opposite process of removing a piece. The suggested function checks if the chosen column is in bounds and then moves the pieces above it down one row before removing the piece from the top.
  • #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;
	}

}
 
Physics news on Phys.org
  • #2
//Here is a suggested solution for the opposite process:int remove(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] == ' '){ return -1; } else { int i = 5; while(place != player) i--; place = ' '; for(int j = i-1; j >= 0; j--){ if(place[j] != ' '){ char temp = place[j]; place[j] = ' '; place[j+1] = temp; } } return i; } } else { return -1; }}
 

1. Can I add new pieces to the traditional Connect 4 game?

Yes, you can add new pieces to the traditional Connect 4 game by designing and creating them yourself. However, the number of pieces added should be equal to the number of pieces already in the game (21 red and 21 yellow pieces).

2. How can I remove pieces from the Connect 4 game?

You can remove pieces from the Connect 4 game by simply not using them in your game setup. For example, if you do not want to use the yellow pieces, you can remove them from the game and only use the red pieces.

3. Can I modify the size of the Connect 4 game board?

Yes, you can modify the size of the Connect 4 game board by either making it smaller or larger. However, keep in mind that the number of rows and columns should remain the same (6 rows and 7 columns) to maintain the gameplay mechanics.

4. Is it possible to change the color of the game pieces?

Yes, you can change the color of the game pieces by using different colored materials or painting them. This can add a unique twist to the game and make it more visually appealing.

5. Can I modify the rules of the game when adding or removing pieces?

Yes, you can modify the rules of the game when adding or removing pieces, as long as the basic objective of connecting four pieces in a row remains the same. You can also come up with new rules to make the game more challenging and interesting.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
852
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
5K
Back
Top