View Single Post
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