1 answer

# Question 2: Virus Wars A popular subgenre of strategy game is the so-called Virus War format,...

###### Question:

Question 2: Virus Wars A popular subgenre of strategy game is the so-called Virus War format, where the player is shown a field of cells, each with a virus count, and may attack other cells within a certain range. We are going to write some classes in Python to implement a simple Virus Wars game. 2a) The position class (9 points) Everything within this game is going to require a position, so it makes sense to define it up front. Define a class Position, with the following fields: • x (float) -> an x coordinate, must be initialized. • y (float) ->a y coordinate, must be initialized. • dx (float) -> a destination x co-ordinate, initialized to zero. dy (float) -> a destination y co-ordinate, initialized to zero. speed (float) -> determines rate of movement, must be initialized. The speed cannot be negative. Raise a ValueError if the speed is provided as a negative number Define the following methods, in addition to init. • move To - takes an x and a y co-ordinate, and sets them to the values of dx and dy respectively. tick - simulates one "second" of simulation time. During a tick, if dx and dy are different than x and y, move x and y towards the values of dx and dy by the value of speed. If x or y are less than speed distance away from dx or dy respectively, set the value of x or y to dx or dy. • distance - takes self and other, calculates the euclidan distance between self and other using pythagorean theorem. In [ ]: your solution for question 2a here In [ ]:  You are encouraged to design some of your own test cases here. In [ ]: * Visible Test for Position created correctly (1 point) p = Position (5, -5, 0.5) assert(p.x == 5 and p.y == -5 and p.dx == 0 and p.dy == 0 and p.speed == 0.5) In [ ]: Semi-Hidden Test for Position updates correctly (1 point)  you'll know if you got it right, but have to reread the question carefully to figure out what you're doing wrong - mocion 21 14
In [ ]: Semi-Hidden Test for Position updates correctly (1 point)  you'll know if you got it right, but have to reread the question carefully to figure out what you're doing wrong p = Position (4, 3, 1.14) p.moveTo(10, 10) p.tick() print(p.x) print(p.y) from hashlib import sha256 hash_fun = lambda x : sha256(Str(x).encode()).hexdigest() assert(hash_fun(p.x) == '47f19dbalac252d2543518a6445ea8081420008505f3eae4e9dc87ff8c356e06') assert(hash_fun(p.y) == 'ef36ba02455468a8f92ff04482d754bb869b53c4cd6b14bb59b49eb47bdc2ced') In [ ] : * Semi-Hidden Test for Distance found correctly (1 point) p = Position (4, 3, 1.14) p2 = Position (6, 4, 1.14) d = p.distance (p2) print(d) from hashlib import sha256 hash_fun = lambda x: sha256( str(x).encode()).hexdigest() assert (hash_fun (round(d, 3)) == 'fedb836f28bd6bf0ea13ea4bbae094484f42a5166edlle3265cd837cef1d286d') In [ ]:  Hidden test for Position

## Answers

#### Similar Solved Questions

1 answer
##### How do you simplify 4k+12+13+k+2k+7?
How do you simplify 4k+12+13+k+2k+7?...
1 answer
##### How do you differentiate the following parametric equation:  x(t)=tlnt, y(t)= cost-tsin^2t ?
How do you differentiate the following parametric equation:  x(t)=tlnt, y(t)= cost-tsin^2t #?...
1 answer
##### Tennies Clinic uses client-visits as its measure of activity. During November, the clinic budgeted for 4,150...
Tennies Clinic uses client-visits as its measure of activity. During November, the clinic budgeted for 4,150 client-visits, but its actual level of activity was 4,140 client-visits. The clinic has provided the following data concerning the formulas used in its budgeting and its actual results for No...
1 answer
##### Ities to stockholders' equity h owing data were taken from Alvarado Company's balance sheet: Dec. 31,...
ities to stockholders' equity h owing data were taken from Alvarado Company's balance sheet: Dec. 31, 2014 Dec 31, 2043 $4,200,000$2,480,000 The stockholders' equity 4,200,000 3,100,000 a compute the ratio of liabilities to stockholders' equity for each year. Round your answers to 2...
1 answer
What is the cash flow to creditors for 2016? showing calculations BALANCE SHEETS 2016 2,860 310 Use the following financial statements to answer questions (Dollars are stated in $millions) INCOME STATEMENT 2015 2016 2015 2016 Net Sales 8,360 9,610 Cash 405 Cost of goods sol 5,247 6,310 Accounts rec... 1 answer ##### Delta Company produces a single product. The cost of producing and selling a single unit of... Delta Company produces a single product. The cost of producing and selling a single unit of this product at the company's normal activity level of 104,400 units per year is: Direct materials Direct labor Variable manufacturing overhead Fixed manufacturing overhead Variable selling and administra... 1 answer ##### Problem Consider the gas phase reaction Part A: Part B Part C: Part DCalculate Kyo at... Problem Consider the gas phase reaction Part A: Part B Part C: Part DCalculate Kyo at 425K Calculate ??, at 298K Calculate AC, at 298K Calculate AC, at 425K Show all work and enter your results of the table below: Part Your results Required units ) ???? at 298K Joules/mol ?GR at 298K Joules/mol Joul... 1 answer ##### Reset Help Uncatalyzed a, release of P Pa, E+S binding E+S a, uncatalyzed ES E+ P... Reset Help Uncatalyzed a, release of P Pa, E+S binding E+S a, uncatalyzed ES E+ P Enzyme EP Catalyzed a, catalysis Reaction coordinate... 1 answer ##### Please help and show work. right answers will get rated. 4) An educator believes that new... please help and show work. right answers will get rated. 4) An educator believes that new reading activities in the classroom will help elementary school pupils improve their reading ability. She arranges for a third grade class of 10 students to follow these activities for an 8-week period. A c... 1 answer ##### 2. A student is given an antacid tablet that weighed 5.6832 g. The tablet was crushed... 2. A student is given an antacid tablet that weighed 5.6832 g. The tablet was crushed and 4.3628 g of the antacid was added to 200 mL of simulated stomach acid. This was allowed to react and then filtered. It was found that 25.00 mL of this partially neutralized stomach acid required 8.50 mL of a Na... 1 answer ##### Exercise 15-18 Job order costing for services LO A1 Hansel Corporation has requested bids from several... Exercise 15-18 Job order costing for services LO A1 Hansel Corporation has requested bids from several architects to design its new corporate headquarters. Frey Architects is one of the firms bidding on the job. Frey estimates that the job will require the following direct labor. Labor Estimated ... 1 answer ##### Please help quickly，thanks a lot 1 Cyanogen azide can exist as three isomers: CNNNN NCNNN NNCNN. Draw valid Lewis dot... please help quickly，thanks a lot 1 Cyanogen azide can exist as three isomers: CNNNN NCNNN NNCNN. Draw valid Lewis dot structures for each isomer. Include formal charges and any important resonance structures. Additionally, use VSEPR to predict the geometry of the underlined atom. (b) Predic... 1 answer ##### Are the laboratory personnel complying with the safety signs, symbols, and labels? Explain why or why... Are the laboratory personnel complying with the safety signs, symbols, and labels? Explain why or why not based on your observations. AV. If risks are present, create a list of issues that need to be addressed. Describe what needs to be done for each risk. 20%... 1 answer ##### A new car costs$36000. The car's value will depreciate over time, which means it will...
A new car costs $36000. The car's value will depreciate over time, which means it will lose value. For tax purposes, depreciation is usually calculated linearly. (a) If the car is worth$28800 after 3 years, write an explicit formula for the value of the car after N years. Note: Webwork is case-...
1 answer
##### Four small aluminum spheres form the corners of a square whose side is 1.7 cm long....
Four small aluminum spheres form the corners of a square whose side is 1.7 cm long. A fifth iron sphere is in the center of the square. m1 = 450 g m2 = 110 g m3 = 250 g m4 = 450 g m5 = 560 g 1) What is total gravitational force on the fifth sphere in the y-direction? N 2) What is total gravitational...