Go Back   Forums > Community Chatterbox > Blah, blah, blah...
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 01-12-2004, 08:07 PM   #1
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

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.
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 01-12-2004, 09:50 PM   #2
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

Can you add your documentation.

This should be simple program, if you are not building AI.

I'll check the code after dinner.
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 01-12-2004, 10:01 PM   #3
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

My documentation? As in what which calculation does?
Code:
Public Sub NESWDiagonaal(intLastSpot, bytChecking, intPosition)
 intLastSpot = intPosition
Dim intKolom As Integer
Dim intRij As Integer
Dim intMultiply As Integer
Dim intMultiplyFinal As Integer

' * Geen doorvallen langs beneden
intLastSpot = intLastSpot - 24
Do Until intLastSpot >= 0
 *intLastSpot = intLastSpot + 8
Loop

 Select Case intPosition
 *Case 14
 * *intLastSpot = 14
 *Case 21
 * *intLastSpot = 21
 *Case 28
 * *intLastSpot = 28
 *Case 35
 * *intLastSpot = 35
End Select

' * Aantal keren dat ge naar rechtsboven kunt

intKolom = 6 - intLastSpotKolom
MsgBox "intKolom = " & intKolom & "."

If intKolom < 3 Then
 *intMultiply = intKolom
Else
 *intMultiply = 3
End If

intMultiplyFinal = intMultiply * 8
MsgBox "Final = " & intMultiplyFinal & "."
Do
Call WinCheck(intLastSpot, bytChecking)

 If intMultiply > 0 Then
 * intLastSpot = intLastSpot + 8
 * intMultiply = intMultiply - 1
 * MsgBox "intMultiply = " & intMultiply & "."
 End If
Loop Until intLastSpot = (intPosition + intMultiplyFinal)
End Sub
This part of the code's the one where the bug's in. The problem, is that the loop gets stuck. The + 8 is to jump to the square one NE of the last one, and it starts three squares SW of the one a disc is dropped in (hence the -24). If that turns out to be under the playfield, it counts up 8 until it's above 0 again (thus being in the playfield)

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.
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 01-12-2004, 11:07 PM   #4
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

I was thinking about documentation for the project, as planning and pseudo code.

Reason program loops is in this loop:

Code:
Do
Call WinCheck(intLastSpot, bytChecking)

If intMultiply > 0 Then
 *intLastSpot = intLastSpot + 8
 *intMultiply = intMultiply - 1
 *MsgBox "intMultiply = " & intMultiply & "."
End If
Loop Until intLastSpot = (intPosition + intMultiplyFinal)
You end up looping, but criteria (intPosition + intMultiplyFinal) is not chenging. (value of intLastSpot is 24, bytChecking is 0, intPosition 8 and intMultyFinal is 24. You have to add the code to change one of values, so that your code can exit loop) It would help me if you have documentation in which you show what your code suposed to do. (That's the way they teach here programming)

When do you need to turn in this program?
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 01-12-2004, 11:57 PM   #5
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

You mean the assignment doc? It's in Dutch, but I'll translate.

Quote:

<snips out the rules of the game, as I guess you already know those>

2. Assignment
The assignment exists out of implementing the Four On A Row/Connect Four game in Visual Basic. In this section, you'll find a summing of what we expect of you concretely.

First you have to design the user interface. This needs to represent the playfield. Of course, the players have to be able to change something to the playfield. For this, the seen objects (buttons, labels, etc) will be used. An example of a layout can be found in image ?? <another example's the one in the zip-file I linked to earlier> You can also be a bit more creative and think up your own layout. The objects that have to be present, are derivable from the requirements we ask of your program.

The program has to agree to at least these criteria:

1) The playfield has to exist out of 7 columns and 6 rows. Each tile can for example exist out of a circular shape object

2) The game has to be able to be played by two human players. You don't have to apply a computerplayer.

3) The name and turn of the player whose turn it is has to be shown. You'll have to make it possible to give the names of the players before the game can start.

4) You need to make a method to drop a coin in a column (iow. coloring the tile). This can be realised by, for example, clicking a button above the column. The coin has to behave like written in the rules. The color of the coin is, of course, the color of the current player.

5) If a player has played a coin, the turn has to switch to the other player automatically. You can do this by showing the corresponding name or color of this player somewhere.

6) You also have to detect if a player has won. This has to be made known (for example with the aid of MsgBox). Also, if the board is full and no winner is appointed, you have to make this known. After one of these situations, a new game has to be started (like clearing the playfield). When these players don't want to play anymore, you have to apply the possibility to stop the game and enter new names.

7) For each of the two players, a score has to be kept. This exists out of the amount of times each player has won. The score is to be kept for a series of consecutive games that the same players play against each other. If a new game is started manually (with inputting the playernames), you can forget the old scores. You don't have to store anything in a file or the likes.

3) EXTRAS
<snips this out, as it just gives examples of extra stuff you can add, but which isn't necessary, and got a list of my own to add>

4) TIPS 'N TRICKS

1) Make sure your program is easy to understand. This is done by supplying enough comments in your code, along with choosing clear and meaningful names for your code-elements.

2) To come to a simple program, it is important to make the right choice of building the board. To come to a good choice here, here is a tip: Make use of a Control Array. You can concider this as a row with alot of objects of the same type and with the same name. A specific object inside this row can be called on* by putting the its number behind the rowname (vb. Buttons(5)). You make a Control Array like this:
* <snips>

The organisation of the fields can look like this:

5|* * 35* * * 36* * * 37* * * 38* * * 39* * * 40* * * 41
4|* * 28* * * 29* * * 30* * * 31* * * 32* * * 33* * * 34
3|* * 21* * * 22* * * 23* * * 24* * * 25* * * 26* * * 27
2|* * 14* * * 15* * * 16* * * 17* * * 18* * * 19* * * 20
1|* * 7* * * * 8* * * * 9* * * 10* * * 11* * * 12* * 13
0|* * 0* * * * 1* * * * 2* * * 3* * * * 4* * * * 5* * * 6
* ------------------------------------------------------
* * * * 0* * * * 1* * * * 2* * * * 3* * * 4* * * * 5* * * 6

The reacting to events of objects in a Control Array (e.g. a mouse-click) happens <yadayadayada, explanation of how to use Control Arrays>

3) To make the code more readable (which makes it easier to correct mistakes), you best do the following. Define 2 global variables: AMOUNT_ROWS and AMOUNT_COLUMS, which respectively represent the amount of rows and the amount of colums (so 6 and 7). Beware, the rows and columns start counting at 0. So the first row (column) is row (column) 0. With the aid of these formulas you can calculate the row and column if your Index is given:

r = Int(index / AMOUNT_COLUMNS)
k = Index mod AMOUNT_COLUMS

These formulas are best to be poured into separate modules, who'll take the index as an argument and returns the column - or rownumber as result. Better apply a methode which does the opposite too, nl. which returns the index of a given column- and rownumber.

You can easily check if a field is at the border of the playfield this way. For example to check if a field is at the right edge of the board, you do the following:

if k = AMOUNT_COLUMNS-1 Then
...
Else
...
EndIf

You can define yet other methodes who'll make the working with indexes easier the same way. Think especially of the controling of the diagonals.

5.
<Snips, as it's some practical stuff, like when to hand it in (friday before noon), and how, and where>
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 02-12-2004, 12:05 AM   #6
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

So,
how do you like to make sure that player won?

Just write pseudo code of your program.
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 02-12-2004, 12:08 AM   #7
Ioncannon
Abandonia Homie

 
Join Date: Mar 2004
Location: Mississauga, Canada
Posts: 558
Send a message via MSN to Ioncannon
Default

I will be takin a VB course next semester YAY . What is this program suppose to do? All I ever done was simmple tiny piece of code for my wolf3d mod.
Ioncannon is offline                         Send a private message to Ioncannon
Reply With Quote
Old 02-12-2004, 12:16 AM   #8
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

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.
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 02-12-2004, 01:01 AM   #9
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

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.
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 02-12-2004, 01:19 AM   #10
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

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
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual problem in all dos games rkrd Troubleshooting 6 07-12-2007 09:43 PM
AdLib Visual Composer crazedloon Gaming Zone 1 20-09-2007 11:30 AM
Damn It punch999 Blah, blah, blah... 2 01-07-2007 06:39 PM
Visual Basic, Helpme! hotty_green Programming 7 19-07-2006 06:39 PM
Visual Basic tomf Programming 11 05-03-2006 10:35 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 05:20 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.