GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 12:32 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jun 06, 2012 11:49 am 
Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
I have a problem with minesweeper, a game that im making to learn programming basics. The problem is infinite loop. I think I got a code working if there wasn't an error for a endless loop.
So when i press the left button on the mouse it starts a function called GRTRemoveBlocks, this function checks if a value that is loaded when the game starts is 0 (have no mine near).
Code:
       
 void GRTRemoveBlocks(int n) {
            if (minenear[n] == 0) {
                RemoveBlock(n);
            }


if the variable is 0 the game loads the function RemoveBlock.

this is a small example of the code inside:
Code:
        void RemoveBlock(int n) {
                #region 1-3
                if (blockposint[n] == 1) {
                    IsBlockVisible[n + 1] = false;
                    IsBlockVisible[n + (int)blockamountxy.Y] = false;
                    IsBlockVisible[n + (int)blockamountxy.Y + 1] = false;

                    //this opens the GRTRemoveBlock with different n value
                    GRTRemoveBlocks(n + 1);
                    GRTRemoveBlocks(n + (int)blockamountxy.Y);
                    GRTRemoveBlocks(n + (int)blockamountxy.Y + 1);
                }

blockposint is the position of the block
Image to show position:
Image

Here is everything I've coded in a rar file: http://www.mediafire.com/download.php?77ajnc93hj33g34


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 12:48 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1552
Location: burrowed
Mentioning an infinite loop and not pasting the actual loop code doesn't help quite as much :P

Please try to provide complete code snippets, don't bother if the post gets long, or use services like pastebin or codepaste to paste functions.

Will try to get a look at your code later today.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 12:58 pm 
Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
weezl wrote:
Mentioning an infinite loop and not pasting the actual loop code doesn't help quite as much :P

Please try to provide complete code snippets, don't bother if the post gets long, or use services like pastebin or codepaste to paste functions.

Will try to get a look at your code later today.


but that is the loop, when it has set IsBlockVisible[n]= false then it redo the process with 3 other values (checks if it is equal to 0 then remove adjacent blocks) for 3 more blocks. Then it might see that more isn't surrounded with mines So (what i think) the computer thinks it is a infinite loop.


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 1:14 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1552
Location: burrowed
oh right, sorry bout that, didn't catch the recursion :O

Only thing that looks suspicious to me currently is (int)blockamountxy.Y, can you make sure it is not 0?

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 1:50 pm 
Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
weezl wrote:
oh right, sorry bout that, didn't catch the recursion :O

Only thing that looks suspicious to me currently is (int)blockamountxy.Y, can you make sure it is not 0?



I forgot to say that blockamountxy is a vector that is holding how many blocks there is in a row/column blockamountxy.Y is the Y axis and that is always = 8 in this case. That value is never changed


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group