Welcome, Guest

Author Topic: Coding  (Read 279441 times)

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Coding
« on: June 09, 2012, 02:04:23 PM »
Post python code, python stuff, maybe even a python.

« Last Edit: December 12, 2013, 01:58:04 PM by vh »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #1 on: June 09, 2012, 02:05:30 PM »
current work on a darvincian name generator, there's probably a way to optimize this way better, but i'm lazy

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Python
« Reply #2 on: June 09, 2012, 02:53:20 PM »
My "building image generator" or whatever it's generating.
« Last Edit: June 11, 2012, 05:39:00 AM by Bla »

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Python
« Reply #3 on: June 09, 2012, 03:27:44 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '72432'.

« Last Edit: March 22, 2021, 01:40:34 AM by FiahOwl »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #4 on: June 09, 2012, 05:01:47 PM »
Darvincian Name Generator

It's not perfect, but the best i can do :P, sometimes, too many of the same letter shows up but it usually works well.

Haven't figured out how to use a while loop on the seperate blocks of code so i just made 2 programs one with 1 name out put another with 10 and i'll do one with 100 if anyone wants
« Last Edit: June 09, 2012, 05:11:34 PM by mudkipz »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #5 on: June 11, 2012, 04:59:53 AM »
lolidunno

Code: [Select]
health = 100
matthealth = 100

def promptaction():
act = raw_input("Wat do?") #run, fight
act.strip("\n")
return act

def action(thing):
modify = "%s" % thing
uppercase = modify.upper()
print "USER used %s!" % uppercase
if uppercase == "TAIL WHIP":
matthealth = matthealth - 20
return "MATTY takes 20 damage."
elif uppercase == "PONY":
matthealth = matthealth - 50
return "MATTY takes 50 damage."
elif uppercase == "MUD SLAP":
matthealth = matthealth - 15
return "MATTY takes 15 damage."
elif uppercase == "CHAT":
matthealth = matthealth - 45
return "MATTY takes 45 damage."
else:
print "Not a valid move."

print "A wild MATTY appeared!"

action = promptaction()

if action == "fight":
move = raw_input("TAIL WHIP, PONY, MUD SLAP, CHAT: ")
move.strip("\n")
print action(move)
if matthealth < 1:
print "MATTY fainted!"
else:
action = promptaction()
elif action == "run":
print "You got away!"
else:
print "fsjfkdsjfkdsk"

Did it in like 30 mins and it really doesn't work as intended yet, maybe I'll mess with it later

It should work if you paste and save the code... I didn't test it though, so no guarantees.

I really wanted it to be more of a surprise but that would require me NOT SHARING SOMETHING or not going to sleep.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #6 on: June 18, 2012, 02:13:28 PM »
asdf

*takes about 15 seconds to run so be patient*

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #7 on: August 06, 2012, 02:46:52 AM »
When i code, it's a contest between me pressing the prtsc sysrq button as fast as humanly can, and that evil little black box of error messages trying to hide from me :P

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #8 on: August 06, 2012, 11:04:56 AM »
When i code, it's a contest between me pressing the prtsc sysrq button as fast as humanly can, and that evil little black box of error messages trying to hide from me :P
open cmd and type C:\<python directory> file.py

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #9 on: October 05, 2012, 07:34:35 PM »
the following code lets you measure the time elapsed since you last ran the function that resets the time. it works even when closed out and restarted because the time data is stored in a save.txt in the same directory as the .py
In addition, it will not be messed up even if you change your computer system time, the time is pulled from the internet. (you need the internet for this to work at all)


import ntplib
import time
import sys
import os

def tme():
    global realtime
    global computertime
    global timeoff
    c = ntplib.NTPClient()
    response = c.request('europe.pool.ntp.org', version=3)
    timeoff = response.offset
    computertime = time.time()
    realtime = timeoff+computertime

def wryte():
    tme()
    file = open ('save.txt', 'r+')
    print file
    wrytestring = repr(realtime)
    file.write(wrytestring)
    file.close()
    os.system('cls')
    print 'Time Reset'

def interval():
    tme()
    file = open ('save.txt', 'r+')
    print file
    lasttime = float(file.readline())
    os.system('cls')
    print 'Time elapsed:',realtime-lasttime
    file.close()
    
def run():
    choice = int(input('1=reset, 2=elapsed time, 3=quit'))
    if choice == 1:
        wryte()
    if choice == 2:
        interval()
    if choice ==3:
        sys.exit()

x = 0
while (x == 0):
    run()
  
  

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #10 on: October 07, 2012, 10:33:45 PM »
I'm using your code above to download and display tropical product updates.

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Python
« Reply #11 on: October 07, 2012, 10:48:27 PM »
on dargen100: too much x, nawt enuf w.

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #12 on: October 08, 2012, 12:29:59 AM »
Code: [Select]
import ntplib #http://pypi.python.org/pypi/ntplib/
import time
import sys
import os
import urllib2
from datetime import datetime

def tme():
    global realtime
    global computertime
    global timeoff
    c = ntplib.NTPClient()
    response = c.request('europe.pool.ntp.org', version=3)
    timeoff = response.offset
    computertime = time.time()
    realtime = timeoff+computertime

def wryte():
    tme()
    file = open ('save.txt', 'r+')
    print file
    wrytestring = repr(realtime)
    file.write(wrytestring)
    file.close()
    os.system('cls')
    print 'Time Reset'
    print 'Time now:',realtime
    d2 = datetime.fromtimestamp( int(float(realtime) ) )
    print d2

def dfilewtpq():
file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpq20.rjtd..txt")
output = open('wtpq20_1.txt','w+b')
output.write(file.read())
output.seek(0)
header = output.read(6)
output.seek(12)
newproducttime = output.read(6)
output.close()
output = open('wtpq20.txt','rb')
output.seek(12)
producttime = output.read(6)
output.close()
if newproducttime == producttime:
return "none"
elif newproducttime != producttime:
output = open('wtpq20.txt','w+b')
copy = open('wtpq20_1.txt','rb')
output.write(copy.read())
output.close()
copy.seek(56)
name = copy.readline()
name = name.strip('\n')
copy.seek(108)
location = copy.readline()
location = location.strip('\n')
copy.seek(132)
dir = copy.readline()
dir = dir.strip('\n')
copy.seek(145)
pres = copy.readline()
pres = pres.strip('\n')
copy.seek(158)
wind = copy.readline()
wind = wind.strip('\n')
update = "WTPQ20 %s %s %s %s %s" % (name, location, dir, pres, wind)
copy.close()
print "File updated."
return update

def checkfiles():
status = dfilewtpq()
tme()
d2 = datetime.fromtimestamp( int(float(realtime) ) )
if status != "none":
print "%s %s" % (d2,status)
else:
print d2,"checked"

def continual():
i = 0
while(i == 0):
checkfiles()
time.sleep(300)
    
def run():
    wryte()
    choice = int(input('1 - time, 2 - quit, 3 - download WTPQ, 4 - continual mode: '))
    if choice == 1:
        wryte()
    if choice == 2:
        sys.exit()
    if choice == 3:
        dfilewtpq()
    if choice == 4:
        os.system('cls')
        continual()

x = 0
while (x == 0):
    run()

I will add the ability for more products to be checked later.

Attatched: what a product looks like when caught

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Python
« Reply #13 on: October 08, 2012, 12:31:09 AM »

Hellpotatoe

  • *****
  • Posts: 230
  • JooJ
Re: Python
« Reply #14 on: October 08, 2012, 04:15:13 AM »

AAAAAAAAaaaaawwww Yeeeeaaaahhhh!!!11

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #15 on: October 08, 2012, 11:45:49 AM »
you had to install ntplib to get it working right?

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #16 on: October 08, 2012, 12:28:53 PM »
Yes.

darscript

(it was called comeon.py because it was my testing script for my cyclone thing and I was mad lol)
« Last Edit: October 08, 2012, 06:05:13 PM by atomic7732 »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #17 on: October 08, 2012, 05:49:26 PM »
Version 1

It searches for west pacific, east pacific, and atlantic discussions and advisories.

Basically if there's a cyclone active, it prints relevant information from the advisory in the cmd, and it will display "...see text" for updated discussions.

(requires ntplib - http://pypi.python.org/pypi/ntplib/ )
« Last Edit: October 08, 2012, 05:54:13 PM by atomic7732 »

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Python
« Reply #18 on: October 08, 2012, 06:09:24 PM »
Yes.

darscript

(it was called comeon.py because it was my testing script for my cyclone thing and I was mad lol)
no it must post in ctam

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #19 on: October 14, 2012, 11:23:26 AM »
http://www.learnpython.org/page/Loops

must complete exercise!

but how

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #20 on: October 20, 2012, 12:09:44 AM »
.gif me ideas for a random text game with forumers in it.

Hellpotatoe

  • *****
  • Posts: 230
  • JooJ
Re: Python
« Reply #21 on: October 20, 2012, 03:09:19 AM »
1º Great Rule: Bla
2º Great Rule: Communism
3º Great Rule: Fiah Hate's Hellpotatoe Nations
4º Great Rule: Cyclones

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #22 on: October 22, 2012, 01:08:28 PM »
ok someone can pretty up the time bars if they want to :P

this python script lets you input a time, and then shows a time bar, which slowly fills up and notifies you with a message of your choice when the time is completed.

input is in seconds

tuto99

  • *****
  • Posts: 533
  • Baba Booey
Re: Python
« Reply #23 on: October 22, 2012, 01:13:56 PM »
Since when do you guys specialize in python!?
I wouldn't mind learning XD

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #24 on: October 22, 2012, 01:17:42 PM »
if you want to learn there are many sites that teach python; or you can just explore the documentation online.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #25 on: October 22, 2012, 01:18:38 PM »
this version makes a beeping noise when finished with timer (no additional installs needed other than python)

if anyone wants i'll make a version where you can select beep or not.

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #26 on: October 23, 2012, 07:50:36 PM »
Code: [Select]
import random

i = 0
x = 100
file = open('file.txt', 'w+b')

while (x > 0):
i = i + 1
die1 = int(random.random()*5)
die2 = int(random.random()*5)
die3 = int(random.random()*5)
die4 = int(random.random()*5)
die5 = int(random.random()*5)
die6 = int(random.random()*5)
if die1 == die2:
if die1 == die3:
if die1 == die4:
if die1 == die5:
if die1 == die6:
print i
j = str(i) + "\n"
i = 0
x = x - 1
file.write(j)
else:
pass
else:
pass
else:
pass
else:
pass
else:
pass


For kip.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #27 on: October 23, 2012, 09:58:11 PM »
and why the hell is the length of blockx increasing by more than 1 each time?

Code: [Select]
import random
import os

#counts stuck attempts
arrayfinish=[]

def setup():
    global n_x, n_y, n_z, posx, posy, posz, blockx, blocky, blockz, xn, xp, yn, yp, zn, zp, n
    #position of bot
    posx=0
    posy=0
    posz=0
    #array for occupied spaces
    blockx=[]
    blocky=[]
    blockz=[]
    #n_x, n_y, n_z
    n_x = 0
    n_y = 0
    n_z = 0
    #step count
    n=0
    #directions = none
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0   
    zp=0

#setting xn, xp, yn, yp, zn, and zp
def direct(n_x, n_y, n_z):
    global xn, xp, yn, yp, zn, zp
    if (n_x < len(blockx) or n_y < len(blocky) or n_z < len(blockz)):       
        #check x n-egative and p-ositive side
        if posx - blockx[n_x] == 1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xn = 1
        if posx - blockx[n_x] == -1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xp = 1
        #check y n-egative and p-ositive side
        if posy - blockx[n_y] == 1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yn = 1
        if posy - blockx[n_y] == -1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yp = 1
        #check z n-egative and p-ositive side
        if posz - blockx[n_z] == 1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zn = 1
        if posz - blockx[n_z] == -1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zp = 1
        #advance one position and redo
        n_x=n_x+1
        n_y=n_y+1
        n_z=n_z+1
        print n_x, 'n_x'
        print len(blockx), 'len'
        #^should increase by 1, but it doesn't!
        direct(n_x, n_y, n_x)
    else: bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
       

#bot movement
def bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z):
    #generate random direction
    direction=random.randint(0,5)
    #the directions
    if xn == 1 and xp == 1 and yn == 1 and yp == 1 and zn == 1 and zp == 1:
        finished(n)
    #check if direction is blocked, if not, move there.
    if direction == 0 and xn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx-1
        n=n+1   
    if direction == 1 and xp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx+1
        n=n+1
    if direction == 2 and yn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy-1
        n=n+1
    if direction == 3 and yp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy+1
        n=n+1
    if direction == 4 and zn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz-1
        n=n+1
    if direction == 5 and zp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz+1
        n=n+1
    #if the space is blocked, rerun
    else:
        bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0
    zp=0
    n_x=0
    n_y=0
    n_z=0
    direct(n_x, n_y, n_z)


    #after bot is stuck
def finished(steps):
    global posx, posy, posz, n
    arrayfinish.append(steps)
    posx=0
    posy=0
    posz=0
    n=0

def mainloop():
    global xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z
    setup()
    direct(n_x, n_y, n_z)
    #bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    finished(n)
    print arrayfinish

mainloop()

os.system('pause')

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #28 on: October 23, 2012, 10:02:21 PM »
ok now this one gets stuck in an endless recursion on line 56

Code: [Select]
import random
import os

#counts stuck attempts
arrayfinish=[]

def setup():
    global n_x, n_y, n_z, posx, posy, posz, blockx, blocky, blockz, xn, xp, yn, yp, zn, zp, n
    #position of bot
    posx=0
    posy=0
    posz=0
    #array for occupied spaces
    blockx=[]
    blocky=[]
    blockz=[]
    #n_x, n_y, n_z
    n_x = 0
    n_y = 0
    n_z = 0
    #step count
    n=0
    #directions = none
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0   
    zp=0

#setting xn, xp, yn, yp, zn, and zp
def direct(n_x, n_y, n_z):
    global xn, xp, yn, yp, zn, zp
    if (n_x < len(blockx) or n_y < len(blocky) or n_z < len(blockz)):       
        #check x n-egative and p-ositive side
        if posx - blockx[n_x] == 1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xn = 1
        if posx - blockx[n_x] == -1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xp = 1
        #check y n-egative and p-ositive side
        if posy - blockx[n_y] == 1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yn = 1
        if posy - blockx[n_y] == -1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yp = 1
        #check z n-egative and p-ositive side
        if posz - blockx[n_z] == 1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zn = 1
        if posz - blockx[n_z] == -1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zp = 1
        #advance one position and redo
        n_x=n_x+1
        n_y=n_y+1
        n_z=n_z+1
        print n_x, 'n_x'
        print len(blockx), 'len'
        direct(n_x, n_y, n_x)
    else: bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
       

#bot movement
def bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z):
    #generate random direction
    direction=random.randint(0,5)
    #the directions
    if xn == 1 and xp == 1 and yn == 1 and yp == 1 and zn == 1 and zp == 1:
        finished(n)
    #check if direction is blocked, if not, move there.
    if direction == 0 and xn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx-1
        n=n+1   
    elif direction == 1 and xp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx+1
        n=n+1
    elif direction == 2 and yn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy-1
        n=n+1
    elif direction == 3 and yp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy+1
        n=n+1
    elif direction == 4 and zn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz-1
        n=n+1
    elif direction == 5 and zp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz+1
        n=n+1
    #if the space is blocked, rerun
    else:
        bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0
    zp=0
    n_x=0
    n_y=0
    n_z=0
    direct(n_x, n_y, n_z)


    #after bot is stuck
def finished(steps):
    global posx, posy, posz, n
    arrayfinish.append(steps)
    posx=0
    posy=0
    posz=0
    n=0

def mainloop():
    global xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z
    setup()
    direct(n_x, n_y, n_z)
    #bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    finished(n)
    print arrayfinish

mainloop()

os.system('pause')

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #29 on: October 23, 2012, 10:22:46 PM »
in this version i've figured that the problem is caused by the if statements in direct not working properly

Code: [Select]
import random
import os

os.sys.setrecursionlimit(9000)

#counts stuck attempts
arrayfinish=[]

def setup():
    global n_x, n_y, n_z, posx, posy, posz, blockx, blocky, blockz, xn, xp, yn, yp, zn, zp, n
    #position of bot
    posx=0
    posy=0
    posz=0
    #array for occupied spaces
    blockx=[]
    blocky=[]
    blockz=[]
    #n_x, n_y, n_z
    n_x = 0
    n_y = 0
    n_z = 0
    #step count
    n=0
    #directions = none
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0   
    zp=0

#setting xn, xp, yn, yp, zn, and zp
def direct(n_x, n_y, n_z):
    global xn, xp, yn, yp, zn, zp
    if (n_x < len(blockx) or n_y < len(blocky) or n_z < len(blockz)):       
        #check x n-egative and p-ositive side
        if posx - blockx[n_x] == 1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xn = 1
        if posx - blockx[n_x] == -1 and posy == blocky[n_y] and posz == blockz[n_z]:
            xp = 1
        #check y n-egative and p-ositive side
        if posy - blockx[n_y] == 1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yn = 1
        if posy - blockx[n_y] == -1 and posx == blocky[n_x] and posz == blockz[n_z]:
            yp = 1
        #check z n-egative and p-ositive side
        if posz - blockx[n_z] == 1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zn = 1
        if posz - blockx[n_z] == -1 and posy == blocky[n_y] and posy == blockz[n_y]:
            zp = 1
        #advance one position and redo
        n_x=n_x+1
        n_y=n_y+1
        n_z=n_z+1
        print n_x, 'n_x'
        print len(blockx), 'len'
        print xn, xp, yn, yp, zn, zp, 'list'
        #^always stays as zero
        direct(n_x, n_y, n_x)
    else: bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
       

#bot movement
def bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z):
    #generate random direction
    direction=random.randint(0,5)
    #the directions
    if xn == 1 and xp == 1 and yn == 1 and yp == 1 and zn == 1 and zp == 1:
        finished(n)
    #check if direction is blocked, if not, move there.
    elif direction == 0 and xn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx-1
        n=n+1   
    elif direction == 1 and xp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posx=posx+1
        n=n+1
    elif direction == 2 and yn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy-1
        n=n+1
    elif direction == 3 and yp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posy=posy+1
        n=n+1
    elif direction == 4 and zn == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz-1
        n=n+1
    elif direction == 5 and zp == 0:
        blockx.append(posx)
        blocky.append(posy)
        blockz.append(posz)
        posz=posz+1
        n=n+1
    #if the space is blocked, rerun
    else:
        bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    xn=0
    xp=0
    yn=0
    yp=0
    zn=0
    zp=0
    n_x=0
    n_y=0
    n_z=0
    direct(n_x, n_y, n_z)


    #after bot is stuck
def finished(steps):
    global posx, posy, posz, n
    arrayfinish.append(steps)
    posx=0
    posy=0
    posz=0
    n=0

def mainloop():
    global xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z
    setup()
    direct(n_x, n_y, n_z)
    #bot_move(xn,xp,yn,yp,zn,zp,n,posx,posy,posz,blockx,blocky,blockz,n_x,n_y,n_z)
    finished(n)
    os.system('pause')
    print arrayfinish
    os.system('pause')


mainloop()

os.system('pause')