Пример #1
0
def test_time_to_value():
    f = farm.Farm()
    with pytest.raises(ValueError) as excinfo:
        f.time_to_max_chickens()
    assert 'max capacity required' in str(excinfo.value)

    f = farm.Farm(max_capacity=250)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_value(100)
    assert 'farm value required' in str(excinfo.value)

    f = farm.Farm(max_capacity=250, farm_value=1)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_value(100)
    assert 'farm population required' in str(excinfo.value)

    f = farm.Farm(max_capacity=250, farm_value=1, farm_population=1)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_value(100)
    assert 'int hatchery rate required' in str(excinfo.value)

    # verify that no exceptions happen
    f = farm.Farm(max_capacity=250,
                  farm_value=1,
                  farm_population=1,
                  int_hatchery_rate=1)
    f.time_to_value(100)
Пример #2
0
def test_time_to_eggs():
    f = farm.Farm()
    with pytest.raises(ValueError) as excinfo:
        f.time_to_eggs(100)
    assert 'eggs required' in str(excinfo.value)

    f = farm.Farm(eggs=0)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_eggs(100)
    assert 'farm population required' in str(excinfo.value)

    f = farm.Farm(eggs=0, farm_population=1)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_eggs(100)
    assert 'egg laying rate required' in str(excinfo.value)

    f = farm.Farm(eggs=0, farm_population=1, egg_laying_rate=1)
    with pytest.raises(ValueError) as excinfo:
        f.time_to_eggs(100)
    assert 'int hatchery rate required' in str(excinfo.value)

    # verify that no exceptions happen
    f = farm.Farm(eggs=0,
                  farm_population=1,
                  egg_laying_rate=1,
                  int_hatchery_rate=1)
    f.time_to_eggs(100)
Пример #3
0
def test_time_to_max_chickens():
    f = farm.Farm()
    with pytest.raises(ValueError) as excinfo:
        f.time_to_max_chickens()
    assert 'max capacity required' in str(excinfo.value)

    # Other possible exceptions are covered by test_time_to_chickens()

    # verify that no exceptions happen
    f = farm.Farm(farm_population=1, int_hatchery_rate=1, max_capacity=250)
    f.time_to_max_chickens()
Пример #4
0
async def create(ctx, *args):
    name = " ".join(args).strip()
    if name == "":
        await client.say("You can't create a farm with no name!")
        return

    play.players[ctx.message.author] = play.Player(ctx.message.author)

    answer = await ask.ask(
        ctx.message,
        f"Are you sure you wish to start a new farm called `{name}`?")
    if answer:
        play.players[ctx.message.author].farm = farm.Farm(name)
        await client.say("Farm created!")
Пример #5
0
def main(animals):
    animal_farm = farm.Farm()
    for animal_kind in animals:
        animal_farm.add_animal(create_animal(animal_kind))
    animal_farm.print_contents()
Пример #6
0
def main(animals):
    """main"""
    animal_farm = farm.Farm()
    for animal_kind in animals:
        animal_farm.add_animal(make_animal(animal_kind))
    animal_farm.print_contents()
Пример #7
0
egg_goal_2 = '500T'
egg_goal_3 = '4.0q'

# farm details
eggs = '437T'
farm_population = 337283248
egg_laying_rate = '338.919B'
int_hatchery_rate = 5840

egg_goals = [
    farm.parse_value(g) for g in (egg_goal_1, egg_goal_2, egg_goal_3)
    if g is not None
]

myfarm = farm.Farm(eggs=eggs,
                   farm_population=farm_population,
                   egg_laying_rate=egg_laying_rate,
                   int_hatchery_rate=int_hatchery_rate)
ttc = farm.parse_time(time_to_complete)
bestfarm = myfarm.future(ttc)

best_reported = False
for n, egg_goal in enumerate(egg_goals):
    if egg_goal is None:
        break

    goal = farm.parse_value(egg_goal)
    t = myfarm.time_to_eggs(goal)
    if t > ttc:
        if not best_reported:
            print('contract complete in', time_to_complete)
            bestfarm.report()
Пример #8
0
    capacity = total * 0.75

    num_occupied = total - farmyard.num_available()

    if num_occupied + quantity <= capacity:
        return True
    else:
        return False


# If run as a script, run the unit tests for this module.
# otherwise, don't
if __name__ == "__main__":
    printer.start()

    farmyard = farm.Farm(INIT_BOARD_SIZE)

    # Set up the page refresh metronome
    draw_thread = threading.Thread(target=draw_board, args=(farmyard, ))
    draw_thread.daemon = True
    draw_thread.start()

    # Make the Animals
    animals = [
        (a, threading.Thread(target=a.run)) for a in
        [Animal.make_random_animal(farmyard) for _ in range(NUM_ANIMALS)]
    ]
    for (a, t) in animals:
        t.daemon = True
    map(lambda (_, t): t.start(), animals)
Пример #9
0
#! /usr/bin/python3.7
import flask
import requests
import argparse
import farm

app = flask.Flask("farm")
app.farm = farm.Farm()


@app.route('/', methods=['GET'])
def show_page():
    return flask.render_template_string(
        """
        <html>
        <body>
        <h1>You farm:</h1>

        - Tomatoes: {{ tomato["adults"] }} adults, {{ tomato["kids"] }} kids <br>
        - Cucumbers: {{ cucumber["adults"] }} adults, {{ cucumber["kids"] }} kids <br>

        Money: {{ money }}

        <form method="post" action="/grow_form?type=tomato">
            <button type="submit">Посадить помидорчик</button>
        </form>
        
        <form method="post" action="/grow_form?type=cucumber">
            <button type="submit">Посадить огурчик</button>
        </form>
Пример #10
0
farm_value = '75.978sd'

# units: chickens
farm_population = 82435477

# units: eggs / minute
egg_laying_rate = '140.820B'

# units: chickens / minute / hab
int_hatchery_rate = 6440

### Values at completion time
print('Stats at completion time')
myfarm = farm.Farm(eggs=eggs,
                   max_capacity=hab_max_capacity,
                   farm_value=farm_value,
                   farm_population=farm_population,
                   egg_laying_rate=egg_laying_rate,
                   int_hatchery_rate=int_hatchery_rate)
new_farm = myfarm.future(time_to_complete)
new_farm.report()
print()

### Values at egg target
print('Stats at egg target')

# units: eggs
e_final = farm.parse_value(target_eggs)
t = myfarm.time_to_eggs(e_final)
print('target reached in', farm.format_time(t))

new_farm2 = myfarm.future(t)
Пример #11
0
from __future__ import print_function

import farm

# upgrade requirement
target_farm_value = '6.7Sd'

# farm details
hab_max_capacity = 1461600000
farm_value = '75.978sd'
farm_population = 82435477
int_hatchery_rate = 6440

myfarm = farm.Farm(max_capacity=hab_max_capacity, farm_value=farm_value,
                   farm_population=farm_population,
                   int_hatchery_rate=int_hatchery_rate)
t = myfarm.time_to_value(target_farm_value)
goalfarm = myfarm.future(t)

if goalfarm.farm_population > hab_max_capacity:
    t = myfarm.time_to_max_chickens()
    fullfarm = myfarm.future(t)
    print('full farm reached in', farm.format_time(t))
    fullfarm.report()
    print()

print('target reached in', farm.format_time(t))
goalfarm.report()
print()

Пример #12
0
from __future__ import print_function

import farm

# trophy requirement
target_chickens = '1.0B'

# farm details
farm_population = 82435477
int_hatchery_rate = 6440

myfarm = farm.Farm(farm_population=farm_population,
                   int_hatchery_rate=int_hatchery_rate)
t = myfarm.time_to_chickens(target_chickens)
print('target reached in', farm.format_time(t))

goalfarm = myfarm.future(t)
goalfarm.report()
print()

Пример #13
0
def main(animals):
    animal_farm = farm.Farm()
    for animal_kind in animals:
        animal_farm.add_animal(make_animal(animal_kind))
    animal_farm.print_contents()
    animal_farm.act('a farmer')