runner.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import time
  2. from agent import Agent
  3. from world import *
  4. # World Setup
  5. class SimParams():
  6. # instance used to hold simulation level parameters
  7. # params:
  8. # world_size: world is a grid, world_size^2
  9. # num_agents: number of agents in the sim
  10. # resources: raw items that are refined to make artifcats
  11. # round length: num turns in a single round
  12. def __init__(self, world_size, num_agents, resources, rounds_per_run,
  13. num_rounds_to_completion):
  14. self.world_size = world_size
  15. self.num_agents = num_agents
  16. self.resources = resources
  17. self.rounds_per_run = rounds_per_run
  18. self.num_rounds_to_completion = num_rounds_to_completion
  19. #Resources w/ Frequencies distributions
  20. # temp notes:
  21. # this list to be set up by modeller;
  22. # resources, below, are what's used in sim
  23. # resource frequencies will be variableized
  24. # resource density will be determined by:
  25. # set total avail, then randomly assign subsets of the resource
  26. # eg total = 0.4, a = rand(0, 0.4), total_rem = total - 0 - a.freg
  27. # repeat for all reso's, could say that if early ones take up entire range,
  28. # other ones get some super small value (0.01 or sth)
  29. def run_round(num_agents, world_size):
  30. resources = generate_resources()
  31. # Main line(s) to set up sim-wide params
  32. # TODO - move num_rounds_to_completion to somwhere else...
  33. sim_params = SimParams(\
  34. world_size=world_size,\
  35. num_agents=num_agents,\
  36. resources=resources,\
  37. rounds_per_run=800,\
  38. num_rounds_to_completion="inc")
  39. # Build world, using world.py keep track of resource counts
  40. world = World(sim_params)
  41. # Setup Agents
  42. setup_agents(sim_params, world)
  43. # End World Setup
  44. ################################################################################
  45. # Round Logic
  46. for round_num in range(sim_params.rounds_per_run):
  47. if sim_params.num_rounds_to_completion == "inc":
  48. for agent in world.agent_list:
  49. agent.act(world, round_num, sim_params)
  50. ("^^^^^^^^^^")
  51. # demo mode - comment out this line if running for data
  52. draw_world(sim_params, world, round_num)
  53. else:
  54. pass
  55. return sim_params.num_rounds_to_completion,\
  56. world.initial_raw_resource_count,\
  57. world.harvested_resource_count