Clash of Clans and image analysis (3)

Thing you want to do

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.

1. About class

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)

2. Input data

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.

3. 3. Reading input data

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)

Four. Specific contents of class

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]

Five. Finally

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

Clash of Clans and image analysis (3)
Story of image analysis of PDF file and data extraction
Analysis of X-ray microtomography image by Python
[Image classification] Facial expression analysis of dogs
Image of closure
Data cleansing 3 Use of OpenCV and preprocessing of image data
I tried morphological analysis and vectorization of words
Analysis of financial data by pandas and its visualization (2)
Analysis of financial data by pandas and its visualization (1)
Deep learning image analysis starting with Kaggle and Keras
[OpenCV / Python] I tried image analysis of cells with OpenCV
Basics of regression analysis
Perform isocurrent analysis of open channels with Python and matplotlib
Python application: Data cleansing # 3: Use of OpenCV and preprocessing of image data
Very convenient combination of CLI image viewer Ɯberzug and Ranger
[PyTorch] Image classification of CIFAR-10
Problems of liars and honesty
Mechanism of pyenv and virtualenv
Ensemble learning and basket analysis
Combination of recursion and generator
Explanation and implementation of SocialFoceModel
100 image processing knocks !! (001 --010) Carefully and carefully
Differentiation of sort and generalization of sort
Implementation of independent component analysis
Application of CNN2 image recognition
Coexistence of pyenv and autojump
Use and integration of "Shodan"
Problems of liars and honesty
Occurrence and resolution of tensorflow.python.framework.errors_impl.FailedPreconditionError
Comparison of Apex and Lamvery
Source installation and installation of Python
Image expansion and contraction processing
Introduction and tips of mlflow.Tracking
Numerical analysis of ordinary differential equations with Scipy's odeint and ode
Read the image of the puzzle game and output the sequence of each block
Correspondence analysis of sentences with COTOHA API and save to file
Practice of data analysis by Python and pandas (Tokyo COVID-19 data edition)
Image processing with Python 100 knocks # 4 Binarization of Otsu (discriminant analysis method)
Implementation of Datetime picker action using line-bot-sdk-python and implementation sample of Image Carousel
Sentiment analysis of Youtube live comment and judge "emo" part from Youtube LIve.