2021-02-28 04:16:32 -08:00
|
|
|
import zero_ad
|
|
|
|
|
from os import path
|
|
|
|
|
|
2024-08-22 00:18:20 -07:00
|
|
|
game = zero_ad.ZeroAD("http://localhost:6000")
|
2021-02-28 04:16:32 -08:00
|
|
|
scriptdir = path.dirname(path.realpath(__file__))
|
2024-08-22 00:18:20 -07:00
|
|
|
with open(path.join(scriptdir, "..", "samples", "arcadia.json"), "r") as f:
|
2021-02-28 04:16:32 -08:00
|
|
|
config = f.read()
|
|
|
|
|
|
2024-08-22 00:18:20 -07:00
|
|
|
with open(path.join(scriptdir, "fastactions.js"), "r") as f:
|
2021-02-28 04:16:32 -08:00
|
|
|
fastactions = f.read()
|
|
|
|
|
|
2024-08-22 00:18:20 -07:00
|
|
|
|
2021-02-28 04:16:32 -08:00
|
|
|
def test_return_object():
|
2024-08-22 00:18:20 -07:00
|
|
|
game.reset(config)
|
2021-02-28 04:16:32 -08:00
|
|
|
result = game.evaluate('({"hello": "world"})')
|
|
|
|
|
assert type(result) is dict
|
2024-08-22 00:18:20 -07:00
|
|
|
assert result["hello"] == "world"
|
|
|
|
|
|
2021-02-28 04:16:32 -08:00
|
|
|
|
|
|
|
|
def test_return_null():
|
2024-08-22 00:18:20 -07:00
|
|
|
result = game.evaluate("null")
|
|
|
|
|
assert result is None
|
|
|
|
|
|
2021-02-28 04:16:32 -08:00
|
|
|
|
|
|
|
|
def test_return_string():
|
2024-08-22 00:18:20 -07:00
|
|
|
game.reset(config)
|
2021-02-28 04:16:32 -08:00
|
|
|
result = game.evaluate('"cat"')
|
2024-08-22 00:18:20 -07:00
|
|
|
assert result == "cat"
|
|
|
|
|
|
2021-02-28 04:16:32 -08:00
|
|
|
|
|
|
|
|
def test_fastactions():
|
|
|
|
|
state = game.reset(config)
|
|
|
|
|
game.evaluate(fastactions)
|
2024-08-22 00:18:20 -07:00
|
|
|
female_citizens = state.units(owner=1, type="female_citizen")
|
|
|
|
|
house_tpl = "structures/spart/house"
|
|
|
|
|
len(state.units(owner=1, type=house_tpl))
|
2021-02-28 04:16:32 -08:00
|
|
|
x = 680
|
|
|
|
|
z = 640
|
|
|
|
|
build_house = zero_ad.actions.construct(female_citizens, house_tpl, x, z, autocontinue=True)
|
|
|
|
|
# Check that they start building the house
|
|
|
|
|
state = game.step([build_house])
|
2024-08-22 00:18:20 -07:00
|
|
|
|
|
|
|
|
def new_house(_=None):
|
|
|
|
|
return state.units(owner=1, type=house_tpl)[0]
|
|
|
|
|
|
2021-02-28 04:16:32 -08:00
|
|
|
initial_health = new_house().health(ratio=True)
|
|
|
|
|
while new_house().health(ratio=True) == initial_health:
|
|
|
|
|
state = game.step()
|
|
|
|
|
|
|
|
|
|
assert new_house().health(ratio=True) >= 1.0
|