def test_fox_should_die_from_hunger_after_5_rounds_without_being_fed(): fox_count = 1 world = World(1, 2, 0, fox_count, CoordGenerator()) for x in range(6): world.launch_round() assert world.territories[0].fox_count() == 0
def two_fox_simulation(): fox_count = 2 starting_position = [Coord(0, 0), Coord(0, 2)] world = World(1, 3, 0, fox_count, CoordGenerator(starting_position)) world.territories[0].foxes[0].feed() world.territories[2].foxes[0].feed() world.launch_round() return world
def test_two_rabbits_cant_breed_if_age_less_than_3(): rabbits_count = 2 starting_position = [Coord(0, 0), Coord(0, 2)] world = World(1, 3, rabbits_count, 0, CoordGenerator(starting_position)) world.launch_round() assert world.territories[1].new_child_rabbit() == 0
def test_one_fed_and_one_hungry_fox_should_breed_no_child(): fox_count = 2 starting_position = [Coord(0, 0), Coord(0, 2)] world = World(1, 3, 0, fox_count, CoordGenerator(starting_position)) world.territories[0].foxes[0].feed() world.launch_round() assert world.territories[1].fox_count() == 2
def test_multiple_rabbit_should_move_from_one_territory_to_another(): rabbit_count = 3 world = World(3, 3, rabbit_count, 0, CoordGenerator()) world.launch_round() assert rabbit_count_for(world, Coord(0, 0)) == 0 assert rabbit_count_for(world, Coord(2, 2)) == 0 assert rabbit_count_for(world, Coord(0, 1)) >= 1 or rabbit_count_for( world, Coord(1, 0)) >= 1 assert rabbit_count_for(world, Coord(1, 2)) == 1 or rabbit_count_for( world, Coord(2, 1)) == 1
def test_rabbit_should_wait_three_rounds_before_procreating_again(): rabbits_count = 2 starting_position = [Coord(0, 0), Coord(0, 0)] world = World(1, 2, rabbits_count, 0, CoordGenerator(starting_position)) for i in range(4): world.launch_round() assert world.territories[0].rabbit_count() == 3 world.launch_round() assert world.territories[1].rabbit_count() == 3 world.launch_round() world.launch_round() world.launch_round() assert world.territories[0].rabbit_count() == 4
def test_fox_should_be_hungry_if_not_feed_during_last_three_turn(): fox_count = 1 world = World(1, 2, 0, fox_count, CoordGenerator()) for x in range(4): world.launch_round() world.territories[0].foxes[0].feed() for x in range(4): world.launch_round() assert not world.territories[0].foxes[0].is_fed()
def test_fox_should_stay_alive_if_feed_during_the_last_five_turn(): fox_count = 1 world = World(1, 2, 0, fox_count, CoordGenerator()) for x in range(4): world.launch_round() world.territories[0].foxes[0].feed() for x in range(2): world.launch_round() assert world.territories[0].fox_count() == 1
def test_one_world_should_contain_a_dimensioned_grid_of_territory(): line = 10 column = 10 world = World(line, column, 0, 0, None) assert len(world.territories) == 100
def test_one_rabbit_start_at_a_random_position(): rabbit_count = 1 world = World(10, 10, rabbit_count, 0, CoordGenerator()) assert rabbit_count_for(world, Coord(0, 0)) == 1 assert rabbit_count_for(world, Coord(4, 4)) == 0
def test_one_fox_start_at_a_random_position(): fox_count = 1 world = World(10, 10, 0, fox_count, CoordGenerator()) assert fox_count_for(world, Coord(0, 0)) == 1 assert fox_count_for(world, Coord(3, 6)) == 0
import random from simulation.domain.Fox import Fox from simulation.domain.Rabbit import Rabbit from simulation.domain.World import World from simulation.game.CoordGenerator import CoordGenerator max_line = 5 max_column = 5 rabbit_count = 100 fox_count = 100 coord_generator = CoordGenerator(random=True, max_line=max_line, max_colum=max_column) world = World(max_line, max_column, rabbit_count, fox_count, coord_generator) print("World instancied with ") print("foxes : " + str(world.total_fox())) print("rabbit : " + str(world.total_rabbits())) print("press enter to start") input() while True: world.launch_round() print("foxes : " + str(world.total_fox())) print("rabbit : " + str(world.total_rabbits()))
def test_fox_should_move_from_one_territory_to_another(): fox_count = 1 world = World(1, 2, 0, fox_count, CoordGenerator()) world.launch_round() assert fox_count_for(world, Coord(0, 0)) == 0 assert fox_count_for(world, Coord(0, 1)) == 1