Computer Science Canada Problems with Connect 4 (Grade 10 level) |
Author: | Rich0591 [ Fri Nov 17, 2006 6:00 pm ] | ||
Post subject: | Problems with Connect 4 (Grade 10 level) | ||
So Im having some big problems with my connect 4 game. I asked my teacher for help but she is taking way too long and its been over due. Could someone nice help me: make it so the game lets players take turns, reognize that 4 in a row means win (not diagonal, then my teacher will know I asked for help) and maybe make the circles fall from the top. I know its alot but I would really appreciate it if comeone could help me out. Also, if someone was to do it, could you do it at a simpler level? Thanks! Heres the program:
|
Author: | Clayton [ Fri Nov 17, 2006 6:10 pm ] |
Post subject: | |
errrr, no we can't do it for you, however we can help you with it, ask some concise, detailed questions about problems you are having, and I'm sure someone would be glad to help. Take a gander through the Turing Walkthrough, and I'm sure, if you take the time, that you will find some tips to help you. |
Author: | Rich0591 [ Fri Nov 17, 2006 6:15 pm ] |
Post subject: | |
Ok well heres the thing. My teacher edited it, and we both dont understand why each circle can turn BOTH red and black. This is what i first need to understand, maybe someone could point out what we did wrong? |
Author: | wtd [ Fri Nov 17, 2006 6:21 pm ] |
Post subject: | |
Code tags would help, as well. |
Author: | Rich0591 [ Fri Nov 17, 2006 6:50 pm ] | ||||
Post subject: | |||||
This is what I have to determine when some one wins.
On my mainline program, I added something like this
This determines the score for one person. But I still can't figure out how to take turns and make it so a person can only win if it is 4 in a ROW.[/code] |
Author: | Wolf_Destiny [ Fri Nov 17, 2006 10:52 pm ] |
Post subject: | |
Fairly quick thought, your life is going to be easier if you use variables (even easier with arrays [dare I say two dimensional arrays? {dare I go too far with types and records? No} No]No) Anyways...If you had variables for each one of your circles you could store whether they're red, black, or empty. Then in your "gui" procedure you could just draw each circle according to their stored colour. Then to check for a win, just see if c1 c2 c3 c4 all = red or black or if c5 c6 c7 c8 all equal red or black ect. Also try to use less "linear" programming you already have a couple of procedures, but gui is hardly ever called upon. You should be using it to draw any/all changes made to the game board. http://www.compsci.ca/v2/viewtopic.php?t=407 Hope any of that actually helped instead of confusing you! ~Wolf_Destiny |
Author: | Rich0591 [ Sat Nov 18, 2006 7:00 pm ] | ||
Post subject: | |||
|
Author: | Mr. T [ Sat Nov 18, 2006 8:01 pm ] |
Post subject: | Alex's Opinion |
I haven't taken a good look at ur code, but from what I see this has been terribly coded. What's more surprising is that if your teacher saw you code, why did not suggest obvious ways that it could be fixed? Anyways, I'm not trying to put down you or your teacher, as I plan on telling you how to go about fixing this program. First of all, the lines can be reduced drastically if you STOP HARD CODING. You can easily draw everything you need to draw in significantly less lines using variables --> arrays, and clever use of for loops. All that is required is simple math. I don't have the time at the moment, but I'm sure someone else on the forum will gladly show you an example of how to reduce your code using a non-hard coding technique. Second, all those if statements in may you main loop can be reduced significantly. If you make a grid using a 2D array, itll become much easier to determine which blocks are filled in, rather than checking each one individually. The way you did it is extraordinarily tidious, and very inflexible. So in summation, check the Turing Walkthrough for more information on variables, arrays, 2D arrays, (and some of the basics you may want to hone up on are your standard procedures, functions, and maybe even records). |
Author: | Rich0591 [ Sun Nov 19, 2006 12:13 pm ] | ||
Post subject: | |||
Ok so I read about the 2D arrays ya I dont pay attention alot which may be why my program sucks anyway
I stuck this in my program. Now the colour don't work, which I think is a good thing cus now I need to store the colours in my array right? Thing is I dont know how lol so could somone like copy and paste something from my previous program so I know what I would know what to do? Again thanks guys! |
Author: | ZeroPaladn [ Mon Nov 20, 2006 1:13 pm ] |
Post subject: | |
First things first, remember that you need two diferent colours to represent both players, and maybe another colour to represent an empty space. So, when you think about it, its not that hard, and in fact, you have all the code you need right on your last post. (just fix the differneces between your for statements and your array declarations, because they should match) The idea is to have differnet declarations for each chunk of the array for each colour, not just one for both, cause the program can't tell the difference, cause there is no difference.) Now we all know that just outputting the string on the screen isnt going to work when you do graphics with your program, so you'll have to use an if statement to determine the colour using the letter youve used to declare the array in that position. This may be geting too far aread of what you wanted, but its something to remember for later, if you do incorperate graphics into your program. |