Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pelita/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,20 @@

#: Default maze sizes
MSIZE = {
'small' : (16, 8),
'tiny': (16, 8),
'small': (24, 12),
'normal': (32, 16),
'big' : (64, 32),
'big': (48, 24),
'huge': (64, 32),
}

#: Food pellets (trapped_food, total_food) on left side of the maze for
# default maze sizes
NFOOD = {
(16, 8) : (3, 10),
(16, 8): (3, 10),
(24, 12): (5, 15),
(32, 16): (10, 30),
(48, 24): (15, 50),
(64, 32): (20, 60),
}

Expand Down
9 changes: 6 additions & 3 deletions pelita/scripts/pelita_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ def w_h_string(s):
if s in pelita.game.MSIZE:
return pelita.game.MSIZE[s]
try:
x_string, y_string = s.split('x')
w_h = (int(x_string), int(y_string))
if 'x' in s:
x_string, y_string = s.split('x')
w_h = (int(x_string), int(y_string))
else:
w_h = (int(s) * 2, int(s))
except ValueError:
msg = "%s is not a valid specification" %s
raise argparse.ArgumentTypeError(msg) from None
Expand Down Expand Up @@ -240,7 +243,7 @@ def long_help(s):
layout_opt.add_argument('--layout', metavar='FILENAME', help='Use layout from FILENAME')
layout_opt.add_argument('--size', type=w_h_string, metavar="STRING", default='normal',
help="Pick a random maze layout of specified size."
" Possible sizes: 'small' (16x8), 'normal' (32x16), 'big' (64x32), 'WxH' where W and H are integers. Default: 'normal'")
" Possible sizes: 'small' (24x12), 'normal' (32x16), 'big' (48x24), 'WxH' where W and H are integers. Default: 'normal'")

timeout_opt = game_settings.add_mutually_exclusive_group()
timeout_opt.add_argument('--timeout', type=float, metavar="SEC",
Expand Down
19 changes: 19 additions & 0 deletions test/test_layout.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import argparse
import itertools
from textwrap import dedent

import pytest

from pelita.scripts.pelita_main import w_h_string
from pelita.layout import (BOT_N2I, get_legal_positions, layout_as_str,
parse_layout, wall_dimensions)

Expand Down Expand Up @@ -437,3 +439,20 @@ def test_parse_layout_game_bad_number_of_bots(bots_hidden):
else:
with pytest.raises(ValueError):
parse_layout(test_layout)


@pytest.mark.parametrize('spec, check', [
("0x0", (0, 0)),
("1", (2, 1)),
("32x16", (32, 16)),
("16", (32, 16)),
("normal", (32, 16)),
("abc", None),
("abxc", None)
])
def test_layout_spec(spec, check):
if check is None:
with pytest.raises(argparse.ArgumentTypeError):
assert w_h_string(spec)
else:
assert w_h_string(spec) == check
16 changes: 8 additions & 8 deletions test/test_libpelita.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_firstNN():
def test_call_pelita():
rounds = 200
viewer = 'ascii'
size = 'small'
size = 'tiny'

teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"]
(state, stdout, stderr) = call_pelita(teams, rounds=rounds, viewer='null', size=size, seed=None)
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_call_pelita():
def test_bad_seeds(seed, success):
rounds = 2
viewer = 'null'
size = 'small'
size = 'tiny'

teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"]
if success:
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_write_replay_is_idempotent():

cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--write-replay', f.name,
'--size', 'small',
'--size', 'tiny',
'--null']

subprocess.run(cmd, check=True)
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_store_layout():

cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--store-layout', f.name,
'--size', 'small',
'--size', 'tiny',
'--seed', '12345',
'--null']

Expand All @@ -141,7 +141,7 @@ def test_store_layout():
with tempfile.NamedTemporaryFile() as g:
cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--store-layout', g.name,
'--size', 'small',
'--size', 'tiny',
'--seed', '12345',
'--null']

Expand All @@ -161,7 +161,7 @@ def test_random_layout_seed_is_random():

cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--store-layout', '-',
'--size', 'small',
'--size', 'tiny',
'--null']

res = subprocess.run(cmd, check=True, text=True, stdout=subprocess.PIPE)
Expand All @@ -187,7 +187,7 @@ def test_random_layout_seed_is_stable():

cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--store-layout', '-',
'--size', 'small',
'--size', 'tiny',
'--null']

res = subprocess.run(cmd, check=True, text=True, stdout=subprocess.PIPE)
Expand All @@ -201,7 +201,7 @@ def test_random_layout_seed_is_stable():
# Check that the same seed generates the same layout
cmd = [sys.executable, '-m', 'pelita.scripts.pelita_main',
'--store-layout', '-',
'--size', 'small',
'--size', 'tiny',
'--seed', seed,
'--null']

Expand Down
2 changes: 1 addition & 1 deletion test/test_remote_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def dummy_layout_dict(dummy_layout):


def test_remote_call_pelita(remote_teams):
res, stdout, stderr = call_pelita(remote_teams, rounds=10, size='small', viewer='null', seed='2')
res, stdout, stderr = call_pelita(remote_teams, rounds=10, size='tiny', viewer='null', seed='2')
assert res['whowins'] == 1
assert res['fatal_errors'] == [[], []]
# errors for call_pelita only contains the last thrown error, hence None
Expand Down
8 changes: 4 additions & 4 deletions test/test_tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_play_game_with_config(self):
config.team_spec = lambda x: x
config.team_group = lambda x: x
config.viewer = 'ascii'
config.size = 'small'
config.size = 'tiny'
config.tournament_log_folder = None

teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"]
Expand Down Expand Up @@ -335,7 +335,7 @@ def mock_print(str="", *args, **kwargs):
config.team_name = lambda x: teams[x]
config.team_group = lambda x: x
config.viewer = 'ascii'
config.size = 'small'
config.size = 'tiny'
config.print = mock_print
config.tournament_log_folder = None

Expand Down Expand Up @@ -373,7 +373,7 @@ def mock_print(str="", *args, **kwargs):
config.team_name = lambda x: teams[x]
config.team_group = lambda x: x
config.viewer = 'ascii'
config.size = 'small'
config.size = 'tiny'
config.print = mock_print
config.tournament_log_folder = None

Expand Down Expand Up @@ -410,7 +410,7 @@ def mock_print(str="", *args, **kwargs):
{"id": "group3", "spec": "pelita/player/StoppingPlayer", "members": []},
{"id": "group4", "spec": "pelita/player/StoppingPlayer", "members": []},
],
"size": "small",
"size": "tiny",
}
config = tournament.Config(c)
config.print = mock_print
Expand Down
Loading