Computer Science Canada Turing Connect Four Stacking Problem |
Author: | Michael3176 [ Mon Dec 31, 2012 11:20 pm ] | ||
Post subject: | Turing Connect Four Stacking Problem | ||
What is it you are trying to achieve? I do not know how to make counters stack on top of the other, for example if the user chooses i column twice, i do not know how to recognize that on Turing. I am trying make my connect four error traps and make it so the user cannot choose a full coloumn. What is the problem you are having? My error traps dont work properly and i dont know how to make counters stack on top of the other Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
|
Author: | Panphobia [ Mon Dec 31, 2012 11:38 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Make an array of integers, and add one to each column until it is full, and then if counter[a] > whatever then give him a message to choose an empty column, or just dont process anything if it is over, and just return to the current persons turn |
Author: | Insectoid [ Tue Jan 01, 2013 12:08 am ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
I suggest you create a 2D array of int to represent the game board. When coordinate x, y is selected, you set that position in the array to 1 or 2 depending on the player that selected it. If a player tries to select a position that is anything but 0, force him to pick a new spot. |
Author: | Raknarg [ Tue Jan 01, 2013 11:57 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
http://compsci.ca/v3/viewtopic.php?t=14333 |
Author: | Michael3176 [ Wed Jan 02, 2013 10:53 am ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Could you give me a code example, Im new to turing and dont quite understand, can arrays use (x,y)coordinates? |
Author: | Panphobia [ Wed Jan 02, 2013 1:16 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Arrays don't specifically store just xy coords, but if you make a 2D array of integers in each slot you can store an x or a y coord, like I would make a 2D array of how many slots there are in connect four in one column times 2 so like counter(6)(0)=x counter(6)(1)=y |
Author: | Raknarg [ Wed Jan 02, 2013 9:41 pm ] | ||||||||||
Post subject: | Re: Turing Connect Four Stacking Problem | ||||||||||
Ok. Lets say I wanted to make a map of 25 tiles. I could do something like this:
Lets assume that all the values are at zero (they're not, we're assuming we already set their values). Now if we draw the map like a coordinated plane, we would end up with something like this:
cool. Now lets make this a little more relatable. Lets say this is connect four, and I dropped a black token in the centre. Lets say that on this map, 0 is empty, 1 is black and 2 is red. We now have this:
The next turn, red wants to drop it directly to the left. Now we have this:
Looks good. Now here comes the part you're having trouble with. Lets say black wants to put another token in the middle. It wont simply drop to the bottom. It's got to land on top of the old black piece. But how will the problem know? It's easy! 5 | 0 0 0 0 0 Looks like there's nothing on this line. Maybe there's another space down. 4 | 0 0 0 0 0 Nope. Lets keep going. 3 | 0 0 0 0 0 Nope. 2 | 0 0 0 0 0 Nope again. 1 | 0 2 1 0 0 Look now. The center space is taken up. Therefore, the next piece would land on top of it. Now taking that information into account, we have this:
Hope that makes more sense now. |
Author: | Michael3176 [ Thu Jan 03, 2013 11:03 am ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
so how would i set up a 2d array of the board using code? Then i could indicate everytime the user would choose a coloumn, indicate that the coodinate was chosen using an array right, and if that coordinate was chosen, if they choose that coloumn again, place it ontop, but how would i now recognize when they have chosen a coloumn twice, would i make a "tries" variable and keep adding one, and if it was two, then locate above it? |
Author: | Raknarg [ Thu Jan 03, 2013 11:22 am ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
You set up the array basically how I just did, however many slots you want as x, and however many slots as y. Basically the player is just choosing which x coordinate they want to put their token in. So all you have to do is use a for loop to search through the array. At anytime if the slot at the x of the players choice is not zero, then you know you need to place a token above it. If it's the top of the row, then they need to make another choice. |
Author: | Michael3176 [ Thu Jan 03, 2013 4:11 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
ok so i did a setup proc like this procedure setup for x : 1 .. 7 for y : 1 .. 6 board (x, y) := 0 end for end for end setup and in my processing i did if coloumn = "1" then if player = 1 then drawfilloval (65, 35, 20, 20, red) board (1, 1) := 1 else drawfilloval (65, 35, 20, 20, blue) board (1, 1) := 2 end if now im stuck i dont no what to write to make them stack |
Author: | Raknarg [ Thu Jan 03, 2013 5:36 pm ] | ||||
Post subject: | RE:Turing Connect Four Stacking Problem | ||||
First o all, do all your drawing outside the loop. You usually want to have them all together, so that your main program flows like this:
It would be easier if you rewrote it, but we dont necessarily have to do that... so now when you get to this part, you have an x coordinate, but you need to find your y coordinate. We can do exactly what we talked about. so in each statement, you have a for loop to search the column.
Now you might be thinking there should be an easier way to do this, and you would be correct. This is set up poorly and could be done much easier. |
Author: | Raknarg [ Thu Jan 03, 2013 6:25 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Or another neat way is using another array to keep track of the next slot open in each column. So like an array 1 .. 7, and all the elements start out at one. Each selection, you set the y coordinate of the token the open slot number of that array. so map (x, slotOpen (x)) := player slotOpen (x) += 1 Something like that |
Author: | Michael3176 [ Thu Jan 03, 2013 11:10 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
So in the first idea you had, what would the for loop look like in code that your talking about, and I don't quite understand how the second one would work |
Author: | jr5000pwp [ Fri Jan 04, 2013 3:54 am ] | ||
Post subject: | Re: Turing Connect Four Stacking Problem | ||
So I wanted to make an example to show you a similar implementation of a 2D array, but I might have went slightly overboard. This is a column based basin filler. You can set the rows and columns, as well as the maximum amount of water per cell. It fills by randomly picking columns and filling a random amount from 0 to MaxLevel*2, that's why it slows down near the end. Hopefully you can learn something from this.
|
Author: | Raknarg [ Fri Jan 04, 2013 11:23 am ] | ||
Post subject: | RE:Turing Connect Four Stacking Problem | ||
This is the first idea. You go through the column. If the slot is empty, move on. If it reaches a filled slot, and its the top slot, no moves are possible. Otherwise, set the token to the slot above. If you reach 0 and it's empty, put it in the first slot. |
Author: | Michael3176 [ Fri Jan 04, 2013 9:45 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Ok I'll try it out and hopefully it will help me, thanks ill get back to you |
Author: | Michael3176 [ Sat Jan 05, 2013 3:11 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
ok so do i make a function called searchColoumn,that includes the for loop you gave me, and then use that in every if statement in processing |
Author: | Michael3176 [ Sat Jan 05, 2013 3:13 pm ] | ||||
Post subject: | RE:Turing Connect Four Stacking Problem | ||||
this would be my function,
Mod Edit: Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Michael3176 [ Sat Jan 05, 2013 3:15 pm ] | ||
Post subject: | Re: Turing Connect Four Stacking Problem | ||
and this is a bit of proccessing but its not working
|
Author: | GuCCIP [ Sat Jan 05, 2013 3:42 pm ] |
Post subject: | Re: Turing Connect Four Stacking Problem |
Author: | Michael3176 [ Sat Jan 05, 2013 4:39 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
I made a procedure like this proc searchColoumn setup for decreasing i : 6 .. 0 if i = 0 then board (coloumn, 1) := player validMove := true exit elsif board (coloumn, i) not= 0 then if i = 6 then validMove := false exit else board (coloumn, i + 1) := player validMove := true exit end if end if end for end searchColoumn and in processing did this proc processing if coloumn = 1 then if player = 1 then searchColoumn drawfilloval (65, 35, 20, 20, red) but how would i make an oval be drawn ontop now? I tried doing if coloumn = 1 then if player = 1 then searchColoumn display, and in display i wrote if board (1,1) then drawoval but it did not work. it said if must be boolean type |
Author: | Raknarg [ Sat Jan 05, 2013 6:19 pm ] | ||
Post subject: | RE:Turing Connect Four Stacking Problem | ||
You need to draw your ovals differently. You're doing it the hard way atm. Think about it, you already have a map that tells you where everything is. just make it bigger, then draw it on the screen. for instance, look at this program.
This is the thing you want to do. But instead of map (i, j), you want to draw it red or black according to the player who placed it. Do you get what I'm saying? |
Author: | Michael3176 [ Sat Jan 05, 2013 8:02 pm ] |
Post subject: | Re: Turing Connect Four Stacking Problem |
ok if i drew it like this for i : 1 .. 7 for j : 1 .. 6 Draw.Oval (i * 50, j * 50, 20, 20, 1) end for end for it would draw all the ovals at once? so how would the game work |
Author: | Insectoid [ Sat Jan 05, 2013 8:07 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Only draw the ones you need. Look in each spot in your array, and if there's a chip in that spot, draw it. |
Author: | Michael3176 [ Sat Jan 05, 2013 9:18 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
ok i got something like this now proc searchColoumn setup for i : 6 .. 0 if i = 0 then board (coloumn, 1) := player validMove := true exit elsif board (coloumn, i) not= 0 then if i = 6 then validMove := false exit else board (coloumn, i + 1) := player validMove := true exit end if end if Draw.FillOval ((coloumn) * 50, i * 50, 20, 20, red) end for end searchColoumn the stacking problem is still there, and what ever coloumn i enter, the whole row is filled up |
Author: | Raknarg [ Sat Jan 05, 2013 9:43 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Except you dont need to draw it there either. Like you can, it's just better orgranized if all the drawing is done together and at once |
Author: | Michael3176 [ Sat Jan 05, 2013 9:46 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
so how and where would i draw it? and do i use both variables "i" and "column" when drawing ? |
Author: | Raknarg [ Sat Jan 05, 2013 9:48 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
in a sense. You can have a procedure for drawing if you want. It's basically just what I put in that program before, with some minor differences |
Author: | Michael3176 [ Sat Jan 05, 2013 9:52 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
ok but i dont understand why its not drawing where i put it to, because its giving the coloumn, and you said the for statement "for i : 6 .. 0 if i = 0 then board (coloumn, 1) := player validMove := true exit elsif board (coloumn, i) not= 0 then if i = 6 then validMove := false exit else board (coloumn, i + 1) := player validMove := true exit end if end if end for" would make the height stack, correct? but maybe that for statement is wrong? |
Author: | jr5000pwp [ Sat Jan 05, 2013 9:52 pm ] | ||
Post subject: | Re: Turing Connect Four Stacking Problem | ||
Can you please, please, please use the
As for your filling problem, think about what your doing with your searchColumn function, why do you have it, what is it's purpose, and most of all, what line doesn't belong? Hint: You aren't actually filling the column atm. |
Author: | Michael3176 [ Sat Jan 05, 2013 10:07 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Ok i will next time sorry, and Well I think the proc is there to trap anything full columns and allow me to place a token where there is open space, but I don't know identify when a column was chosen twice or 3 times, and as to which doesn't belong , I guess it would be the draw command considering you said I'm not filling it it in here ? |
Author: | Raknarg [ Sat Jan 05, 2013 10:25 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Sorry, you mind clarifying your question? |
Author: | Michael3176 [ Sat Jan 05, 2013 10:33 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Im not sure how to get my program to now draw the counters when the user chooses a coloumn, and have them stack one upon the other using the searchColumn procedure, so i am wondering what code would i now put in my display procedure to make the counters display stacked upon eachother like connect four would run. |
Author: | Raknarg [ Sat Jan 05, 2013 10:35 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
The same way you were trying to do it before, thats the correct way, just instead of the searching procedure put it in the display prodecure |
Author: | Michael3176 [ Sat Jan 05, 2013 10:45 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
when i do that it says, "i" has not been declared, and also, it does not display properly, the counters do not stack one at a time, all the counters will stack up to 6 in the column chosen, and i do not know why, i can post the code of the game again if you are confused? |
Author: | Raknarg [ Sat Jan 05, 2013 10:46 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
sure, lets see what you have now |
Author: | Michael3176 [ Sat Jan 05, 2013 10:51 pm ] | ||
Post subject: | Re: Turing Connect Four Stacking Problem | ||
code:
|
Author: | jr5000pwp [ Sat Jan 05, 2013 11:05 pm ] | ||||
Post subject: | RE:Turing Connect Four Stacking Problem | ||||
|
Author: | Michael3176 [ Sat Jan 05, 2013 11:12 pm ] |
Post subject: | Re: Turing Connect Four Stacking Problem |
I know but i dont know where else to put it, because thats the only place in my program where i has been declared. |
Author: | Insectoid [ Sat Jan 05, 2013 11:15 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
You don't have to use i. You can use a new for loop. You could use p if you wanted. Or q. Or gfefreqwrewhr (though I don't recommend it). |
Author: | Michael3176 [ Sat Jan 05, 2013 11:30 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
i know, but thats where im getting at, i dont know what to put in this for loop or how to use it with the draw command |
Author: | Michael3176 [ Sun Jan 06, 2013 9:50 am ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
So any idea on what code I should use? |
Author: | Raknarg [ Sun Jan 06, 2013 1:20 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Yes we do, but we're trying to get you to see things for yourself |
Author: | Michael3176 [ Sun Jan 06, 2013 3:42 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
ive been trying for a while now and have no idea, i made put the draw command in a display procedure, i had a for loop in that of 1..6 and all the counters showed up at once again, i have no idea what to do. |
Author: | Michael3176 [ Sun Jan 06, 2013 10:09 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
? |
Author: | GuCCIP [ Mon Jan 07, 2013 1:11 pm ] |
Post subject: | Re: Turing Connect Four Stacking Problem |
I'm trying to fix your whole program in a bit just wait. As for everyone else i think actually posting the code could help him more than just explain to him why it works. |
Author: | Insectoid [ Mon Jan 07, 2013 1:14 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
No, it really doesn't. It's actually against the rules. At any rate, I think OP has bitten off more than he can chew in this case and should have picked an easier project. If you post the code, OP will still have no idea how it works. He'll just have code he can't read and doesn't understand. |
Author: | GuCCIP [ Mon Jan 07, 2013 1:26 pm ] |
Post subject: | Re: Turing Connect Four Stacking Problem |
Would it be against the rules if someone posts the correct code and explains it to the user? |
Author: | jr5000pwp [ Mon Jan 07, 2013 2:05 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Snippets, yes, finish his code no, especially since this appears to be a school project. |
Author: | Raknarg [ Mon Jan 07, 2013 9:19 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
Understanding a concept is really more important than the code itself. |
Author: | Michael3176 [ Mon Jan 07, 2013 10:58 pm ] |
Post subject: | RE:Turing Connect Four Stacking Problem |
I finished my code it works now thanks |