All pastes #18069 Raw Edit

Something

public text v1 · immutable
#18069 ·published 2005-07-19 17:37 UTC
rendered paste body
from math import sqrt
class players:
    def __init__(self):
        self.name=""
        self.nh=0
        self.pos=[]
        self.place=""
#p1
player=players()
player.nh=2
player.pos=[1,1,1]
player.name="p1"

#p2
player2=players()
player2.nh=2
player2.pos=[2,2,2]
player2.name="p2"
player3=players()

#p3
player3.nh=3
player3.pos=[3,3,3]
player3.name="p3"
playerlist=[player, player2, player3]

class cHoopList:
    def __init__(self):
        self.pos=[0,0,0]

hoop1 = cHoopList()
hoop2 = cHoopList()
hoop3 = cHoopList()
hoop4 = cHoopList()
hoop5 = cHoopList()
HoopList=[hoop1,hoop2,hoop3,hoop4,hoop5]

def dist(a, b):
	"""
Calculates the distance between two 3D points.
Requires 2 arguments namely 2 3D position lists.
	"""
	return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2)

def hoopsort(tempa):
    tempd = {}
    id = 0
    for x in tempa:	
        tempd[x]=id
        id+=1
    templ=tempd.keys()
    templ.sort()
    newi=[]
    for x in templ:
        newi.append(tempd[x])
    newi.reverse()
    return newi

def distsort(tempa):
    tempdist=[]
    for x in tempa.keys():
        id=0
        for y in tempa.values()[0]:
            tempdist.append(dist(playerlist[y].pos, HoopList[x].pos))
            id+=1
    print "tempdist", tempdist
    tempd = {}
    id = 0
    for x in tempdist:
        tempd[x]=id
        id+=1
    templ=tempd.keys()
    templ.sort()
    newi=[]
    for x in templ:
        newi.append(tempd[x])
    return newi
    
##MAIN##

#create dictionary with repeatedHoop==key and value==correspondingPlayerlistId
evallist=[]
evaldict={}
evaldict2={}
placedict=["1st", "2nd", "3rd", "4th", "5th"]
for x in playerlist:
    evallist.append(x.nh)
id=0
for x in playerlist:
    if evallist.count(x.nh)>1:
        if evaldict.has_key(x.nh):
            evaldict[x.nh].append(id)
        else:
            evaldict[x.nh]=[id]
    else:
        if evaldict2.has_key(x.nh):
            evaldict2[x.nh].append(id)
        else:
            evaldict2[x.nh]=[id]
    id+=1
    
##testing evaldict
#print "Names: ", playerlist[0].name, playerlist[1].name, playerlist[2].name
#print "MultipleHoops: ", evaldict
#print "SingleHoops", evaldict2
#print "Evallist", evallist
#print ""

##debug
print "Names", playerlist[0].name, playerlist[1].name, playerlist[2].name
print "evallist", evallist
print "evaldict", evaldict
print "evaldict2", evaldict2
#means no dist calculations to do only hoop  
id=0
id2=0
for x in evallist:
    newi=hoopsort(evallist)
    print "before if->id", id
    print "before if->id2", id2 
    print "hoopsort->newi->", newi 
    if x!=evaldict.keys()[id2]:
        playerlist[x].place=placedict[id]
    else:
        print x, evaldict.keys()[id2]
        print "else->id", id
        newi=distsort(evaldict)
        playerlist[x].place=placedict[newi[id]]
        id2+=1
    id+=1
    
##testing hoopsort
print "Names", playerlist[0].name, playerlist[1].name, playerlist[2].name
print "Places", playerlist[0].place, playerlist[1].place, playerlist[2].place
print ""

#if evaldict!={}:
#    newi=distsort(evaldict)
#    id=0
#    for x in evaldict.values()[0]:
#        if x!= len(evaldict2.keys()):
#            playerlist[x].place=placedict[newi[id]]
#        id+=1
        
##testing distsort
#print "Names", playerlist[0].name, playerlist[1].name, playerlist[2].name
#print "Places", playerlist[0].place, playerlist[1].place, playerlist[2].place
#print "distsortNewi", newi
#print ""