Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Few questions about minesweeper
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
31201558




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: 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 : array 1 .. 10, 1 .. 10 of string
var value : array 1 .. 9, 1 .. 9 of int
var minex, miney : array 1 .. 10 of int
buttonchoose ("multibutton")
for a : 0 .. 320 by 40
    for b : 0 .. 320 by 40
        drawfillbox (a, b, a + 38, b + 38, 7)
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (i, j) := "not mine"
        value (i, j) := 0
    end for
end for
%mines
for i : 1 .. 10
    minex (i) := Rand.Int (0, 359)
    miney (i) := Rand.Int (0, 359)
    minex (i) := minex (i) - minex (i) mod 40
    miney (i) := miney (i) - miney (i) mod 40
    drawfillbox (minex (i), miney (i),minex (i)+38,miney (i)+38 ,green)
end for
for i : 1 .. 10
       
        cells (minex (i) div 40+1, miney (i) div 40+1) := "mine"
end for
for i : 1 .. 9
    for j : 1 .. 9
        if cells (i, j) = "mine" then
            if j + 1 <= 9 then
                if cells (i, j + 1) not= "mine" then
                    value (i, j + 1) += 1
                end if
            end if
            if i + 1 <= 9 and j + 1 <= 9 then
                if cells (i + 1, j + 1) not= "mine" then
                    value (i + 1, j + 1) += 1
                end if
            end if
            if i + 1 <= 9 then
                if cells (i + 1, j) not= "mine" then
                    value (i + 1, j) += 1
                end if
            end if
            if i + 1 <= 9 and j - 1 > 0 then
                if cells (i + 1, j - 1) not= "mine" then
                    value (i + 1, j - 1) += 1
                end if
            end if
            if j - 1 > 0 then
                if cells (i, j - 1) not= "mine" then
                    value (i, j - 1) += 1
                end if
            end if

            if i - 1 > 0 and j - 1 > 0 then
                if cells (i - 1, j - 1) not= "mine" then
                    value (i - 1, j - 1) += 1
                end if
            end if
            if i - 1 > 0 then
                if cells (i - 1, j) not= "mine" then
                    value (i - 1, j) += 1
                end if
            end if
            if i - 1 > 0 and j + 1 <= 9 then
                if cells (i - 1, j + 1) not= "mine" then
                    value (i - 1, j + 1) += 1
                end if
            end if
        end if
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        if value (i, j) > 0 then
            cells (i, j) := "num cells" + intstr (value (i, j))
        end if
    end for
end for

loop
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    for i : 1 .. 10
        if mx = minex (i) and my = miney (i) and mb = 1 then
            dead := true
        end if
    end for
    var a : int
    var b : int
    a := mx div 40
    b := my div 40
    if cells (a, b) = "num cells" and mb = 1 then
        font := Font.New ("serif:36")
        Draw.Text (intstr (value (a, b)), mx, my, font, red)
    end if
    if cells (a, b) = "not mine" and mb = 1 then
        drawfillbox (mx + 1, my + 1, mx + 37, my + 37, white)
    end if
    exit when dead
    delay (100)
end loop



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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: 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
31201558




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: 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......
Tony




PostPosted: Mon Jan 03, 2011 2:32 am   Post subject: RE:Few questions about minesweeper

And with 13 hours to spare! Well done Smile
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: 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 : array 1 .. 10, 1 .. 10 of string
var value : array 1 .. 9, 1 .. 9 of int
var minex, miney : array 1 .. 10 of int
var totalTime : real := 0
buttonchoose ("multibutton")
for a : 0 .. 320 by 40
    for b : 0 .. 320 by 40
        drawfillbox (a, b, a + 38, b + 38, 7)
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (i, j) := "not mine"
        value (i, j) := 0
    end for
end for
%mines
for i : 1 .. 10
    minex (i) := Rand.Int (0, 359)
    miney (i) := Rand.Int (0, 359)
    minex (i) := minex (i) - minex (i) mod 40
    miney (i) := miney (i) - miney (i) mod 40
    drawfillbox (minex (i), miney (i), minex (i) + 38, miney (i) + 38, green)
end for
for i : 1 .. 10
    cells (minex (i) div 40 + 1, miney (i) div 40 + 1) := "mine"
end for
for i : 1 .. 9
    for j : 1 .. 9
        if cells (i, j) = "mine" then
            if j + 1 <= 9 then
                if cells (i, j + 1) not= "mine" then
                    value (i, j + 1) += 1
                end if
            end if
            if i + 1 <= 9 and j + 1 <= 9 then
                if cells (i + 1, j + 1) not= "mine" then
                    value (i + 1, j + 1) += 1
                end if
            end if
            if i + 1 <= 9 then
                if cells (i + 1, j) not= "mine" then
                    value (i + 1, j) += 1
                end if
            end if
            if i + 1 <= 9 and j - 1 > 0 then
                if cells (i + 1, j - 1) not= "mine" then
                    value (i + 1, j - 1) += 1
                end if
            end if
            if j - 1 > 0 then
                if cells (i, j - 1) not= "mine" then
                    value (i, j - 1) += 1
                end if
            end if

            if i - 1 > 0 and j - 1 > 0 then
                if cells (i - 1, j - 1) not= "mine" then
                    value (i - 1, j - 1) += 1
                end if
            end if
            if i - 1 > 0 then
                if cells (i - 1, j) not= "mine" then
                    value (i - 1, j) += 1
                end if
            end if
            if i - 1 > 0 and j + 1 <= 9 then
                if cells (i - 1, j + 1) not= "mine" then
                    value (i - 1, j + 1) += 1
                end if
            end if
        end if
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        if value (i, j) > 0 then
            cells (i, j) := "num cells" + intstr (value (i, j))
        end if
    end for
end for
loop
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    if mx < 0 then
        mx := 0
    elsif mx > 359 then
        mx := 359
    end if
    if my < 0 then
        my := 0
    elsif my > 359 then
        my := 359
    end if
    for i : 1 .. 10
        if mx = minex (i) and my = miney (i) and mb = 1 then
            dead := true
        end if
    end for
    var a : int
    var b : int
    a := mx div 40
    b := my div 40
    if cells (a + 1, b + 1) not= "num cells" and mx < 359 and my < 359 and mb = 1 then
        font := Font.New ("serif:36")
        Draw.Text (intstr (value (a + 1, b + 1)), mx, my, font, red)
    end if
    if cells (a + 1, b + 1) = "not mine" and mb = 1 then
        drawfillbox (mx + 1, my + 1, mx + 37, my + 37, white)
    end if
    locate (1, 1)
    totalTime := totalTime + 0.1
    put totalTime
    if totalTime = 999 then
        dead := true
    end if
    exit when dead
    delay (100)
end loop



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?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 42 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: