0 Replies - 320 Views - Last Post: 28 January 2012 - 09:09 AM Rate Topic: -----

Topic Sponsor:

#1 disappearer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-January 12

maze solver(I post the wrong one)

Posted 28 January 2012 - 09:09 AM


from visual import *
def dis(x,ex,y,ey):
    c = sqrt((x-ex)**2+(y-ey)**2)
    return c

def ar(a,b,c,d):
    if a > b:
        if a > c:
            if a > d:
                return a
    if b > a:
        if b > c:
            if b > d:
                return b
    if c > b:
        if c > a:
            if c > d:
                return c
    if d > b:
        if d > c:
            if d > a:
                return d
            
def matr(board):
    row = len(board)
    column = len(board[0])
    B=[]
    for i in range (0,row):
        A=[]
        for j in range (0,column):
            if board[i][j] == 9:
                b = 1000
            else:
                b = board[i][j]
            A.append(B)
        B.append(A)
    print B
    print row
    print column
    if row%2 == 1:
        hr = (row/2)+1
    else:
        hr= (row/2)+0.5
    if column%2 == 1:
        hc = (column/2)+1
    else:
        hc = (column/2)+0.5
    v=[]    
    for i in range (0,row):
        c = []
        for j in range (0,column):
            if B[i][j] == 1000:
                h = box(pos=(i-hr,j-hc),lenght =0.5,width = 2,hieght = 2, color = color.red)
            if B[i][j] == 2:
                h = box(pos=(i-hr,j-hc),lenght =0.5,width = 0.5,hieght = 2, color = color.green)
            if B[i][j] < 0:
                h = box(pos=(i-hr,j-hc),lenght =0.5,width = 0.5,hieght = 2, color = color.white)
            else:
                h = box(pos=(i-hr,j-hc),lenght =0.5,width = 0.5,hieght = 2, color = color.blue)
            c.append(h)
        v.append(c)
    print v

    ball = sphere(radius = 0.5,pos = (-(hr-1),-(hc-1),1),color = color.green)
    ball2 = sphere(radius = 0.5,pos = (-(hr-1),-(hc-1),1),color = color.green)
    face = 0
    for i in range (0,row):
        for j in range (0,column):
            if B[i][j] < 0:
                ex = i
                ey = j
    xx = int(ball.pos.x) +hr
    yy = int(ball.pos.y) +hc
    v = 1
    z = 1
    while v <> 0:
        x = int(ball.pos.x) +hr
        y = int(ball.pos.y) +hc
        if B[x][y] >= 0:
            if B[x+1][y] <> 1000 and B[x+1][y] < B[x][y]:
                av = x+1
                a = dis(av,ex,y,ey)
                if B[x-1][y] <> 1000 and B[x-1][y] < B[x][y]:
                    bv = x-1
                    b = dis(bv,ex,y,ey)
                    if B[x][y+1] <> 1000 and B[x][y+1] < B[x][y]:
                        cv = y+1
                        c = dis(x,ex,cv,ey)
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                    if B[x][y+1] == 1000:
                        c = 0
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                if B[x-1][y] == 1000:
                    b = 0
                    if B[x][y+1] <> 1000 and B[x][y+1] < B[x][y]:
                        cv = y+1
                        c = dis(x,ex,cv,ey)
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                    if B[x][y+1] == 1000:
                        c = 0
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            B[x][y] = B[x][y] + 1000
                            print x , y
                            ball.pos.x += 1
                            v = 1
            if B[x+1][y] == 1000:
                a = 0
                if B[x-1][y] <> 1000 and B[x-1][y] < B[x][y]:
                    bv = x-1
                    b = dis(bv,ex,y,ey)
                    if B[x][y+1] <> 1000 and B[x][y+1] < B[x][y]:
                        cv = y+1
                        c = dis(x,ex,cv,ey)
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                    if B[x][y+1] == 1000:
                        c = 0
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            B[x][y] = B[x][y] + 1000
                            print x , y
                            ball.pos.x -= 1
                            v = 1
                if B[x-1][y] == 1000:
                    b = 0
                    if B[x][y+1] <> 1000 and B[x][y+1] < B[x][y]:
                        cv = y+1
                        c = dis(x,ex,cv,ey)
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            jojo = ar(a,b,c,d)
                            B[x][y] = B[x][y] + 1
                            print x , y
                            if jojo == c:
                                ball.pos.y += 1
                            if jojo == b:
                                ball.pos.x -= 1
                            if jojo == d:
                                ball.pos.y -= 1
                            if jojo == a:
                                ball.pos.x += 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            B[x][y] = B[x][y] + 1000
                            print x , y
                            ball.pos.y += 1
                            v = 1
                    if B[x][y+1] == 1000:
                        c = 0
                        if B[x][y-1] <> 1000 and B[x][y-1] < B[x][y]:
                            dv = y-1
                            d = dis(x,ex,dv,ey)
                            B[x][y] = B[x][y] + 1000
                            print x , y
                            ball.pos.y -= 1
                            v = 1
                        if B[x][y-1] == 1000:
                            d = 0
                            print x , y
                            v = 1
        if B[x][y] < 0:
            v = 0
            
    while z <> 0:
        xxx = int(ball2.pos.x) +hr
        yyy = int(ball2.pos.y) +hc
        if B[xxx][yyy] < 0:
            z = 0
            return z
        else:
            if B[xxx][yyy+1] == 1 or B[xxx][yyy+1] == 2:
                ball2.pos.y += 1
            if B[xxx-1][yyy] == 1 or B[xxx-1][yyy] == 2:
                ball2.pos.x -= 1
            if B[xxx][yyy-1] == 1 or B[xxx][yyy-1] == 2:
                ball2.pos.y -= 1
            if B[xxx+1][yyy] == 1 or B[xxx+1][yyy] == 2:
                ball2.pos.x += 1
        print ball2.pos



Someone please tell me what's wrong.

When I use the open program to use this function

my ball move only one time but my program still running.

I need some advice please

Is This A Good Question/Topic? 0
  • +

Page 1 of 1