53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import random
|
|
|
|
from src.sim.simulator import Simulator
|
|
from src.classes.avatar import Avatar, Gender
|
|
from src.classes.calendar import Month, Year, MonthStamp, create_month_stamp
|
|
from src.classes.world import World
|
|
from src.classes.map import Map
|
|
from src.classes.tile import TileType
|
|
from src.classes.action import Move
|
|
from src.classes.name import get_random_name
|
|
|
|
|
|
def test_simulator_step_moves_avatar_and_sets_tile():
|
|
# 固定随机种子,确保决定的移动是可预测的
|
|
random.seed(0)
|
|
|
|
# 构建 3x3 地图并填充地块
|
|
game_map = Map(width=3, height=3)
|
|
for x in range(3):
|
|
for y in range(3):
|
|
game_map.create_tile(x, y, TileType.PLAIN)
|
|
|
|
world = World(map=game_map, month_stamp=create_month_stamp(Year(1), Month.JANUARY))
|
|
|
|
# 将角色放在地图中心,避免越界
|
|
avatar = Avatar(
|
|
world=world,
|
|
name=get_random_name(Gender.MALE),
|
|
id="1",
|
|
birth_month_stamp=create_month_stamp(Year(2000), Month.JANUARY),
|
|
age=20,
|
|
gender=Gender.MALE,
|
|
pos_x=1,
|
|
pos_y=1,
|
|
)
|
|
|
|
|
|
sim = Simulator(world)
|
|
sim.avatars["1"] = avatar
|
|
|
|
# 执行一步模拟
|
|
sim.step()
|
|
|
|
# 断言位置在边界内
|
|
assert 0 <= avatar.pos_x < game_map.width
|
|
assert 0 <= avatar.pos_y < game_map.height
|
|
|
|
# 断言 tile 已正确设置且与位置一致
|
|
assert avatar.tile is not None
|
|
assert avatar.tile.x == avatar.pos_x
|
|
assert avatar.tile.y == avatar.pos_y
|
|
|