-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest_demo03_smartrandom.py
52 lines (48 loc) · 1.23 KB
/
test_demo03_smartrandom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from demo03_smartrandom import move
from pelita.utils import setup_test_game
def test_legalmoves():
# check that the only two valid moves are always returned
# we try ten times, to test 10 different random streams
layout="""
########
#a######
#b. .xy#
########
"""
for i in range(10):
bot = setup_test_game(layout=layout, is_blue=True)
next_pos = move(bot, {})
assert next_pos in ((1,2), (1,1))
def test_kill_enemy():
# check that we indeed kill an enemy when possible
layout="""
########
#x###.##
#a. by#
########
"""
bot = setup_test_game(layout=layout, is_blue=True)
next_pos = move(bot, {})
assert next_pos == (1,1)
def test_eat_food():
# check that we indeed collect food when possible
layout="""
########
#y # .##
#b.x a #
########
"""
bot = setup_test_game(layout=layout, is_blue=True)
next_pos = move(bot, {})
assert next_pos == (5,1)
def test_no_kamikaze_stop():
# Check that we stop if escaping would kill us
layout="""
########
# ###.#
#b. xay#
########
"""
bot = setup_test_game(layout=layout, is_blue=True)
next_pos = move(bot, {})
assert next_pos == (5, 2)