0
0

More than 3 years have passed since last update.

クラッシュオブクラウンと画像解析(3)

Posted at

やりたいこと

前回の画像解析の続きです.
前回:クラッシュオブクラウンと画像解析(2)

前回まではクラクラの配置画像を加工し,施設の位置を特定するためのプログラムを考えました.
今回は少し休憩ということで,建物の情報を記憶するためにclassの練習をしていきたいと思います.

1. classについて

詳しい説明は他の方の記事の方がしっかりしているので,簡単にまとめたいと思います.
pyhtonにはclassという予約語があり,classを用いることでデータだけでなくデータを使った処理を記憶することができます.(詳しくはオブジェクト指向を理解する必要がある)

2. 入力データ

入力として建物の情報を記述した以下のようなcsvファイルを考えます.

id,name,level,hp,size,max_install,range_min,range_max,attack_type,targets,dps
104,SpellFactory,6,840,3,1
402,X-BombTower-AG,8,4200,3,4,0,11,ground&air,single,185
...

内容としてはid(自分で勝手につけた),名前,レベル,体力,一辺の長さ,施設の数,攻撃範囲(最低,最大),攻撃のタイプ(陸or空or両方),ターゲット(単体or範囲or複数),DPSです.防衛施設ではない施設は攻撃範囲以降の項目を空白にしています.

3.入力データの読み込み

入力データの読み込みはpandasを使って比較的簡単に実装することができます.

import numpy as np
import pandas as pd

path_dir = 'facility_list.csv'
df = pd.read_csv(path_dir)

4.classの具体的な中身

まずは非攻撃施設のクラスを作ります.

class Facility():
    def __init__(self, id, name, size, hp, level=-1):
        self.id = id
        self.name = name
        self.size = size
        self.hp = hp
        self.level = level

防衛施設はFacilityを継承して作ることにしました.

class AttackFacility(Facility):
    def __init__(self, id, name, size, hp, level, range_min, range_max, attack_type, targets, dps):
        super().__init__(id, name, size, hp, level)
        self.attack_range = self.attack_range_info(range_min, range_max)
        self.attack_type = attack_type
        self.targets = targets
        self.dps = dps

    def attack_range_info(self, range_min, range_max):
        return [range_min, range_max]

5.最後に

今回は全然進みませんでした…
次は施設の画像を使って配置のどこにどの施設があるか認識できるようにしたいと思います.
事前準備がたいへんそうですが

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0