コード例 #1
0
def init():
    global aquarium
    cfg = dict()
    with open(fpath + '/pi_service_cfg.json') as cfgfile:
        cfg = json.load(cfgfile)

    if cfg['aquarium']:
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        aquarium = Aquarium()
コード例 #2
0
def main():
    aquarium = Aquarium()
    fish = Tang("Bubble", 3, "grey", False)
    fish2 = Clownfish("Nemo", 4, "red", "blue")
    fish3 = Kong("Sirilla", 5, "azure")
    fish4 = Kong("Moby", 11, "green")

    fish.feed()
    fish2.feed()
    fish3.feed()

    fish.status()
    fish2.status()
    fish3.status()
    fish4.status()

    aquarium.add_fish(fish)
    aquarium.add_fish(fish2)
    aquarium.add_fish(fish3)
    aquarium.feed()
    aquarium.remove_fish()
    aquarium.get_status()
コード例 #3
0
def main():

    dory = Tang("tang", "doreeee", 6, "blue")
    dory.feed("tang")
    dory.status()

    nemo = Kong("kong", "nemo", 3, "red")
    nemo.status()
    nemo.feed("kong")
    nemo.feed("kong")
    nemo.status()

    clown = Clownfish("clownfish", "joker", 4, "purple")
    clown.status()
    clown.feed("clownfish")
    clown.status()

    aquarium = Aquarium("Underworld")
    aquarium.addFish(dory)
    aquarium.addFish(nemo)
    aquarium.addFish(clown)
    aquarium.get_status()
    aquarium.feed(20)
    dory.status()
    clown.status()
    nemo.status()
    aquarium.feed(10)
    dory.status()
    clown.status()
    nemo.status()
    aquarium.removeFish()
    aquarium.get_status()
コード例 #4
0
COUNT_ALL_DWELLERS = 100
COUNT_PREDATORS = 2
COUNT_COCHLEA = 3
COUNT_PLANT = 55
COUNT_REGULAR = 40


class SampleError(Exception):
    def __init__(self, arg):
        # Set some exception infomation
        self.msg = arg


if __name__ == '__main__':
    # создали аквариум, просто один - лучший синглтон
    myAqua = Aquarium()
    try:
        # запустили хищников
        predator_01 = dweller.PredatoryFish(10, 'Anton')
        myAqua.dwellers.append(predator_01)
        predator_02 = dweller.PredatoryFish(10, 'Sam')
        myAqua.dwellers.append(predator_02)
        # запустили обычную рыбу
        for regular in range(COUNT_REGULAR):
            myAqua.dwellers.append(
                dweller.RegularFish(
                    randint(dweller.RegularFish.MIN_WEIGHT,
                            dweller.RegularFish.MAX_WEIGHT)))
        # запустили улиток
        for regular in range(COUNT_COCHLEA):
            myAqua.dwellers.append(
コード例 #5
0
        while len(self.aquarium.occupants) > (count_snails + count_predators):
            occupant1 = choice(self.aquarium.occupants)
            occupant2 = choice(self.aquarium.occupants)

            try:
                occupant1.eat(occupant2)
                index = self.aquarium.occupants.index(occupant2)
                del self.aquarium.occupants[index]
            except FoodError as e:
                print(e.message)

        print(" =RESULT= ")
        self.print_result(self.filter.get_snails())
        self.print_result(self.filter.get_predators())

    @staticmethod
    def print_result(occupants):
        occupants = sorted(occupants, key=lambda occupant: occupant.weight, reverse=True)

        for occupant in occupants:
            print(occupant.__class__.__name__ + " \"" + occupant.name + "\", weight: " + str(occupant.weight) + ", victims: " + str(occupant.victims))

if __name__ == '__main__':
    aquarium = Aquarium()

    print(BColors.BOLD, "Occupants in aquarium:", len(aquarium.occupants), BColors.ENDC)

    app = Application(aquarium)
    app.play()
コード例 #6
0
import sys
import os
import os.path
from aquarium import Aquarium
import time
if __name__ == "__main__":
  tiempo_inicial = time.time()

  if len(sys.argv) != 3:
    print(f"Modo de uso: python3.6+ {sys.argv[0]} input_file output_file")
    print("Donde")
    print("\tinput_file es un archivo del test a resolver")
    print("\toutput_file es el archivo donde el programa guardará el output")
    sys.exit(1)

  # El primer parámetro es el archivo de input
  input_file = sys.argv[1]

  # El segundo parámetro es el archivo de output
  output_file = sys.argv[2]

       
  path = os.path.join(os.getcwd(), output_file)
 
  directory = os.path.dirname(path)
  if not os.path.exists(directory):
    os.makedirs(directory)
  aquarium = Aquarium(path, input_file)
  aquarium.is_solvable()
  print(f"Tiempo de ejecución: {time.time()-tiempo_inicial}")
コード例 #7
0
from aquarium import Aquarium
from clownfish import Clownfish
from tang import Tang
from kong import Kong

aquarium = Aquarium()

# checking what happens with empty aquarium
aquarium.get_status()
aquarium.feed()
aquarium.remove_fat_fishes()

# creating fishes
clownfish_1 = Clownfish("Laughy", 9, "orange", "white")
clownfish_2 = Clownfish("Funny", 10, "yellow", "pink")
tong_1 = Tang("Dumby", 7, "blue")
kong_1 = Kong("Fatty", 18, "grey")

# adding fishes to the aquarium
aquarium.add_fish(clownfish_1)
aquarium.add_fish(clownfish_2)
aquarium.add_fish(tong_1)
aquarium.add_fish(kong_1)

# testing


def test_feeding():
    print("# feeding the aquarium:")
    aquarium.feed()
    print_status()
from fish import Fish
from aquarium import Aquarium

Clown_fish = Fish("Bob", 12, "Blue", False)
Tang = Fish("Buddy", 13, "Orange", True)
Kong = Fish("Patrick", 14, "Red", False)

aquarium1 = Aquarium()
aquarium1.add_fish([Clown_fish])
aquarium1.add_fish([Tang])
aquarium1.add_fish([Kong])

aquarium2 = Aquarium()
aquarium2.add_fish([Clown_fish, Kong])

print(aquarium1.getstatus())
print(aquarium2.getstatus())

for i in range(len(aquarium1.list_of_fish)):
    print(aquarium1.list_of_fish[i].status())

for i in range(len(aquarium2.list_of_fish)):
    print(aquarium2.list_of_fish[i].status())
コード例 #9
0
from fish import Fish
from fish import Tang
from fish import Kong
from fish import Clownfish
from aquarium import Aquarium

a = Tang("Annácska", 3, "pink", True)
b = Kong("Benike", 9, "red")
c = Clownfish("Ceci", 2, "blue", "yellow")
d = Kong("Dögike", 12, "white")
e = Tang("Viktor", 6, "orange", False)
a.status()
a.feed()
a.status()

q = Aquarium()
q.add_fish(a)
q.add_fish(b)
q.add_fish(c)
q.add_fish(d)
q.add_fish(e)

q.get_status()
q.feed()
q.get_status()
q.remove_fish()
q.get_status()