Posted: 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 ?
Sponsor Sponsor
Tony
Posted: 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.
Posted: 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"
Tony
Posted: 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.
Posted: Mon Jan 03, 2011 2:01 am Post subject: Re: Few questions about minesweeper
Turing:
var mx, my, mb, font :int var dead :=false var cells :array1.. 10, 1.. 10ofstring var value :array1.. 9, 1.. 9ofint var minex, miney :array1.. 10ofint buttonchoose("multibutton") for a :0.. 320by40 for b :0.. 320by40 drawfillbox(a, b, a + 38, b + 38, 7) endfor endfor
for i :1.. 9 for j :1.. 9
cells (i, j):="not mine"
value (i, j):=0 endfor endfor %mines for i :1.. 10
minex (i):= Rand.Int (0, 359)
miney (i):= Rand.Int (0, 359)
minex (i):= minex (i) - minex (i)mod40
miney (i):= miney (i) - miney (i)mod40 drawfillbox(minex (i), miney (i),minex (i)+38,miney (i)+38 ,green) endfor
for i :1.. 10
cells (minex (i)div40+1, miney (i)div40+1):="mine" endfor for i :1.. 9 for j :1.. 9 if cells (i, j)="mine"then if j + 1 <= 9then if cells (i, j + 1)not= "mine"then
value (i, j + 1) +=1 endif endif if i + 1 <= 9and j + 1 <= 9then if cells (i + 1, j + 1)not= "mine"then
value (i + 1, j + 1) +=1 endif endif if i + 1 <= 9then if cells (i + 1, j)not= "mine"then
value (i + 1, j) +=1 endif endif if i + 1 <= 9and j - 1 > 0then if cells (i + 1, j - 1)not= "mine"then
value (i + 1, j - 1) +=1 endif endif if j - 1 > 0then if cells (i, j - 1)not= "mine"then
value (i, j - 1) +=1 endif endif
if i - 1 > 0and j - 1 > 0then if cells (i - 1, j - 1)not= "mine"then
value (i - 1, j - 1) +=1 endif endif if i - 1 > 0then if cells (i - 1, j)not= "mine"then
value (i - 1, j) +=1 endif endif if i - 1 > 0and j + 1 <= 9then if cells (i - 1, j + 1)not= "mine"then
value (i - 1, j + 1) +=1 endif endif endif endfor endfor
for i :1.. 9 for j :1.. 9 if value (i, j) > 0then
cells (i, j):="num cells" + intstr(value (i, j)) endif endfor endfor
loop mousewhere(mx, my, mb)
mx := mx - mx mod40
my := my - my mod40 for i :1.. 10 if mx = minex (i)and my = miney (i)and mb =1then
dead :=true endif endfor var a :int var b :int
a := mx div40
b := my div40 if cells (a, b)="num cells"and mb =1then
font :=Font.New("serif:36") Draw.Text(intstr(value (a, b)), mx, my, font, red) endif if cells (a, b)="not mine"and mb =1then drawfillbox(mx + 1, my + 1, mx + 37, my + 37, white) endif exitwhen dead
delay(100) endloop
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...
Tony
Posted: 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.
Posted: 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:
Turing:
var mx, my, mb, font :int var dead :=false var cells :array1.. 10, 1.. 10ofstring var value :array1.. 9, 1.. 9ofint var minex, miney :array1.. 10ofint var totalTime :real:=0 buttonchoose("multibutton") for a :0.. 320by40 for b :0.. 320by40 drawfillbox(a, b, a + 38, b + 38, 7) endfor endfor
for i :1.. 9 for j :1.. 9
cells (i, j):="not mine"
value (i, j):=0 endfor endfor %mines for i :1.. 10
minex (i):= Rand.Int (0, 359)
miney (i):= Rand.Int (0, 359)
minex (i):= minex (i) - minex (i)mod40
miney (i):= miney (i) - miney (i)mod40 drawfillbox(minex (i), miney (i), minex (i) + 38, miney (i) + 38, green) endfor
for i :1.. 10
cells (minex (i)div40 + 1, miney (i)div40 + 1):="mine" endfor
for i :1.. 9 for j :1.. 9 if cells (i, j)="mine"then if j + 1 <= 9then if cells (i, j + 1)not= "mine"then
value (i, j + 1) +=1 endif endif if i + 1 <= 9and j + 1 <= 9then if cells (i + 1, j + 1)not= "mine"then
value (i + 1, j + 1) +=1 endif endif if i + 1 <= 9then if cells (i + 1, j)not= "mine"then
value (i + 1, j) +=1 endif endif if i + 1 <= 9and j - 1 > 0then if cells (i + 1, j - 1)not= "mine"then
value (i + 1, j - 1) +=1 endif endif if j - 1 > 0then if cells (i, j - 1)not= "mine"then
value (i, j - 1) +=1 endif endif
if i - 1 > 0and j - 1 > 0then if cells (i - 1, j - 1)not= "mine"then
value (i - 1, j - 1) +=1 endif endif if i - 1 > 0then if cells (i - 1, j)not= "mine"then
value (i - 1, j) +=1 endif endif if i - 1 > 0and j + 1 <= 9then if cells (i - 1, j + 1)not= "mine"then
value (i - 1, j + 1) +=1 endif endif endif endfor endfor
for i :1.. 9 for j :1.. 9 if value (i, j) > 0then
cells (i, j):="num cells" + intstr(value (i, j)) endif endfor endfor loop mousewhere(mx, my, mb)
mx := mx - mx mod40
my := my - my mod40 if mx < 0then
mx :=0 elsif mx > 359then
mx :=359 endif if my < 0then
my :=0 elsif my > 359then
my :=359 endif for i :1.. 10 if mx = minex (i)and my = miney (i)and mb =1then
dead :=true endif endfor var a :int var b :int
a := mx div40
b := my div40 if cells (a + 1, b + 1)not= "num cells"and mx < 359and my < 359and mb =1then
font :=Font.New("serif:36") Draw.Text(intstr(value (a + 1, b + 1)), mx, my, font, red) endif if cells (a + 1, b + 1)="not mine"and mb =1then drawfillbox(mx + 1, my + 1, mx + 37, my + 37, white) endif locate(1, 1)
totalTime := totalTime + 0.1 put totalTime
if totalTime =999then
dead :=true endif exitwhen dead
delay(100) endloop
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?