This is a continuation of the previous image analysis. Last time: [Clash of Clans and image analysis (2)] (https://qiita.com/Bert/items/fc0fd330a0c80ef0a9ae)
Until the last time, I thought of a program to process the layout image of Clash of Clans and identify the location of the facility. This time it's a short break, so I'd like to practice the class to memorize the building information.
The detailed explanation is more solid in other articles, so I would like to summarize it briefly. There is a reserved word called class in pyhton, and by using class, it is possible to memorize not only data but also processing using data. (Details need to understand object orientation)
Consider the following csv file that describes the building information as input.
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
...
The contents are id (I gave it myself), name, level, physical strength, length of one side, number of facilities, attack range (minimum, maximum), attack type (land or air or both), target (single or Range or plural), DPS. For facilities that are not defense facilities, the items after the attack range are left blank.
Reading input data is relatively easy to implement using pandas.
import numpy as np
import pandas as pd
path_dir = 'facility_list.csv'
df = pd.read_csv(path_dir)
First, create a class for non-attack facilities.
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
We decided to build the defense facility by inheriting the 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]
I didn't make any progress this time ... Next, I would like to be able to recognize which facility is located in the layout using the image of the facility. It seems that advance preparation is difficult
Recommended Posts