def score_test_3(): width = 8 height = 5 points = [ [1, 0, 2, 1, 1, 2, 0, 1], [0, 1, 0, 1, 1, 0, 1, 0], [1, 3, -1, 2, 2, -1, 3, 1], [0, 1, 0, 1, 1, 0, 1, 0], [1, 0, 2, 1, 1, 2, 0, 1] ] tiled = [ [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 2, 1 ,0], [0, 1, 2, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 1, 0] ] board = Board(width, height, points, tiled) game = Game(board, []) true_score = { 1: { "tilePoint": 22, "areaPoint": 10 }, 2: { "tilePoint": 2, "areaPoint": 4 } } assert(game.cal_score([1, 2]) == true_score)
def score_test_6(): width = 7 height = 7 points = [ [0, 1, 2, 0, 2, 1, 0], [2, -2, 0, 1, 0, -2, 2], [2, 1, 0, -2, 0, 1, 2], [1, 2, 2, 3, 2, 2, 1], [1, 2, 2, 3, 2, 2, 1], [2, 1, 0, -2, 0, 1, 2], [2, -2, 0, 1, 0, -2, 2] ] tiled = [ [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1] ] board = Board(width, height, points, tiled) game = Game(board, []) true_score = { 1: { "tilePoint": 32, "areaPoint": 22 } } assert(game.cal_score([1]) == true_score)
def score_test_5(): width = 5 height = 5 points = [ [-2, 0, 1, 0, -2], [1, 0, -2, 0, 1], [2, 2, 3, 2, 2], [2, 2, 3, 2, 2], [1, 0, -2, 0, 1] ] tiled = [ [1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1] ] board = Board(width, height, points, tiled) game = Game(board, []) true_score = { 1: { "tilePoint": 15, "areaPoint": 4 } } assert (game.cal_score([1]) == true_score), "Test Failed"
def flow_test_2(): width = 7 height = 3 points = [ [1, 4, -2, 5, -2, 4, 1], [8, 9, 1, 0, 1, 9, 8], [0, 4, 6, 3, 6, 4, 0], ] tiled = [ [0, 0, 1, 0, 2, 0, 0], [0, 0, 1, 0, 2, 0, 0], [0, 0, 1, 0, 2, 0, 0] ] agents = [ Agent(1, 1, 2, 0), Agent(1, 2, 2, 1), Agent(1, 3, 2, 2), Agent(2, 4, 4, 0), Agent(2, 5, 4, 1), Agent(2, 6, 4, 2), ] board = Board(width, height, points, tiled) simulator = Game(board, agents) # 1 simulator.set_action(1, 1, 1, 0) simulator.set_action(1, 2, 1, 0) simulator.set_action(1, 3, -1, 0) simulator.set_action(2, 4, 1, 0) simulator.set_action(2, 5, -1, 0) simulator.set_action(2, 6, -1, 0) simulator.step() true_score = { 1: { "tilePoint": 14, "areaPoint": 0 }, 2: { "tilePoint": 12, "areaPoint": 0 } } assert(simulator.cal_score([1, 2]) == true_score) assert(simulator.turn == 1)
def flow_test_1(): width = 5 height = 5 points = [ [2, 1, 0, 1, 2], [4, 5, 3, 5, 4], [1, 1, 2, 1, 1], [4, 5, 3, 5, 4], [2, 1, 0, 1, 2] ] tiled = [ [0, 1, 0, 2, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 2, 0, 1, 0] ] agents = [ Agent(1, 1, 1, 0), Agent(1, 2, 3, 4), Agent(2, 3, 3, 0), Agent(2, 4, 1, 4) ] board = Board(width, height, points, tiled) simulator = Game(board, agents) simulator.set_action(1, 1, 0, 1) simulator.set_action(1, 2, -1, 0) simulator.set_action(2, 3, 1, 0) simulator.set_action(2, 4, 0, -1) simulator.step() true_score = { 1: { "tilePoint": 7, "areaPoint": 0 }, 2: { "tilePoint": 9, "areaPoint": 0 } } assert(simulator.cal_score([1, 2]) == true_score) assert(simulator.turn == 1)
def get_stage_data(self, battle_id): """ Stageテーブルから初期データを取得して盤面(Board)とエージェント情報(list)を返す Params ---------- battle_id : int 試合ID Return ---------- Board 盤面情報 list(Agent) エージェント情報 """ # 盤面情報 board_info = self.__get_data(battle_id) if len(board_info) == 0: return None width = board_info["width"] height = board_info["height"] points = json.loads(board_info["points"])["points"] tiled = json.loads(board_info["tiled"])["tiled"] agent_pos = json.loads(board_info["agent_pos"])["agent_pos"] board = Board(width, height, points, tiled) # エージェント情報 agents = [] for team in agent_pos.keys(): for agent_id in agent_pos[team].keys(): agent = agent_pos[team][agent_id] agents.append( Agent(int(team), int(agent_id), agent["x"], agent["y"])) return board, agents
def _get_exist_board(battle_id, json_id, teamA, teamB): # JSONデータ読み込み data = read_exist_json(json_id) if data == None: return None width = data["width"] height = data["height"] # チーム, エージェントID置換 agent_pos_dict = {teamA: {}, teamB: {}} teams = [teamA, teamB] for t_idx in range(2): data["teams"][t_idx]["team_id"] = teams[t_idx] for a_idx in range(len(data["teams"][0]["agents"])): agent_id = int( str(battle_id % 2048) +\ str(teams[t_idx] % 2048) +\ str(a_idx) ) data["teams"][t_idx]["agents"][a_idx]["agentID"] = agent_id data["teams"][t_idx]["agents"][a_idx]["x"] -= 1 data["teams"][t_idx]["agents"][a_idx]["y"] -= 1 x = data["teams"][t_idx]["agents"][a_idx]["x"] y = data["teams"][t_idx]["agents"][a_idx]["y"] agent_pos_dict[teams[t_idx]][agent_id] = { "x": x, "y": y } # tiled置換 for y in range(height): for x in range(width): if data["tiled"][y][x] != 0: team_id = data["tiled"][y][x] data["tiled"][y][x] = teams[team_id-1] return Board(data["width"], data["height"], data["points"], data["tiled"]), agent_pos_dict