arknights recruit calculator(1)

# arknights recruit calculator

# Published: 2022/08/27
# Updated: 2022/08/27

# PREFACE

  • I’m pretty addicted to this game named Arknights these days, and there is this module named “公招”(“recruit” in English or whatever). So there is this calculator tools use to help you recruit what you want on website. One day it the website/procedure were been maintained. And I been studying php for couples of days. That’s when I decided to build my own recruit calculator.
  • It’s still in testing phase, when it’s complete, I may put it on a website.
  • The php function mention below can be consulted on php.net

I use html, css to create the User Interface. User can input their tags(5 at most in one post), and program will output the cadres that fits(It will print all combination of the tags that are input).

The UI designed was easy(not to pursue a perfect, that is), just use a POST method and let the php program receive it. The backend devided the STRING into array, and search in the mysql.

There is this problem that HOW TO ESTABLISH THE SQL? There isn’t a sql you can find so easily that is ready made. The closest thing I found was a python dictionary. I wasn’t going to wrote the program in python. So I need to transform it into a PHP ARRAY. At first, I tried to use C to read the py dictionary. Obviously it’s too complicate and I should have better choose– json.dumps() ,a function in python that can transform a dictionary into a json file. Like this:

a=json.dumps(list)
However, it outputted errors. There I knew json.dumps cann’t dail with Chinese. So I searched for solutions and code down whese:

import json
import numpy as np
class Encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, bytes):
return str(obj, encoding='utf-8')
return json.JSONEncoder.default(self, obj)
a=json.dumps(top_operators_list,cls=Encoder)
with open('tags.txt','a') as file0:
print(a,file=file0)
It actually still output error. After few hours, I found the dictionary’s array used “{}” instead of “[]”. Correct all of that, it works and I got a json file containing the data I need.

Now, I need to put the data in json file into a php array. Luckly, there is this function json_decode that can do the trick. So now the array was prepared.

To search the cadres, you can combine the array into a string in full permutation.(USING DFS) (TIPS:sort your string each time you search will make the work much easier.)

Designed the output UI, and it’s all done!