 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Football play
import time
import random
#Global Variables
width = 1040
height = 640
x_center = width/2
y_center = height/2
yard = 5
splits = 35
def callPlay():
qb = ['gun', 'reg']
backfield = ['sp', 'rt', 'lt']
receivers = ['wirt', 'wilt', 'slrt', 'sllt']
routes = ['0','1','2','3','4','5','6','7','8','9']
for playCount in range(1,11):
thePlay = random.choice(qb) + " " + random.choice(backfield) + " " + random.choice(receivers) + " " + random.choice(routes) + random.choice(routes) + random.choice(routes)
printNow( str(playCount) + ") " + thePlay + "\n" )
runPlay( thePlay )
time.sleep(1)
def runPlay(thePlay):
world = makeWorld(width, height)
drawFormation(thePlay[0:11],world)
moveIt(thePlay,world)
def drawFormation(formation,world):
#Make 5 down linemen
for index in range(1,6):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+(index-3)*splits, y_center)
#Make QB
temp = makeTurtle(world)
temp.penUp()
if (formation[0:3] =='gun'):
temp.moveTo(x_center, y_center+4*splits)
else:
temp.moveTo(x_center, y_center+1*splits)
#Make 2 Backs
if (formation[4:6] == 'sp'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-2*splits, y_center+3*splits)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+2*splits, y_center+3*splits)
if (formation[4:6] == 'rt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-0*splits, y_center+3*splits)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+2*splits, y_center+3*splits)
if (formation[4:6] == 'lt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-2*splits, y_center+3*splits)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+0*splits, y_center+3*splits)
#Make X,Y,Z
if (formation[7:11] == 'wirt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-9*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+3*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+9*splits, y_center+1*splits)
if (formation[7:11] == 'wilt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+9*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-3*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-9*splits, y_center+1*splits)
if (formation[7:11] == 'slrt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+9*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-3*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+5*splits, y_center+1*splits)
if (formation[7:11] == 'sllt'):
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-9*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center+3*splits, y_center)
temp = makeTurtle(world)
temp.penUp()
temp.moveTo(x_center-5*splits, y_center+1*splits)
#Color team
team = getTurtleREMOVEDst(world)
for turtle in team:
if (turtle.getXPos() == x_center) and (turtle.getYPos() == y_center):
turtle.setBodyColor(blue)
turtle.setShellColor(darkGray)
else:
turtle.setBodyColor(blue)
turtle.setShellColor(blue)
def moveIt(thePlay, world):
#Delay for snap count
time.sleep(1)
#Pass routes for XYZ
x_route = int(thePlay[12])
y_route = int(thePlay[13])
z_route = int(thePlay[14])
#Blocking assignment for front 5 linemen
block = fwd(5)
#Initialize routes for XYZ
route = []
for index in range(0,10):
route.append('')
route[0] = fwd(10)
route[1] = fwd(10) + ['turnREMOVEDft()'] + fwd(10)
route[2] = fwd(10) + ['turnRight()'] + fwd(10)
route[3] = fwd(20) + ['turnREMOVEDft()'] + fwd(15)
route[4] = fwd(20) + ['turnRight()'] + fwd(15)
route[5] = fwd(30) + ['turnREMOVEDft()'] + fwd(20)
route[6] = fwd(30) + ['turnRight()'] + fwd(20)
route[7] = fwd(30) + ['turn(-45)'] + fwd(30)
route[8] = fwd(30) + ['turn(45)'] + fwd(30)
route[9] = fwd(50)
#QB Drop
qbdrop = bwd(20)
#REMOVEDft back moves
lbblockStraight = fwd(5)
lbblockStraightFlats = fwd(5) + ['turn(-45)'] + fwd(50)
lbblockREMOVEDft = fwd(1) + ['turn(-60)'] + fwd(10)
lbblockREMOVEDftFlare = fwd(1) + ['turn(-45)'] + fwd(5) + ['turn(-45)'] + ['turn(-15)'] + fwd(30)
#Right back moves
rbblockStraight = fwd(5)
rbblockStraightFlats = fwd(5) + ['turn(45)'] + fwd(50)
rbblockREMOVEDft = fwd(1) + ['turn(60)'] + fwd(10)
rbblockREMOVEDftFlare = fwd(1) + ['turn(45)'] + fwd(5) + ['turn(45)'] + ['turn(15)'] + fwd(30)
team = getTurtleREMOVEDst(world)
for turtle in team:
turtle.penDown()
#Get linemen
linemen = []
for index in range(0,5):
linemen.append(team[index])
#Get XYZ
x = team[8]
y = team[9]
z = team[10]
#Get QB
qb = team[5]
#Get REMOVEDft Back and Right Back
lb = team[6]
rb = team[7]
for step in range(1,50):
#REMOVEDnemen
if step < len(block):
for turtle in linemen:
eval('turtle.' + block[step])
#XYZ
if step < len(route[x_route]):
eval('x.' + route[x_route][step])
if step < len(route[y_route]):
eval('y.' + route[y_route][step])
if step < len(route[z_route]):
eval('z.' + route[z_route][step])
#QB
if (thePlay[0:3] != 'gun') and (step < len(qbdrop)):
eval('qb.' + qbdrop[step])
#REMOVEDft Back
if (thePlay[4:6] == 'sp') and (step < len(lbblockStraightFlats)):
eval('lb.' + lbblockStraightFlats[step])
if (thePlay[4:6] == 'rt') and (step < len(lbblockREMOVEDft)):
eval('lb.' + lbblockREMOVEDft[step])
if (thePlay[4:6] == 'lt') and (step < len(lbblockREMOVEDftFlare)):
eval('lb.' + lbblockREMOVEDftFlare[step])
#Right Back
if (thePlay[4:6] == 'sp') and (step < len(rbblockStraightFlats)):
eval('rb.' + rbblockStraightFlats[step])
if (thePlay[4:6] == 'lt') and (step < len(rbblockREMOVEDft)):
eval('rb.' + rbblockREMOVEDft[step])
if (thePlay[4:6] == 'rt') and (step < len(rbblockREMOVEDftFlare)):
eval('rb.' + rbblockREMOVEDftFlare[step])
#Delay for viewing
time.sleep(0.1)
def fwd(d):
temp = []
for index in range(0,d):
temp.append('forward(yard)')
return temp
def bwd(d):
temp = []
for index in range(0,d):
temp.append('backward(yard)')
return temp
Link to this Page