Skip to content

Instantly share code, notes, and snippets.

@yashbonde
Last active February 5, 2019 07:09
Show Gist options
  • Save yashbonde/b84b140d7e93179b99019698c3103859 to your computer and use it in GitHub Desktop.
Save yashbonde/b84b140d7e93179b99019698c3103859 to your computer and use it in GitHub Desktop.
minimal file of freeciv-python
import pyfc
world = pyfc.World() # make world
world.new_game(username = 'lutanet', server_ip = '127.0.0.1', port = 5004) # server details
map_status, map_terrain, map_specials = world.start_game() # initialise and get maps
while world.is_running():
for unit in world.get_units(): # iterate over units
while unit.can_take_action(): # some units can take multiple actions
obs, action_mask = unit.observe() # action_mask tells which actions can be taken
# xxxx.sample() gives a sample action for that object
map_status, map_terrain, map_specials = world.take_action(unit, unit.sample())
for city in world.get_cities():
obs, action_mask = city.observe()
map_status, map_terrain, map_specials = world.take_action(city, city.sample())
obs, action_mask = world.Government.observe() # government
map_status, map_terrain, map_specials = world.step(gov, gov.sample())
obs, action_mask = world.Technology.observe() # tech tree
map_status, map_terrain, map_specials = world.step(tech, tech.sample())
obs, action_mask = world.Diplomacy.observe() # diplomacy
map_status, map_terrain, map_specials = world.step(dipl, dipl.sample())
for player in world.Opponents.get_player():
obs, action_mask = player.observe()
map_status, map_terrain, map_specials = world.step(player, player.sample())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment