rendered paste bodyclass players:
def __init__(self):
self.name=""
self.nh=0
self.pos=[]
self.place="1st"
#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 ((abs(a[0] - b[0]))**2+(abs(a[1] - b[1]))**2+(abs(a[2] - b[2]))**2)**0.5
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()
print "hoopsortNewi: ", newi
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])
print "tempa.keys()", tempa.keys()
print "tempa.values()", tempa.values()[0]
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 evaldict.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 ""
#means no dist calculations to do only hoop
id=0
for x in hoopsort(evallist):
playerlist[x].place=placedict[id]
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.items():
if x!= len(evaldict2.keys()):
playerlist[x[id]].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 ""