connect four style game

Pages: 12
Haha, that's best analogy I've ever heard. :)
And you called it, that was definitely the cause of that problem. So now I have and interesting issue that I think I might have an idea to fix it. So when it loops through it prints this:

Dimensions: -c 8 -p 8 -r 4 

<in arg checker>
Error!!!!!

c = 56 
Error!!!!!

p = 56 
Error!!!!!

r = 52

So I can see that it's hitting the error in every iteration until -r, -c, and -p have all been read. Do you think it would work if I combined all the if's in one line separated with && so it reads them all at once. I just want to check if that would make sense before changing all the code that I finally got somewhat working. Also, I assumed the 56, 56, 52 that was printed is ASCII so I tried changing int r = *info[i+1]; to int r = atoi(*info[i+1]);. but that just gave the error:

connect_any.cpp:33: error: invalid conversion from ‘char’ to ‘const char*’
connect_any.cpp:33: error:   initializing argument 1 of ‘int atoi(const char*)’

That confused me because I thought I was going from ASCII to Integer but its saying I'm going from character to Character? Not sure what's going on with that.

**EDIT**
I figured out ascii to integer thing just did cout << 'r = " << r-48 << endl; :):):)
Last edited on
char is a numeric type that is traditionally treated as a character. You can cast it to int if you want to guarantee it will be treated as a number instead. But I am not sure where this would apply in your program.

Unless your assignment requires you to, you don't need to worry about the error case in your code. When you get into one of the if statements, increment i and read the argument into a variable. You will need some way to communicate the variables to the rest of your program - I assume that is in your assignment description.
Yeah, I don't think I'm going to worry about the error message for a while. I'm really happy that I got the arguments and dimensions into a function that would print them.
I'm supposed to have a function that sets the game information but it seems like I pretty much did that in my checking function. Now I have to figure out how to use the r and c values to create a 2D array that creates and prints the rows and columns of the board/table that I must drop the pieces, p, into. I've made a 2D array that printed a grid of random numbers before, but in these last few hours I've been looking around trying to figure out how to do a 2D array of lines that will serve as the columns in which the players are to drop the pieces in to. Haven't had much luck understanding what I've seen. I don't see how I can have a 2D array of lines that is the board and then have these player pieces dropped into it. It feels like there's two separate things involved that somehow get merged together. Any hints or tips on how to go about it?
How close is this supposed to be to connect-four, on a scale of 1 to 4?
Connect any. The variable, p, is supposed to set the number of pieces you have to get in a row to win. Basic connect four rules other than the board gets whatever dimensions and however many pieces required to win as the user chooses. It kinda blows my mind. :|
You may want to experiment with a tic-tac-toe game first to understand how 2D board games with x-in-a-row win conditions work.

If the game will only have two players, that means each cell in your board can only have three states: empty, owned by player A, or owned by player B. You can choose to represent this however you want - it could be a simple as using integers where 0 is empty, 1 is player 1, 2 is player 2, etc.
Topic archived. No new replies allowed.
Pages: 12