![]() |
Why isn't it working properly?
If you toss a disc in at the second row, it'll stay in the loop after the if-statement, after all that has to be done, is done, except when you toss the disc in the first column. Then it works fine. I tried putting an else-statement there, to turn the loop off if the else-statement was called, and it works fine then, but the four on a row diagonally isn't detected then. |
Can you add your documentation.
This should be simple program, if you are not building AI. I'll check the code after dinner. |
My documentation? As in what which calculation does?
Code:
Public Sub NESWDiagonaal(intLastSpot, bytChecking, intPosition) The intKolom and intMultiply are there to take care of the wrapping around. We don't want people to win when they have two discs diagonal from each other on the right edge and two on the left. |
I was thinking about documentation for the project, as planning and pseudo code.
Reason program loops is in this loop: Code:
Do When do you need to turn in this program? |
You mean the assignment doc? It's in Dutch, but I'll translate.
Quote:
|
So,
how do you like to make sure that player won? Just write pseudo code of your program. |
I will be takin a VB course next semester YAY :D. What is this program suppose to do? All I ever done was simmple tiny piece of code for my wolf3d mod.
|
Position = LastPosition
counter = 0 <check horizontally> Position = Position - 3 or until it hits the left border do if Position.value = CurrentPlayer { counter ++ } else { counter = 0 } if counter = 4 { win! } Position ++ loop until Position = Position + 3 or Position = last column <check vertically> Position = Position - 21 or - 7 until it's at the bottom row do if Position.value = CurrentPlayer { counter ++ } else { counter = 0 } if counter = 4 { win! } Position += 7 loop until Position = Position + 21 or Position = top <check diagonally / > Position = Position - 24 or - 8 until it's either at the leftmost column or the bottom row do if Position.value = CurrentPlayer { counter ++ } else { counter = 0 } if counter = 4 { win! } position += 8 loop until Position = Position + 24 or Position = rightmost column or top row <check diagonally \ > Position = Position - 18 or - 6 until it's either at the rightmost column or the bottom row do if Position.value = CurrentPlayer { counter++ } else { counter = 0 } if counter = 4 { win! } position += 6 loop until Position = Position + 18 or Position = leftmost column or top row. |
This code does not make much sense to me.
Here is what you have to do: (pseudo code) 1. Make a function which will return index value in the cell for given row / column 2. Make a function which will return row / column for a given index 3. Make a function which will for column check where the top is and place a coin there 4. Check anywhere you have 4 cells horizontally that mach 5. Check anywhere you have 4 cells vertically that mach 6. Check anywhere you have 4 cells up diagonal that mach 7. Check anywhere you have 4 cells down diagonal that mach 8. Check if all fields are used 9. Make a function that checks steps 4 - 7 and then give a winner, move to next player, or if all fields are used (draw). Details: STEP 3 Check top value for that column ( using function in step 2, eg col 1, row 5) -- if is filled: don’t allow to place piece there (message) -- if is empty, check next one (-8) Loop this way till you don’t place a coin on the bottom. STEP 4 Create loop for Column 0 – 3 -- Create loop for Rows 0 - 5 ----Check if CP (Current position), CP + 1 , CP + 2 and CP + 3 are the same ------If yes, we have a winner STEP 5 Create loop for Columns 0 – 7 -- Create loop for Rows 0 - 2 ----Check if CP (Current position), CP + 7 , CP + 14 and CP + 21 are the same ------If yes, we have a winner STEP 6 Create loop for Column 0 – 3 -- Create loop for Rows 0 - 2 ----Check if CP (Current position), CP + 8 , CP + 16 and CP + 24 are the same ------If yes, we have a winner STEP 7 Create loop for Column 3 – 6 -- Create loop for Rows 3 - 5 ----Check if CP (Current position), CP - 8 , CP - 16 and CP - 24 are the same ------If yes, we have a winner STEP 8 Run separate functions similar to step 3 where you’ll find top for each column. If you have 7 hits and you at this step, then it’s draw STEP 9 Just to make it easy, functions which incorporates steps 4 – 8 If you follow this pseudo code, it should be a piece of cake to make this program. ;) |
That's basically what I've been trying to do. Although I don't understand why you're only checking to row 2, or to column 3, and in the diagonals, how it would know cases like this?
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 2 0 0 0 0 1 2 2 0 0 0 1 2 1 1 0 0 1 2 2 1 1 0 0 |
Because you can't have 4 pieces in diagonal if column (horisontal number) is greater then 3 and row (vertical position) is greater then 2.
So these are your start position: 2 X X X X 1 X X X X 0 X X X X = 0 1 2 3 These are only valid first position (I colled them current position in example before), and you can't get 4 coins in up-diagonal if your first position is greater then this. Note in your example above that start position is 0 for rows, 1 for column. Try to make a diagonale that has start position greater then loop value. |
Ehm... 's 4am now and I'm already pissed off because a week's worth of work's got to be thrown away and redone within a day, so my understanding's probably off. Please explain slow and as if you were trying to get an infant to understand :tomato:
|
:D Somehow I really good know that feeling LOL
When you check your win position, it's much easier to make it in 4 steps (like I said before) with checking next three coins based on first one. That way you don't have to go trough all rows and columns, as if you for horizontal check can't make 4 coins in row, if your position in columns is beyond position 3. In other words: 3 - 4 - 5 - 6 (if they are the same) = win but you can't make win position if you start from column 4 4 - 5- 6 and there is NO column 7 (count starts from 0) so you don't have to bother to check this position, as it can make win position. Better? |
I see. So more like this: (Googled for example codes)
Code:
Dim Row As Integer, Count As Integer |
Very similar, but I would suggest use of two loops. This way you can have much cleaner code.
Code:
For column 1 to 3 Note 2: I used = 1 as sample for player 1, you can have three option in each array position, 0 - no coins, 1 - player 1 and 2 - player 2. Just change 1 with variable which represents which player's turn it is. |
Hmmm... the code in this other thingy I got, is
Code:
'Check Diagonal Lines [Up to Right] |
Loop should work much better then this code, as it's simple and it's easier to mentain.
Just write here other 3 loops (pseudo code same way I did first one) and that's most of your project. Visual implementation is ok, then still you'll have to make sure that STEP #1 - 3 are working right, and your project is almost done. |
Ok, for the loops... what does the program need to know per direction? The row and the column and the index number? Or the row and the column? And which ones ought to be variables and which constants? (just making sure I won't crap things up at the input-part, then waste my time trying to fix output, as I don't have time for such nonsense)
|
You need:
* an array of 42 elements ( 0 - 41) * rows (0-5) variable * columns (0-6) variable * playerID (use this variable to change value in array if coins is dropped, and to check win situation) Reuse your player name variable, as that's ok. Just to explain couple of other functions again: New button should loop trough array and change all the values to 0. Drop of coin should check what is lowest position in that column and change value for that cell ( function that returns array value for the given row/column) to player value Redraw function will go trough array and place player coins in the cells on the visual interface. Do this after player placed a coin! Two variables (optional) if you like to keep a score for players, and function to null both values if players like to start from the beginning. Just to make sure you got logic for win situation, make a code simillar to mine and post it here. It's better now to make sure there is no mistakes, then later. |
Trying to make such a code, and it's splitting my brain. I'm trying to understand how ...
*looks at his grid with the numbers in* *counts* Arglgl :wall: ... Ok Man, that was almost like pointers in C++ (which I understand, but don't see a use for) Anyways, I see why only column 0-3 now. If the coin thrown in is in column 4, 5 or 6, the loop starting from column 3 will cover those too. Not so much checking around the coin that's tossed in, more as checking if there's a four on a row in the entire row. |
Done.
Code:
For Column = 0 To 3 |
Oh, I see now.
Use this line to create above function Code:
position = row * 7 + Column |
Hmm... might be a good idea. Never thought of making a one-line function, but it's used too many times (even in the clicking of the button on top) to keep readability. Just a slight readability improvement, but it is one.
|
It will help you in diagonals, and it will give you back value for the box right where you need it. (It's not 1 line, as you have to return value for that position)
|
Maybe a dumb question, but what's the syntax to return values? I've been working around it by making global vars >_>
|
add 'as type' in declaration of function
Example: Code:
Function GRID( row, column) as Integer |
Code:
Dim Row As Integer, Column As Integer, pos As Integer Edit: Nevermind. 6:30am here, so could expect such things. Changed the or to and in the loop and it works now. Edit Edit: Seems like it always ends on row 0 >_> |
I see, in VB you can't use functions same as in C++
Sory about that, you can change that one line for position back to main function. Just copy/paste this stuff, change criteria and you're done. :) |
Code:
Dim Row As Integer, Column As Integer, pos As Integer |
Why you have this line criteria in the sub line?
Code:
Sub Direction(Position, player) Code:
Private Sub Klik_Click(Index As Integer) |
I can take Position out, and Player is now PlayerTurn, which shouldn't be passed through, as it's a global var now too. Code now:
Code:
Dim Row As Integer, Column As Integer, position As Integer, PlayerTurn As Integer |
Seems like I need to empty Position afterwards...
|
Code:
If PlayerTurn = 1 Then |
I'm taking that out of there and put it in where it belongs once the dropping-through works fine. Right now, I can place coins, but they always drop to the bottom row. To fix the emptying of Position, I put
Position = Row * 7 + Column above the loop too. |
That will fix begining of loop.
Post your code here when you're done, and I'll check it later. I got whole 3 hours to sleep, and then I got some of my own stuff to finish. :) Good night! :bye: |
I ought to go to bed too. Guess it's better to code with a clear head :whistle:
Entire code for now: Code:
Dim Row As Integer, Column As Integer, Position As Integer, PlayerTurn As Integer |
Well I am back. :)
There is one logical error in current code. You need IF statement to make sure that first Code:
Position = Row * 7 + Column |
Code:
Do Until Row < 0 Edit: W00000000000000000-OOOOOOOOOOOOOOO-000000000000t :Brain: :bannana: :band: :Brain: Code:
Do Until Row < 0 Edit Edit: Code:
Do Until Row < 0 |
kind of bad code.... :blink:
Try this: Code:
|
That one gives the same problem as before: the bottom line gets colored. The coins don't drop on each other, but over each other.
|
Change only loop problem the other way you did before *I thought that code was OK*, but use that if statement to check if first top cell is colored, if yes, don't do any code that you would if player place a coin in the column (no win/draw check, and no change of players).
|
Hence the exit sub ;) It'll stop running through the code until there's new input. Right now, I'm trying to hook the horizontal winning-checking up to the code. So far, no good. Time to put the MsgBoxes in to see what works and what doesn't.
Edit: Found the problem. Still used a hypotethical/hypothetical name for the player's turn. Changed all = player to = PlayerTurn and it works like a charm now :ok: Edit: Woah momma, this coding goes quick now :blink: Vertical's already added too. Time for the diagonals :w00t: |
Use debug mode (F8 >> next step).
That's the best way to trace program and find code with the problems. |
All directions needed're in now :D Now to test them all...
And DAMN this code's short :blink: Especially compared to the shitload of crap I had before. |
Quote:
:ok: |
Time to finish it up, maybe add the choice of tileset in and add C64 music in (with .sid-files) if I ever knew how, then add a crapload of ascii porn in there, commented away :whistle:
|
You should create exe and post it here (and code if you like).
So we can try and play it :) |
Code:
Dim Row As Integer, Column As Integer, Position As Integer, PlayerTurn As Integer, GameOn As Integer, score1 As Integer, score2 As Integer The compiled version The compiled version with all files from the coding included |
Good job! :ok:
It works great! |
And it's so slim in size :D I'm looking into how to add music now. Preferably SIDfiles, but can't understand that fileformat documentation, so probably have to convert them to wav or midi first. Also will add the possibility of tilesets. Shouldn't be too hard to do.
|
I would sugest to make result more clearer (it's kind of hard to read).
I did some sound work long time ago. Can't remember what format we used. |
Make result more clearer?
As for sound, I got a filetype documentation on .sid files, but don't see how to use that to get the songs to play in this game. Also got this as another explanation, but it feels like it's got a load of rubble in there. Guess I'll do the tilesets first, and try to change the icon :D |
It's hard to read it.
|
Changing the Windows XP theme, it changed it.
You can make background and font be OS independent. |
Didn't notice that :blink: Win98SE here, so no XP problems. It looked fine here, like on the lower pic, but with a grey background, not a pale yellow one.
|
Tilesets code's done too, and works like a charm. Friend of mine's sprucing up my sheep tileset and am making another couple of sets.
Code:
' ************** |
The current time is 01:45 AM (GMT) |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.