Down below there are 2 .py code. Please read the question paper carefully and help me solve this paper using Gitbash. Th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Down below there are 2 .py code. Please read the question paper carefully and help me solve this paper using Gitbash. Th

Post by answerhappygod »

Down below there are 2 .py code. Please read the question paper
carefully and help me solve this paper using Gitbash. Thank you
!!!!
test3.py code -
'''
beaconSim.py - beacon simulation, knights move to the beacon
when lit
and run away
when it goes out
'''
import matplotlib.pyplot as plt
import numpy as np
import random
from grailCast import *
MAXROWS = 40
MAXCOLS = 60
def plot_feature_scatter(itemlist, colour, limits):
xlist = []
ylist = []
slist = []
for r,c in itemlist:
ylist.append(limits[0] - r - 1)
xlist.append(c)
slist.append(100)
plt.scatter(xlist,ylist,color=colour, marker='s',
s=slist)
def plot_knight_scatter(knights, limits):
xlist = []
ylist = []
slist = []
clist = []
for k in range(len(knights)):
ylist.append(limits[0] -
knights[k].getRow() - 1)
xlist.append(knights[k].getCol()) #flip
rows/columns to y/x
slist.append(40)
clist.append(k)
plt.scatter(xlist,ylist,s=slist,c=clist)
def main():
knightNames = ["Sir Galahad", "Sir Robin", "Sir
Lancester", "Sir Donald", "Sir David", "Sir Alexander"]
beacons = [(20,30)]
beaconLit = False
limits = [MAXROWS, MAXCOLS]
# Starting population
numKnights = 6
knightList = []
for i in range(numKnights): # add knight
objects to grid
knightList.append(Knight(limits,
knightNames))
# Simulation
for t in range(10):
print("### Timestep ", t, "###")
for i in range(numKnights):

knightList.lure(beacons, limits)
ax = plt.axes()
ax.set_facecolor("palegreen")
plot_knight_scatter(knightList,
limits)
plot_feature_scatter(beacons, "yellow",
limits)
plt.title("Behold! At timestep 2 the
beacons were out")
plt.xlabel("Columns")
plt.ylabel("Rows")
plt.xlim(-1,MAXCOLS)
plt.ylim(-1,MAXROWS)
plt.pause(1)
plt.clf()
if __name__ == "__main__":
main()
grailCast.py code -
'''
grailCast.py - characters based on The Holy Grail, by Monty
Python
Cast:
Knight - the knights of the round table, lured by a beacon
'''
import random
class Knight():
'''
Knight - has a row,col position and a name
__init__ arguments:
row : within MAXROWS
col : within MAXCOLS
name : a string
'''
def __init__(self, limits, name):
self.row = random.randint(0,
limits[0]-1)
self.col = random.randint(0,
limits[1]-1)
self.name = name
self.captured = False
self.felloff = False
# Accessor methods
def getRow(self): # you
*could* access these directly
return self.row # but
showing how we can protect the data
def getCol(self):
return self.col
def getName(self):
return self.name
# Mutator methods
def lure(self, beacons, limits):
'''
lure - moves the individual knight
towards the beacon(s)
beacons - a list of beacon tuples
(round bracket lists)
limits - the boundaries of the
"world"
'''
chosenBeacon = beacons[0] # could have
multiple beacons...
self.row -= 1
self.col -= 1
def runaway(self, beacons, limits):
'''
runaway - moves the individual knight
away from the beacon(s)
beacons - a list of beacon tuples
(round bracket lists)
limits - the boundaries of the
"world"
'''
chosenBeacon = beacons[0]
self.row += 1
self.col += 1

Down Below There Are 2 Py Code Please Read The Question Paper Carefully And Help Me Solve This Paper Using Gitbash Th 1
Down Below There Are 2 Py Code Please Read The Question Paper Carefully And Help Me Solve This Paper Using Gitbash Th 1 (671.69 KiB) Viewed 43 times
Bb Modify Grade-Integrating Indig X [136 Assessments - Fundamentals of X Feedback Studio → C Ⓒ File F:/COMP1005/Practical%20Test%203/PracTest3_Tues.pdf 1 of 1 Q +? COMP1005 - Practical Test 3 Within your work area, create a PracTest3 directory to work in. 1. Download and modify a Python program Download the zip file from Blackboard/Assessments and put it in the PracTest3 directory. Unzip the file using the unzip command, then edit test3.py and grailCast.py as needed to satisfy the instructions below: Modify the code to: 1. Have a plot title including the timestep and whether the beacon is lit: "Behold! At timestep <5> the beacons were <lit>". 2. Have a green background to the plot, and annotate the names of the knights onto their positions. 3. Make the beacon change from lit (True) to unlit (False), randomly with a ¼ chance. Print out the beacon state on each timestep. 4. Add more knights to have 6 in the simulation, and give them names. 5. Update the lure and runaway methods in Knight to print out the name and movement of the knight. 6. Update lure and runaway to move towards and away from the beacon. 7. Update lure to capture the knight if they get to the beacon. 8. Update runaway for the knight to fall off the edge of the Earth if they go past the map limits. (1/2 mark each) 2. README, saved plots and history Record the history of the commands you've used: history > hist.txt Create or copy a README file and update it to include info on your code 3. Submission and Assessment Ask your tutor to assess your work when complete. All of your work should be submitted via Blackboard through the link on the Assessment page. This should be done as a single "zipped" file. [D Page view X Tn Course: Integrating Indigenous X A Read aloud Add textDraw Highlight Erase Hints: ● Familiarise yourself with the code before making changes - e.g. grailCast.py is a module for classes to represent the knights in the simulation Substitute just the value into <5> and <lit> - no brackets required. ● Look at slides and/or matplotlib documentation for info on plotting Move one unit in the rows and/or the columns on each timestep • • Use the self.fallen and self.captured instance variables to avoid moving the knights once they are lost. ● The background below is palegreen - the background needs to be drawn first ● Sample output is below: ### Timestep 8 *** The beacon is out RUN AWAY! Sir Galahad survives at row 10 and col 58 Sir Robin has fallen! Sir Lancelot survives at row 11 and col 36 Sir Bedevere survives at row 9 and col 5 Sir Loin fell to his doom! Sir Render survives at row 15 and col 52 ###Timestep 9 *** The beacon is out RUN AWAY! Sir Galahad survives at row 9 Sir Robin has fallen! col 59 STP Sir Lancelot survives at row 10 Sir Bedevere survives at row 8 and col 37 and col 4 Sir Loin has fallen! and col 53 Sir Render survives at row 14 Timestep 10 The beacon is out RUN AWAY! sir Galahad survives at row 8 Sir Robin has fallen! and col 601 Sir Lancelot survives at row 9 Sir Bedevere survives at row 7 and col 38 and col 3 Sir Loin has fallen! Sir Render survives at row 13 and col 54 Timestep 11 Beware the beacon is lit and col 59 sir Galahad survives at row 9 Sir Robin has fallen! Sir Lancelot survives at row 10 Sir Bedevere survives at row 8 Sir Loin has fallen! and col 37 and col 4 Sir Render survives at row 14 and col 53 35- 25 25- 30- 5. PracTest3 Tues.pdf Behold! At timestep 2 the Beacons were out Columns 10 20 X + 60 Q so 20 X
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply