Commit 6f9cffb9 authored by drallensmith's avatar drallensmith

May have figured out doing travis tests with two languages

parent 869f1719
...@@ -14,6 +14,7 @@ install: ...@@ -14,6 +14,7 @@ install:
brew install cartr/qt4/qt brew install cartr/qt4/qt
; ;
fi fi
- sudo pip install nose numpy
os: os:
- linux - linux
- osx - osx
...@@ -23,3 +24,4 @@ compiler: ...@@ -23,3 +24,4 @@ compiler:
script: script:
- mkdir build && cd build - mkdir build && cd build
- cmake -DCMAKE_BUILD_TYPE=RelwithDebInfo .. && make -j4 && make install - cmake -DCMAKE_BUILD_TYPE=RelwithDebInfo .. && make -j4 && make install
- cd .. && nosetests --exe
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
import hfo import hfo
hfo_env = hfo.HFOEnvironment() def test_basic():
hfo_env = hfo.HFOEnvironment()
for action in range(hfo.NUM_HFO_ACTIONS): for action in range(hfo.NUM_HFO_ACTIONS):
assert len(hfo_env.actionToString(action)) assert len(hfo_env.actionToString(action))
for state in range(hfo.NUM_GAME_STATUS_STATES): for state in range(hfo.NUM_GAME_STATUS_STATES):
assert len(hfo_env.statusToString(state)) assert len(hfo_env.statusToString(state))
if __name__ == '__main__':
test_basic()
...@@ -8,105 +8,109 @@ import time ...@@ -8,105 +8,109 @@ import time
import hfo import hfo
test_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
binary_dir = os.path.normpath(test_dir + "/../bin")
conf_dir = os.path.join(binary_dir, 'teams/base/config/formations-dt')
bin_HFO = os.path.join(binary_dir, "HFO")
popen_list = [sys.executable, "-x", bin_HFO,
"--offense-agents=1", "--defense-npcs=2",
"--offense-npcs=2", "--trials=1", "--headless"]
HFO_process = subprocess.Popen(popen_list)
hfo_env = hfo.HFOEnvironment() hfo_env = hfo.HFOEnvironment()
time.sleep(0.2)
assert (HFO_process.poll() is
None), "Failed to start HFO with command '{}'".format(" ".join(popen_list))
time.sleep(3)
def try_step(): # if a game ends within ~20 frames, something is wrong... def try_step(): # if a game ends within ~20 frames, something is wrong...
status = hfo_env.step() status = hfo_env.step()
assert (status == assert (status ==
hfo.IN_GAME), ("Status is {!s} ({!r}), not IN_GAME". hfo.IN_GAME), ("Status is {!s} ({!r}), not IN_GAME".
format(hfo_env.statusToString(status),status)) format(hfo_env.statusToString(status),status))
return hfo_env.getState() return hfo_env.getState()
try: def test_with_server():
hfo_env.connectToServer(config_dir=conf_dir) # using defaults otherwise test_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
binary_dir = os.path.normpath(test_dir + "/../bin")
conf_dir = os.path.join(binary_dir, 'teams/base/config/formations-dt')
bin_HFO = os.path.join(binary_dir, "HFO")
popen_list = [sys.executable, "-x", bin_HFO,
"--offense-agents=1", "--defense-npcs=2",
"--offense-npcs=2", "--trials=1", "--headless"]
HFO_process = subprocess.Popen(popen_list)
time.sleep(0.2)
assert (HFO_process.poll() is
None), "Failed to start HFO with command '{}'".format(" ".join(popen_list))
time.sleep(3)
try:
hfo_env.connectToServer(config_dir=conf_dir) # using defaults otherwise
min_state_size = 58+(9*4) min_state_size = 58+(9*4)
state_size = hfo_env.getStateSize() state_size = hfo_env.getStateSize()
assert (state_size >= assert (state_size >=
min_state_size), "State size is {!s}, not {!s}+".format(state_size,min_state_size) min_state_size), "State size is {!s}, not {!s}+".format(state_size,min_state_size)
print("State size is {!s}".format(state_size)) print("State size is {!s}".format(state_size))
my_unum = hfo_env.getUnum() my_unum = hfo_env.getUnum()
assert ((my_unum > 0) and (my_unum <= 11)), "Wrong self uniform number ({!r})".format(my_unum) assert ((my_unum > 0) and (my_unum <= 11)), "Wrong self uniform number ({!r})".format(my_unum)
print("My unum is {!s}".format(my_unum)) print("My unum is {!s}".format(my_unum))
had_ok_unum = False had_ok_unum = False
had_ok_unum_set_my_side = set() had_ok_unum_set_my_side = set()
had_ok_unum_set_their_side = set(); had_ok_unum_set_their_side = set();
hfo_env.act(hfo.NOOP) hfo_env.act(hfo.NOOP)
state = try_step() state = try_step()
for x in range(0,20): for x in range(0,20):
if int(state[12]) == 1: # can kick the ball if int(state[12]) == 1: # can kick the ball
hfo_env.act(hfo.DRIBBLE) hfo_env.act(hfo.DRIBBLE)
elif (x % 2) != 0: elif (x % 2) != 0:
hfo_env.act(hfo.MOVE) hfo_env.act(hfo.MOVE)
elif int(state[50]) == 1: # can see the ball elif int(state[50]) == 1: # can see the ball
hfo_env.act(hfo.GO_TO_BALL) hfo_env.act(hfo.GO_TO_BALL)
else: else:
hfo_env.act(hfo.MOVE) hfo_env.act(hfo.MOVE)
state = try_step() state = try_step()
for n in range((state_size-4), state_size): for n in range((state_size-4), state_size):
their_unum = state[n] their_unum = state[n]
if ((their_unum > 0) and (their_unum <= 0.11)): if ((their_unum > 0) and (their_unum <= 0.11)):
print("{!s}: OK uniform number ({!r}) for {!s}".format(x,their_unum,n)) print("{!s}: OK uniform number ({!r}) for {!s}".format(x,their_unum,n))
had_ok_unum = True had_ok_unum = True
if n > (state_size-3): if n > (state_size-3):
had_ok_unum_set_their_side.add(their_unum) had_ok_unum_set_their_side.add(their_unum)
else: else:
had_ok_unum_set_my_side.add(their_unum) had_ok_unum_set_my_side.add(their_unum)
elif x > 3: elif x > 3:
print("{!s}: Wrong other uniform number ({!r}) for {!s}".format(x,their_unum,n)) print("{!s}: Wrong other uniform number ({!r}) for {!s}".format(x,their_unum,n))
if (len(had_ok_unum_set_my_side) > 1) and (len(had_ok_unum_set_their_side) > 1): if (len(had_ok_unum_set_my_side) > 1) and (len(had_ok_unum_set_their_side) > 1):
break break
assert had_ok_unum, "Never saw OK other uniform number" assert had_ok_unum, "Never saw OK other uniform number"
try: try:
hfo_env.act(hfo.MOVE_TO) hfo_env.act(hfo.MOVE_TO)
except AssertionError: except AssertionError:
pass pass
else: else:
raise AssertionError("Should have got AssertionError") raise AssertionError("Should have got AssertionError")
HFO_process.terminate() HFO_process.terminate()
hfo_env.act(hfo.QUIT) hfo_env.act(hfo.QUIT)
time.sleep(1.2) time.sleep(1.2)
status = hfo_env.step() status = hfo_env.step()
assert (status == assert (status ==
hfo.SERVER_DOWN), ("Status is {!s} ({!r}), not SERVER_DOWN". hfo.SERVER_DOWN), ("Status is {!s} ({!r}), not SERVER_DOWN".
format(hfo_env.statusToString(status), status)) format(hfo_env.statusToString(status), status))
finally: finally:
if HFO_process.poll() is None: if HFO_process.poll() is None:
HFO_process.terminate() HFO_process.terminate()
os.system("killall -9 rcssserver") os.system("killall -9 rcssserver")
if __name__ == '__main__':
test_with_server()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment