SeAIPalette/Palette/examples/pure_boustrophedon.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-05-30 21:36:26 +08:00
from argparse import ArgumentParser
from Palette.env import make, SeaEnv
from Palette.constants import UP, DOWN, LEFT, RIGHT, FINISHED, BROKEN
from Palette.algos import Boustrophedon
def main(env: SeaEnv, agent: Boustrophedon):
state, info = env.reset()
while True:
act = agent.step(state, info)
if act == FINISHED:
print(f'Congrates! Covered all the places!')
break
elif act == BROKEN:
print(f'Broken!')
break
state, terminate, info = env.step(act)
if terminate:
print(f'Terminate!')
break
def get_args():
parser = ArgumentParser()
parser.add_argument('-c', "--config_name", type=str, required=True,
help="The name of config file, e.g., map0")
parser.add_argument('--render', action='store_true',
help='render or not')
return parser.parse_args()
if __name__ == '__main__':
args = get_args()
sea_env = make(env_config=args.config_name, render=args.render)
algo = Boustrophedon()
main(sea_env, algo)