Computer Science Canada Few questions about minesweeper |
Author: | 31201558 [ Sun Dec 26, 2010 10:40 pm ] | ||
Post subject: | Few questions about minesweeper | ||
What is it you are trying to achieve? Homework from school Teacher wants us to make a game We just finished one semester so I'm not that good or pro as you do please do not use some code that's hard to be understood you can use some hard code but easy to understand What is the problem you are having? (my code is underneath) 1) The biggest problem I'm having right now is : how to make the number "2" appear when I click an area that have two of the green(mine area) are beside one box. I think if you answered this I can make the etcetera myself 2) A another one: how can I finish the program by winning (found all the mines) 3) How would I make a number clock keep on going in second on the top left corner. 4) No idea how to draw a flag in the middle of green (mine box). 5) When I was indenting the code. It won't let me a box appear says "not enough memory to indent file" Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> |
Author: | Tony [ Sun Dec 26, 2010 11:25 pm ] |
Post subject: | RE:Few questions about minesweeper |
You know where all the mines are. You can figure out how many of those mines are next to any one cell. The winning is typically defined as "opening all cells that are not mines". 3) are you asking about the time or positioning of it? 4) once again, which part are you asking about: positioning, drawing the shape, etc? 5) I would guess that this happens when any particular line has too many elements on it. |
Author: | 31201558 [ Mon Dec 27, 2010 3:03 pm ] |
Post subject: | RE:Few questions about minesweeper |
You've only answered question 5..... which is a question not even related to my program I think you are trying to hint me or something. But I'm really strugling here. I said that I only took one semeter. I'm not good enough to make it your way by myself. Would you please show me some code or something? Or you don't understand my question? I' ll repeat them in your way. 1) But how? 2) Yes what your are saying is right but it's for the windows minesweeper My minesweeper sucks I'm not pro enough to do anything like that Did you try my program? You'll see what I MEAN. YOU can't really open anything. so I'll just make it so that it finishes when all the mines boxes have a flag on it. 3) I'm asking that in Windows minesweeper on the top left corner there is a clock keep on going. I want to make that clock. 4) Once you tried my program You'll know that when you right click one of the green box the flag only appears on one corner of a green box I know it 's because of the mod But I've got no idea how to fix it How would make it in the middle? |
Author: | 31201558 [ Mon Dec 27, 2010 3:46 pm ] |
Post subject: | RE:Few questions about minesweeper |
Ok I messed up. First time ask a question online please forgive me For question 2 please tell me what to do I tried this to open all cells that are not mines: I changed the font colour of the numbers from white to black I added some code elsif mx > x (i) + 80 and my > y (i) + 80 and mb = 1 or mx < x (i) - 80 and my > y (i) + 80 and mb = 1 or mx > x (i) + 80 and my < y (i) - 80 and mb = 1 or mx < x (i) - 80 and my < y (i) - 80 and mb = 1 or mx = x (i) and my > y (i) + 80 and mb = 1 or mx = x (i) and my < y (i) - 80 and mb = 1 or mx > x (i) + 80 and my = y (i) and mb = 1 or mx < x (i) - 80 and my = y (i) and mb = 1 then drawfillbox(mx,my,mx+38,my+38,0) The problem is when I click on a cell that has mines beside them. The number "1" some times appear and sometimes not. Please just tell me what to do. Not what's wrong with it. I basicly knows everything I did wrong. But no idea how to fix it. Just forget about question #4 |
Author: | TokenHerbz [ Mon Dec 27, 2010 3:51 pm ] |
Post subject: | RE:Few questions about minesweeper |
okay first thing is first. in order to solve each tile, we have to check the areas around that square. lets assume all the values start at ZERO. for each time we check the mine tile, we check around that time, and every one of those tiles get a +1 because its near a mine. So if there are 2 mines side by side, if that tile that was +1 from zero from mine 1, will get another +1 making it a +2 from the 2nd mine. so code wise, you want to run threw your tiles row,columns and check for mines, if ones found you want to search all grid tiles around that 1 tile, making that 0 value +1. make sure you exclude the mine tiles. Now, Dont worry about the cutesy things like score/timers etc yet. Lets get your main program working first. its worth more marks for sure. to draw something in the middle of your mine, you need to know a few things. one being the SIZE of your mine tile. then from there we can just position the "?" or picture to draw over that mine at the location of that mine (x,y) and center it using the size of that tile. ex: Draw.Oval(tileX5 + (tileXsize div 2),tileY5 + (tileYsize div 2), size of oval(or pic x, and Y) etc. Tony covered the Q5, lets see what else i see here, hmmz, ahh yes, To know that you "beat" the game, you need to uncover or "know" all the tiles. so you uncover all the NON MINE TILES and you win. otherwise i guess you could also add, if you "FLAG ALL CORRECT MINES" you win to, im not sure the correct real minesweeper winning terms, but its a simple check to see, and if it is then you exit your main loop displaying the correct results of losing/winning. ALSO: Please don't jump to this part yet, as your currect program needs the effort here, but what your looking for is the "" Time.Elapsed "" feature of turing. this returns back the amount if miliseconds since the program started to run, so with some math, you can get your "seconds" "mins" "hours" etc from it. basic setup would be to decalre your time variable to use like var game_time : int then in your loop have it check each time and update your game_time like this game_time := Time.Elapsed --this returns MILISECONDS do some math here and you can display it. ex: instead of showing 70seconds. make it go 1MIN and 10seconds. I guess thats all you need im pretty sure to get a heads start. if you need more assistance feel free to post, i want to see some effort code first! GOOD LUCK! |
Author: | 31201558 [ Mon Dec 27, 2010 11:25 pm ] |
Post subject: | RE:Few questions about minesweeper |
TokenHerbz Your answers for Q1,Q2 AND Q3 are helpful Could you please answer question 1 for me by showing me some code? Just to make sure if you know what I'm asking. You see that my codes are made so that when you click a cell that has one mine tile beside it the number"1" will appear. But if there's a cell that has two mine tiles beside it. The number appear is still "1". How can I make it to "2". |
Author: | Tony [ Tue Dec 28, 2010 12:23 am ] |
Post subject: | RE:Few questions about minesweeper |
If there are at least 2 mines around a cell, then there is also at least 1 mine around the same cell. That should be enough of a hint to address your particular code flow. The code could be much simpler than you are going for right now -- you don't care where the mines around the cell are, just the number of them. There's an 8 or 9 cell block (@TokenHerbz -- you actually don't have to exclude the center block itself; if there's a mine, the player loses before that number shows up), you just care about how many mines are in that set. Count them. |
Author: | TokenHerbz [ Tue Dec 28, 2010 10:02 am ] | ||
Post subject: | RE:Few questions about minesweeper | ||
i suppose i could, i make a program but then i realized, "Maybe i shouldn't of done so with classes" lol -> heres some code tho, the idea is the same, so i think should be usefull.
010 2X0 001 -------> See the X is the tile, -1 .. 1 goes top to bottom, left to right of that X when used like it is in the above. It's important to grow your array (use blank /NIL values) **Turing dont support NIL tho** for your grids extra border so that this check wont error when checking say, your first TILE. instead of it going -1 of its 1st tile and going ERROR, it goes, 0,1,2 -- 1,2 being your game tiles, 0 being the buffer NIL space to let it work, if that makes sense lol... i hope it does. let me know. After we SOLVE THE GRID, we have all our info we need, so we check the tiles thats checked to see what we display or happens. EDIT: ADDED COMMENTS TO MY CODE TO HELP EXPLAIN IT FOR YOU! |
Author: | TokenHerbz [ Tue Dec 28, 2010 10:20 am ] |
Post subject: | RE:Few questions about minesweeper |
@Tony - I did it anyways tho to show it after if its what your saying im thinking is the same thing. |
Author: | Tony [ Tue Dec 28, 2010 1:13 pm ] |
Post subject: | RE:Few questions about minesweeper |
I was thinking of a more general case, without the Quote: if grid (r, c) -> is_a_mine = false but since you're using the same data structure for both the mines and the counters, that check is required. Still, you have clear 3x3 for-loops for the counter, so I approve. |
Author: | 31201558 [ Tue Dec 28, 2010 2:31 pm ] |
Post subject: | RE:Few questions about minesweeper |
I see what you are doing But once you got the number "amount" how would I out put that number. I mean : if mx = x (i) + 40 and my = y (i) + 40 and mb = 1 or mx = x (i) - 40 and my = y (i) + 40 and mb = 1 or mx = x (i) + 40 and my = y (i) - 40 and mb = 1 or mx = x (i) - 40 and my = y (i) - 40 and mb = 1 or mx = x (i) and my = y (i) + 40 and mb = 1 or mx = x (i) and my = y (i) - 40 and mb = 1 or mx = x (i) + 40 and my = y (i) and mb = 1 or mx = x (i) - 40 and my = y (i) and mb = 1 then then what? Draw.Text? Is it something like: Draw.Text(amount,mx,my,font,colour) That's what I was asking in Q3. I just want to make a number keep on going by 1 by using the Draw.Text code Is it something like: var font:int font := Font.New ("serif:36") for x:0..999 by 1 Draw.Text(x,1,maxy-36,font,7) Well, of course it doesn't work this way but what can I do to make it work |
Author: | Tony [ Tue Dec 28, 2010 2:35 pm ] |
Post subject: | RE:Few questions about minesweeper |
check out the function signature for Draw.Text. The "amount" has to be a string, not an integer. |
Author: | 31201558 [ Tue Dec 28, 2010 3:59 pm ] |
Post subject: | RE:Few questions about minesweeper |
How many times do I have to say this I know what's wrong with my program But I'm not pro enough to fix the problem I have. If Draw.Text doesn't work. Which code will? Please tell me |
Author: | jcollins1991 [ Tue Dec 28, 2010 4:31 pm ] |
Post subject: | Re: Few questions about minesweeper |
http://compsci.ca/holtsoft/doc/intstr.html Tony told you what your problem was, there's a link to a function to solve it. You'll never be taught everything in class, sometimes you're gonna have to search google and language documentation for answers. |
Author: | 31201558 [ Wed Dec 29, 2010 4:21 pm ] |
Post subject: | RE:Few questions about minesweeper |
Never used a 2d array before How can I use the 2d array for this? If there is a tutorial where is it? |
Author: | 31201558 [ Wed Dec 29, 2010 4:28 pm ] |
Post subject: | RE:Few questions about minesweeper |
........ Never mind I found the tutorial |
Author: | 31201558 [ Wed Dec 29, 2010 5:34 pm ] |
Post subject: | RE:Few questions about minesweeper |
var counter : array 0 .. 16, 0 .. 16 of int for n : 0 .. 600 by 40 for j : 0 .. 16 for k : 0 .. 16 var boxx : array 1 .. 15 of int := init (n) var boxy : array 1 .. 15 of int := init (n) drawfillbox (boxx (j), boxy (k), boxx (j) + 40, boxy (k) + 40, 7) counter (j, k) := 0 end for end for end for Here's my code for my counter(it can count the mine around it) and to draw all the grid in minesweeper. I'm trying to set all the cell's counter at 0 But I don't know how to set values for an array Is that even possible? |
Author: | Tony [ Wed Dec 29, 2010 5:56 pm ] |
Post subject: | RE:Few questions about minesweeper |
First of all, I don't understand why you are even creating boxx and boxy arrays 4000+ times, but to answer your question regarding setting values for an (entire) array -- the error message you receive should be descriptive enough. If not, the correct question to ask would be about that particular message. |
Author: | 31201558 [ Wed Dec 29, 2010 8:13 pm ] |
Post subject: | RE:Few questions about minesweeper |
I guess I'm really bad at explain questions The question I want to ask is how do I give values for each variables in my array for n : 0 .. 540 by 40 %these are 15 numbers var boxx : array 1 .. 15 of int := init (n) %These are 15 variables end for see: for boxx(1) it value is 0, for boxx(2) it value is 40, for boxx(3) it value is 80. That's what I'm trying to do. In tutorial it says, var mensNames : array 1 .. 3 of string := init ( "Tom", "Dick", "Harry" ) I guess the init feature is for giving values to arrays. |
Author: | 31201558 [ Wed Dec 29, 2010 8:16 pm ] |
Post subject: | RE:Few questions about minesweeper |
The message says : Compile time expression expected |
Author: | 31201558 [ Wed Dec 29, 2010 8:37 pm ] |
Post subject: | RE:Few questions about minesweeper |
Just make sure you saw both of my reply..... |
Author: | Tony [ Wed Dec 29, 2010 9:00 pm ] |
Post subject: | RE:Few questions about minesweeper |
One of the best skills you could pick up (and not just for programming) is the ability to ask the right questions. Takes time and practice though. The right questions will usually lead you to the correct documentation -- reading and interpreting that is the next important life skill to have. The way init works is that it initializes the entire array. In the example you've posted, there are 3 elements and so init has 3 values. 1st element gets 1st value, etc. "Compile time expression expected" is telling you that the expression (the init statement) needs to be available at the compile time (all the values known at the time when you compile the program, not during the run-time). To change the values in an array during the run-time, you'd have to do it one element at a time. For-loops are usually helpful. |
Author: | TokenHerbz [ Thu Dec 30, 2010 9:20 am ] | ||
Post subject: | RE:Few questions about minesweeper | ||
|
Author: | 31201558 [ Mon Jan 03, 2011 12:29 am ] | ||
Post subject: | Re: Few questions about minesweeper | ||
Here's my code now
When I run this it says "Array subscript is out of range. Why? The code is have problem is : cells (minex (i) div 40, miney (i) div 40) := "mine" Well, it's the midnight. The due time is 15 hours later. Please just tell me the answer completely( Please just give me some code and tell me where do I put it. I know this is not good, but.... I've got no time.....) |
Author: | Tony [ Mon Jan 03, 2011 12:47 am ] | ||
Post subject: | RE:Few questions about minesweeper | ||
You have 15 hours, that's plenty of time! Try
|
Author: | 31201558 [ Mon Jan 03, 2011 1:00 am ] |
Post subject: | RE:Few questions about minesweeper |
I don't really understand it just output lots of numbers |
Author: | Tony [ Mon Jan 03, 2011 1:12 am ] |
Post subject: | RE:Few questions about minesweeper |
Until it crashes. Then you know what number was out of array's bounds. |
Author: | 31201558 [ Mon Jan 03, 2011 1:29 am ] |
Post subject: | RE:Few questions about minesweeper |
but each time it's different |
Author: | Tony [ Mon Jan 03, 2011 1:31 am ] |
Post subject: | RE:Few questions about minesweeper |
What's the value of minex (i) ? |
Author: | 31201558 [ Mon Jan 03, 2011 1:33 am ] |
Post subject: | RE:Few questions about minesweeper |
Oh~~~~~ I see, but still don't know what to do. Should I change all the 1..9 to 0..8? |
Author: | 31201558 [ Mon Jan 03, 2011 1:35 am ] |
Post subject: | RE:Few questions about minesweeper |
I know I should not...... But what I need to do ? |
Author: | Tony [ Mon Jan 03, 2011 1:41 am ] |
Post subject: | RE:Few questions about minesweeper |
You need to make sure those values are in the same range as the array. Trace back to where the value comes from, and change your expressions to guarantee that the answer will be in a particular range of values. |
Author: | 31201558 [ Mon Jan 03, 2011 1:45 am ] |
Post subject: | RE:Few questions about minesweeper |
add one to both? cells (minex (i) div 40+1, miney (i) div 40+1) := "mine" |
Author: | Tony [ Mon Jan 03, 2011 1:50 am ] |
Post subject: | RE:Few questions about minesweeper |
That will guarantee the low bound of 1, yes. It will also increase your upper bound value by 1 as well. Coincidentally this might still work, but I'll leave the prove of that up to you. |
Author: | 31201558 [ Mon Jan 03, 2011 2:01 am ] | ||
Post subject: | Re: Few questions about minesweeper | ||
Yes, that problem has solved. But my minesweeper is still a mess Can you run this to see where my problem is? Something gotta be wrong with the mousewhere... |
Author: | Tony [ Mon Jan 03, 2011 2:04 am ] |
Post subject: | RE:Few questions about minesweeper |
Same problem, "Array subscript is out of range". Turing tells you what line the problem is at. You can use the same trick with printing the values being used for indexes, to see when and with what value the bound is broken. |
Author: | 31201558 [ Mon Jan 03, 2011 2:05 am ] |
Post subject: | RE:Few questions about minesweeper |
You'll have to use F1 to run this because of the mousewhere. Just in case you havn't noticed this |
Author: | 31201558 [ Mon Jan 03, 2011 2:12 am ] |
Post subject: | RE:Few questions about minesweeper |
I fixed it again. And I noticed that anywhere that's suppose to have a number don't have one. Why is this happening? |
Author: | Tony [ Mon Jan 03, 2011 2:18 am ] |
Post subject: | RE:Few questions about minesweeper |
Probably because "if cells (a, b) = "num cells" and mb = 1 then" is not true. |
Author: | 31201558 [ Mon Jan 03, 2011 2:26 am ] |
Post subject: | RE:Few questions about minesweeper |
Oh my god!!!!!!!!!!!! It worked!!!!!!!!!!! Thank you so much!!!!!!!!!!!! Tony!!!!!!!!!!!!!!!!!! I'll donate all my bits to you!!!!!!!!!!!!!!! Well, some for token too...... |
Author: | Tony [ Mon Jan 03, 2011 2:32 am ] |
Post subject: | RE:Few questions about minesweeper |
And with 13 hours to spare! Well done ![]() |
Author: | 31201558 [ Thu Jan 06, 2011 6:33 pm ] | ||
Post subject: | Re: Few questions about minesweeper | ||
Well, our teacher has lated the due date because he is so nice...... Therefore I now want to make the open multiboxes feature to work. I just notice that there's a flood fill algorithm to make it. Here's my code:
The problem is, I don't think I got a reveal procedure. Will I still be able to make the flood fill without an reveal procedure? |