def test_upgrade_research(): game_state = initialise_gamestate() game = Game(game_state) game.update(24 * 3600) earth = PlanetLocation(1, 1, 3) upgrade_success = game.action_upgrade_research("max", earth, "energy") assert not upgrade_success upgrade_success = game.action_upgrade_building("max", earth, "research_lab") assert upgrade_success upgrade_success = game.action_upgrade_research("max", earth, "laser") assert not upgrade_success upgrade_success = game.action_upgrade_research("max", earth, "energy") assert upgrade_success upgrade_success = game.action_upgrade_research("max", earth, "laser") assert not upgrade_success upgrade_success = game.action_upgrade_building("max", earth, "research_lab") upgrade_sucess = game.action_upgrade_research("max", earth, "energy") upgrade_sucess = game.action_upgrade_research("max", earth, "laser") assert upgrade_success
def test_build_ship(): game_state = initialise_gamestate() game = Game(game_state) game_state.world.speed = 1000000 earth = PlanetLocation(1, 1, 3) outcome = game.action_build_ship("max", earth, "light_fighter") assert not outcome.success game.update(24 * 3600) success = game.action_upgrade_building("max", earth, "shipyard") assert success outcome = game.action_build_ship("max", earth, "light_fighter") assert not outcome.success assert game.action_upgrade_building("max", earth, "research_lab") assert game.action_upgrade_research("max", earth, "energy") assert game.action_upgrade_research("max", earth, "combustion_drive") outcome = game.action_build_ship("max", earth, "light_fighter") assert outcome.success assert len(game_state.players["max"].fleets) == 1 assert ( game_state.players["max"] .fleets[0] .light_fighter.components[ShipComponent] .number == 1 )
def test_upgrade_building(): game_state = initialise_gamestate() game = Game(game_state) upgrade_success = game.action_upgrade_building( "max", PlanetLocation(1, 1, 3), "metal_mine" ) assert not upgrade_success game.update(3600) upgrade_success = game.action_upgrade_building( "max", PlanetLocation(1, 1, 3), "metal_mine" ) planet_component = game_state.world.planets[PlanetLocation(1, 1, 3)].components[ PlanetComponent ] assert upgrade_success assert planet_component.resources[Resources.Metal] < 30 * game_state.world.speed assert ( int(planet_component.resources[Resources.Cristal]) < 20 * game_state.world.speed ) with pytest.raises(AssertionError) as excinfo: game.action_upgrade_building("max", "ploup", "metal_mine") assert "unkwnown planet" in str(excinfo.value).lower() with pytest.raises(AssertionError) as excinfo: game.action_upgrade_building("ploup", PlanetLocation(1, 1, 3), "metal_mine") assert "unknown player" in str(excinfo.value).lower()
def test_colonize_planet(): game_state = init_state_complex() game = Game(game_state) earth = PlanetLocation(1, 1, 3) game.update(100) game.action_upgrade_building("max", earth, "shipyard") game.update(100) game.action_build_ship("max", earth, "colony_ship") game.action_send_mission( "max", earth, "COLONIZE", PlanetLocation(1, 1, 6), cargo={Resources.Metal: 5} ) game.update(25) game.update(25) assert len(game_state.world.planets) == 4 new_planet = game_state.world.planets[PlanetLocation(1, 1, 6)] new_planet_comp = new_planet.components[PlanetComponent] assert new_planet.buildings["metal_mine"].components[BuildingComponent].level == 0