Question: this is the code scaffold for virus.py: from _ _ future _ _ import annotations from abc import ABC, abstractmethod from computer import Computer from

this is the code scaffold for virus.py:
from __future__ import annotations
from abc import ABC, abstractmethod
from computer import Computer
from route import Route, RouteSeries
from branch_decision import BranchDecision
class VirusType(ABC):
def __init__(self)-> None:
self.computers =[]
def add_computer(self, computer: Computer)-> None:
self.computers.append(computer)
@abstractmethod
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
raise NotImplementedError()
class TopVirus(VirusType):
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
# Always select the top branch
return BranchDecision.TOP
class BottomVirus(VirusType):
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
# Always select the bottom branch
return BranchDecision.BOTTOM
class LazyVirus(VirusType):
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
"""
Try looking into the first computer on each branch,
take the path of the least difficulty.
"""
top_route = type(top_branch.store)== RouteSeries
bot_route = type(bottom_branch.store)== RouteSeries
if top_route and bot_route:
top_comp = top_branch.store.computer
bot_comp = bottom_branch.store.computer
if top_comp.hacking_difficulty bot_comp.hacking_difficulty:
return BranchDecision.TOP
elif top_comp.hacking_difficulty > bot_comp.hacking_difficulty:
return BranchDecision.BOTTOM
else:
return BranchDecision.STOP
# If one of them has a computer, don't take it.
# If neither do, then take the top branch.
if top_route:
return BranchDecision.BOTTOM
return BranchDecision.TOP
class RiskAverseVirus(VirusType):
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
"""
This virus is risk averse and likes to choose the path with the lowest risk factor.
"""
raise NotImplementedError()
class FancyVirus(VirusType):
CALC_STR ="73+8-2*2/"
def select_branch(self, top_branch: Route, bottom_branch: Route)-> BranchDecision:
"""
This virus has a fancy-pants and likes to overcomplicate its approach.
"""
raise NotImplementedError()
 this is the code scaffold for virus.py: from __future__ import annotations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!