Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions