Beispiel #1
0
def _generate_line_symmetry_half_A(width, height, point_lower, point_upper):
    points = gen_2d_list(height, width)

    # 基準となる点配置を作成
    base_width = int((width + 1) / 2)
    for y in range(height):
        for x in range(base_width):
            points[y][x] = randint(point_lower, point_upper)

    # 対象となるように点を配置していく
    start_idx = base_width - (1 if len(points[0]) % 2 == 1 else 0)
    for y in range(height):
        points[y][start_idx:] = points[y][:base_width][::-1]

    return deepcopy(points)
Beispiel #2
0
def _generate_point_symmetry(width, height, point_lower, point_upper):
    points = gen_2d_list(height, width)

    # 基準となる点を設定する
    base_width = int((width + 1) / 2)
    for y in range(height):
        for x in range(base_width):
            points[y][x] = randint(point_lower, point_upper)

    # 点対称に得点を配置していく
    for x in range(width):
        for y in range(height):
            points[height - y - 1][width - x - 1] = points[y][x]

    return deepcopy(points)
Beispiel #3
0
    def cal_score(self, team_id_list):
        """
        スコアを計算する

        Params
        ----------
        team_id_list : int + List
            スコアを計算するチームIDのリスト

        Returns
        ----------
        map<int, int>
            チームIDがキー, スコアが値
        """
        score_list = {}

        for (idx, team_id) in enumerate(team_id_list):
            score_list[team_id] = {}

            # タイルポイント
            tiled_tmp = flatten_2d(self.board.tiled)
            points_flat = flatten_2d(self.board.points)
            score_list[team_id]["tilePoint"] = sum(
                map(lambda x, y: (x == team_id) * y, tiled_tmp, points_flat))

            # 全ての座標について、囲みが有効か探索
            self.rec_tiled = gen_2d_list(self.board.height, self.board.width)
            for y in range(self.board.height):
                for x in range(self.board.width):
                    if self.rec_tiled[y][x] == 0:
                        search_result = self.__recursive_child(x, y, team_id)
                        self.rec_tiled = search_result_process(
                            self.rec_tiled, search_result)
                        # ↑探索成功ならrec_tiledに結果を反映、そうでない場合は結果を破棄する

            # 領域ポイント : 囲みが有効である座標のスコアを合計する
            self.rec_tiled = flatten_2d(self.rec_tiled)
            score_list[team_id]["areaPoint"] = sum(
                map(lambda x, y: abs(x * y), self.rec_tiled, points_flat))

        self.rec_tiled = None
        return score_list
Beispiel #4
0
def _generate_line_symmetry_quarter(width, height, point_lower, point_upper):
    points = gen_2d_list(height, width)

    # 基準となる点を設定する
    base_width = int((width + 1) / 2)
    base_height = int((height + 1) / 2)
    for y in range(base_height):
        for x in range(base_width):
            points[y][x] = randint(point_lower, point_upper)

    # 対称となるように点を配置していく
    start_idx_x = base_width - (1 if len(points[0]) % 2 == 1 else 0)
    start_idx_y = base_height - (1 if len(points) % 2 == 1 else 0)
    for y in range(height):
        points[y][start_idx_x:] = points[y][:base_width][::-1]
    for x in range(width):
        for y in range(height):
            points[height - y - 1][x] = points[y][x]

    return deepcopy(points)
Beispiel #5
0
def _put_player_point_symmetry(width, height, player_num):
    tiled = gen_2d_list(height, width)
    base_width = int(width / 2)

    # 基準プレイヤー配置
    for cnt in range(player_num):
        x = randint(0, base_width - 1)
        y = randint(0, height - 1)
        while (tiled[y][x] != 0) and (tiled[y][x] == 1):
            x = randint(0, base_width - 1)
            y = randint(0, height - 1)
        tiled[y][x] = 1

    # 点対称に配置する
    for y in range(height):
        for x in range(base_width):
            if tiled[y][x] == 1:
                tiled[height - y - 1][width - x - 1] = 2

    return deepcopy(tiled)