예제 #1
0
def test_game_window():
    game_conf = GameConf()
    game_conf.map_rows = 15
    game_conf.map_cols = game_conf.map_rows
    game_conf.show_grid_line = True
    game_conf.show_info_panel = False

    game_map = Map(game_conf.map_rows + 2, game_conf.map_cols + 2)
    contents = (
        # Walls
        (Pos(1, 6), PointType.WALL),
        (Pos(1, 7), PointType.WALL),
        (Pos(1, 8), PointType.WALL),
        (Pos(1, 9), PointType.WALL),
        (Pos(1, 10), PointType.WALL),
        (Pos(15, 6), PointType.WALL),
        (Pos(15, 7), PointType.WALL),
        (Pos(15, 8), PointType.WALL),
        (Pos(15, 9), PointType.WALL),
        (Pos(15, 10), PointType.WALL),
        (Pos(6, 1), PointType.WALL),
        (Pos(7, 1), PointType.WALL),
        (Pos(8, 1), PointType.WALL),
        (Pos(9, 1), PointType.WALL),
        (Pos(10, 1), PointType.WALL),
        (Pos(6, 15), PointType.WALL),
        (Pos(7, 15), PointType.WALL),
        (Pos(8, 15), PointType.WALL),
        (Pos(9, 15), PointType.WALL),
        (Pos(10, 15), PointType.WALL),
        # Food
        (Pos(4, 6), PointType.FOOD),
        (Pos(4, 10), PointType.FOOD),
        (Pos(6, 4), PointType.FOOD),
        (Pos(10, 4), PointType.FOOD),
        (Pos(6, 12), PointType.FOOD),
        (Pos(10, 12), PointType.FOOD),
        (Pos(12, 6), PointType.FOOD),
        (Pos(12, 10), PointType.FOOD),
        # Top-left
        (Pos(2, 2), PointType.BODY_VER),
        (Pos(3, 2), PointType.BODY_VER),
        (Pos(4, 2), PointType.BODY_UR),
        (Pos(4, 3), PointType.BODY_LU),
        (Pos(3, 3), PointType.BODY_VER),
        (Pos(2, 3), PointType.BODY_RD),
        (Pos(2, 4), PointType.BODY_DL),
        (Pos(2, 4), PointType.BODY_DL),
        (Pos(3, 4), PointType.BODY_VER),
        (Pos(4, 4), PointType.HEAD_D),
        # Top-right
        (Pos(2, 14), PointType.BODY_VER),
        (Pos(3, 14), PointType.BODY_VER),
        (Pos(4, 14), PointType.BODY_LU),
        (Pos(4, 13), PointType.BODY_UR),
        (Pos(3, 13), PointType.BODY_VER),
        (Pos(2, 13), PointType.BODY_DL),
        (Pos(2, 12), PointType.BODY_RD),
        (Pos(3, 12), PointType.BODY_VER),
        (Pos(4, 12), PointType.HEAD_D),
        # Bottom-left
        (Pos(14, 2), PointType.BODY_VER),
        (Pos(13, 2), PointType.BODY_VER),
        (Pos(12, 2), PointType.BODY_RD),
        (Pos(12, 3), PointType.BODY_DL),
        (Pos(13, 3), PointType.BODY_VER),
        (Pos(14, 3), PointType.BODY_UR),
        (Pos(14, 4), PointType.BODY_LU),
        (Pos(13, 4), PointType.BODY_VER),
        (Pos(12, 4), PointType.HEAD_U),
        # Bottom-right
        (Pos(14, 14), PointType.BODY_VER),
        (Pos(13, 14), PointType.BODY_VER),
        (Pos(12, 14), PointType.BODY_DL),
        (Pos(12, 13), PointType.BODY_RD),
        (Pos(13, 13), PointType.BODY_VER),
        (Pos(14, 13), PointType.BODY_LU),
        (Pos(14, 12), PointType.BODY_UR),
        (Pos(13, 12), PointType.BODY_VER),
        (Pos(12, 12), PointType.HEAD_U),
        # Middle
        (Pos(10, 6), PointType.HEAD_L),
        (Pos(10, 7), PointType.BODY_HOR),
        (Pos(10, 8), PointType.BODY_HOR),
        (Pos(10, 9), PointType.BODY_HOR),
        (Pos(10, 10), PointType.BODY_LU),
        (Pos(9, 10), PointType.BODY_VER),
        (Pos(8, 10), PointType.BODY_DL),
        (Pos(8, 9), PointType.BODY_HOR),
        (Pos(8, 8), PointType.BODY_HOR),
        (Pos(8, 7), PointType.BODY_HOR),
        (Pos(8, 6), PointType.BODY_UR),
        (Pos(7, 6), PointType.BODY_VER),
        (Pos(6, 6), PointType.BODY_RD),
        (Pos(6, 7), PointType.BODY_HOR),
        (Pos(6, 8), PointType.BODY_HOR),
        (Pos(6, 9), PointType.BODY_HOR),
        (Pos(6, 10), PointType.HEAD_R)
    )
    for content in contents:
        game_map.point(content[0]).type = content[1]

    GameWindow("Basic Elements", game_conf, game_map).show()
예제 #2
0
def test_game_window():
    game_conf = GameConf()
    game_conf.map_rows = 15
    game_conf.map_cols = game_conf.map_rows
    game_conf.show_grid_line = True
    game_conf.show_info_panel = False

    game_map = Map(game_conf.map_rows + 2, game_conf.map_cols + 2)
    contents = (
        # Walls
        (Pos(1, 6), PointType.WALL),
        (Pos(1, 7), PointType.WALL),
        (Pos(1, 8), PointType.WALL),
        (Pos(1, 9), PointType.WALL),
        (Pos(1, 10), PointType.WALL),
        (Pos(15, 6), PointType.WALL),
        (Pos(15, 7), PointType.WALL),
        (Pos(15, 8), PointType.WALL),
        (Pos(15, 9), PointType.WALL),
        (Pos(15, 10), PointType.WALL),
        (Pos(6, 1), PointType.WALL),
        (Pos(7, 1), PointType.WALL),
        (Pos(8, 1), PointType.WALL),
        (Pos(9, 1), PointType.WALL),
        (Pos(10, 1), PointType.WALL),
        (Pos(6, 15), PointType.WALL),
        (Pos(7, 15), PointType.WALL),
        (Pos(8, 15), PointType.WALL),
        (Pos(9, 15), PointType.WALL),
        (Pos(10, 15), PointType.WALL),
        # Food
        (Pos(4, 6), PointType.FOOD),
        (Pos(4, 10), PointType.FOOD),
        (Pos(6, 4), PointType.FOOD),
        (Pos(10, 4), PointType.FOOD),
        (Pos(6, 12), PointType.FOOD),
        (Pos(10, 12), PointType.FOOD),
        (Pos(12, 6), PointType.FOOD),
        (Pos(12, 10), PointType.FOOD),
        # Top-left
        (Pos(2, 2), PointType.BODY_VER),
        (Pos(3, 2), PointType.BODY_VER),
        (Pos(4, 2), PointType.BODY_UR),
        (Pos(4, 3), PointType.BODY_LU),
        (Pos(3, 3), PointType.BODY_VER),
        (Pos(2, 3), PointType.BODY_RD),
        (Pos(2, 4), PointType.BODY_DL),
        (Pos(2, 4), PointType.BODY_DL),
        (Pos(3, 4), PointType.BODY_VER),
        (Pos(4, 4), PointType.HEAD_D),
        # Top-right
        (Pos(2, 14), PointType.BODY_VER),
        (Pos(3, 14), PointType.BODY_VER),
        (Pos(4, 14), PointType.BODY_LU),
        (Pos(4, 13), PointType.BODY_UR),
        (Pos(3, 13), PointType.BODY_VER),
        (Pos(2, 13), PointType.BODY_DL),
        (Pos(2, 12), PointType.BODY_RD),
        (Pos(3, 12), PointType.BODY_VER),
        (Pos(4, 12), PointType.HEAD_D),
        # Bottom-left
        (Pos(14, 2), PointType.BODY_VER),
        (Pos(13, 2), PointType.BODY_VER),
        (Pos(12, 2), PointType.BODY_RD),
        (Pos(12, 3), PointType.BODY_DL),
        (Pos(13, 3), PointType.BODY_VER),
        (Pos(14, 3), PointType.BODY_UR),
        (Pos(14, 4), PointType.BODY_LU),
        (Pos(13, 4), PointType.BODY_VER),
        (Pos(12, 4), PointType.HEAD_U),
        # Bottom-right
        (Pos(14, 14), PointType.BODY_VER),
        (Pos(13, 14), PointType.BODY_VER),
        (Pos(12, 14), PointType.BODY_DL),
        (Pos(12, 13), PointType.BODY_RD),
        (Pos(13, 13), PointType.BODY_VER),
        (Pos(14, 13), PointType.BODY_LU),
        (Pos(14, 12), PointType.BODY_UR),
        (Pos(13, 12), PointType.BODY_VER),
        (Pos(12, 12), PointType.HEAD_U),
        # Middle
        (Pos(10, 6), PointType.HEAD_L),
        (Pos(10, 7), PointType.BODY_HOR),
        (Pos(10, 8), PointType.BODY_HOR),
        (Pos(10, 9), PointType.BODY_HOR),
        (Pos(10, 10), PointType.BODY_LU),
        (Pos(9, 10), PointType.BODY_VER),
        (Pos(8, 10), PointType.BODY_DL),
        (Pos(8, 9), PointType.BODY_HOR),
        (Pos(8, 8), PointType.BODY_HOR),
        (Pos(8, 7), PointType.BODY_HOR),
        (Pos(8, 6), PointType.BODY_UR),
        (Pos(7, 6), PointType.BODY_VER),
        (Pos(6, 6), PointType.BODY_RD),
        (Pos(6, 7), PointType.BODY_HOR),
        (Pos(6, 8), PointType.BODY_HOR),
        (Pos(6, 9), PointType.BODY_HOR),
        (Pos(6, 10), PointType.HEAD_R)
    )
    for content in contents:
        game_map.point(content[0]).type = content[1]

    GameWindow("Basic Elements", game_conf, game_map).show()
예제 #3
0
    "greedy": "GreedySolver",
    "hamilton": "HamiltonSolver",
    "dqn": "DQNSolver",
}

dict_mode = {
    "normal": GameMode.NORMAL,
    "bcmk": GameMode.BENCHMARK,
    "train_dqn": GameMode.TRAIN_DQN,
    "train_dqn_gui": GameMode.TRAIN_DQN_GUI,
}

parser = argparse.ArgumentParser(description="Run snake game agent.")
parser.add_argument(
    "-s",
    default="greedy",
    choices=dict_solver.keys(),
    help="name of the solver to direct the snake (default: hamilton)")
parser.add_argument("-m",
                    default="normal",
                    choices=dict_mode.keys(),
                    help="game mode (default: normal)")
args = parser.parse_args()

conf = GameConf()
conf.solver_name = dict_solver[args.s]
conf.mode = dict_mode[args.m]
print("Solver: %s    Mode: %s" % (conf.solver_name, conf.mode))

Game(conf).run()
예제 #4
0
from snake.game import Game, GameConf, GameMode

greedy = "GreedySolver"
hamilton = "HamiltonSolver"

normal = GameMode.NORMAL

conf = GameConf()
conf.solver_name = greedy
conf.mode = normal
print("Solver: %s " % (conf.solver_name))
print("Mode: %s" % (conf.mode))
Game(conf).run()
from snake.game import Game, GameConf, GameMode

greedy = "GreedySolver"
hamilton = "HamiltonSolver"

normal = GameMode.NORMAL

conf = GameConf()
conf.solver_name = hamilton
conf.mode = normal
print("Solver: %s " % (conf.solver_name))
print("Mode: %s" % (conf.mode))
Game(conf).run()
예제 #6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0103,C0111

from snake.game import GameConf, Game


conf = GameConf()

conf.solver_name = "NeuralSolver"
#conf.solver_name = "HamiltonSolver"
#conf.solver_name = "GreedySolver"


Game(conf).run()
예제 #7
0
dict_mode = {
    "normal": GameMode.NORMAL,
    "bcmk": GameMode.BENCHMARK,
    "train_dqn": GameMode.TRAIN_DQN,
    "train_dqn_gui": GameMode.TRAIN_DQN_GUI,
}

parser = argparse.ArgumentParser(description="Run snake game agent.")
parser.add_argument(
    "-s",
    default="hamilton",
    choices=dict_solver.keys(),
    help="name of the solver to direct the snake (default: hamilton)")
parser.add_argument("-m",
                    default="normal",
                    choices=dict_mode.keys(),
                    help="game mode (default: normal)")
parser.add_argument("-c", default=8, help="column size(default: 8)", type=int)
parser.add_argument("-r", default=8, help="row size(default: 8)", type=int)
args = parser.parse_args()

conf = GameConf()
conf.solver_name = dict_solver[args.s]
conf.mode = dict_mode[args.m]
conf.map_rows = args.r
conf.map_cols = args.c
conf.readjust_UI()
print("Solver: %s    Mode: %s" % (conf.solver_name, conf.mode))

Game(conf).run()
예제 #8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0103,C0111
import sys
from snake.game import Game, GameConf, GameMode

sys.tracebacklimit = 0
dict_solver = {
    "g": "GreedySolver",
    "h": "HamiltonSolver",
}

dict_mode = {
    "n": GameMode.NORMAL,
    "b": GameMode.BENCHMARK,
}

conf = GameConf()
conf.solver_name = dict_solver["g"]
conf.mode = dict_mode["b"]
print("Solver: %s    Mode: %s" % (conf.solver_name, conf.mode))

Game(conf).run()
예제 #9
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0103,C0111

from snake.game import GameConf, Game

conf = GameConf()

conf.solver_name = "HamiltonSolver"
#conf.solver_name = "GreedySolver"

Game(conf).run()
예제 #10
0
파일: run.py 프로젝트: chuyangLiu/Snake-AI
import argparse

from snake.game import Game, GameConf, GameMode

dict_solver = {
    "greedy": "GreedySolver",
    "hamilton": "HamiltonSolver",
    "dqn": "DQNSolver",
}

dict_mode = {
    "normal": GameMode.NORMAL,
    "bcmk": GameMode.BENCHMARK,
    "train_dqn": GameMode.TRAIN_DQN,
    "train_dqn_gui": GameMode.TRAIN_DQN_GUI,
}

parser = argparse.ArgumentParser(description="Run snake game agent.")
parser.add_argument("-s", default="hamilton", choices=dict_solver.keys(),
                    help="name of the solver to direct the snake (default: hamilton)")
parser.add_argument("-m", default="normal", choices=dict_mode.keys(),
                    help="game mode (default: normal)")
args = parser.parse_args()

conf = GameConf()
conf.solver_name = dict_solver[args.s]
conf.mode = dict_mode[args.m]
print("Solver: %s    Mode: %s" % (conf.solver_name, conf.mode))

Game(conf).run()