ETH官方钱包

切換
舊版
前往
大廳
主題

open source

| 2021-05-03 12:47:26 | 巴幣 0 | 人氣 359

這個檔案沒有涉及什麼奇怪的bug或非正規遊戲手段,所以可以直接公開。
我本來是寫C++的,所以有些部分看起來可能很不Python,就請各位當作沒發現吧。
from PIL import Image
from dhash import dhash_int, get_num_bits_different
import os, json

runestone_dhash = dict()
sample_names = ['water', 'fire', 'earth', 'light', 'dark', 'heart']
for k in sample_names:
    img = Image.open('./samples/%s.png' % k)
    runestone_dhash[k] = dhash_int(img)

sample_size = 179
sample_x = [0, 179, 359, 538, 718, 898]
sample_y = [0, 181, 361, 540, 716]

boards = []
histogram = {n: 0 for n in range(31)}

def compare_runestone(img):
    dh = dhash_int(img)
    min_k, min_value = '', 128
    for k in sample_names:
        dist = get_num_bits_different(runestone_dhash[k], dh)
        if dist < min_value:
            min_k, min_value = k, dist
    return min_k

for i in range(1, 1501):
    img = Image.open('./images/scr%d.png' % i)
    board = {
        'stones': [[None for _ in range(5)] for _ in range(6)],
        'frequency': {k: 0 for k in sample_names},
        'dissolvable': 0
    }
    for x in range(6):
        for y in range(5):
            runestone_piece = img.crop((sample_x[x], sample_y[y], sample_x[x]+sample_size, sample_y[y]+sample_size))
            k = compare_runestone(runestone_piece)
            board['stones'][x][y] = k
            board['frequency'][k] += 1
    for k in sample_names:
        if board['frequency'][k] >= 3:
            board['dissolvable'] += table['frequency'][k]
    histogram[board['dissolvable']] += 1
    boards.append(board)

for n in histogram:
    if histogram[n] > 0:
        print('%d: %d time%s' % (n, histogram[n], 's' if histogram[n] > 1 else ''))

d = {
    'histogram': {n: histogram[n] for n in histogram if histogram[n] > 0},
    'boards': boards
}
with open('result.json', 'w') as file:
    json.dump(d, file)

你問我測試的哪部分用了非正規手段?
給個提示,請問版面#1418的截圖是在哪一關拍的呢?

創作回應

更多創作