讨论:    

来自希顶维基

        

              。

              ,       3,                  。                    (clinker )。

          (       gui,              ,      ,          ,   shift       )           ,             ,                   。       shift        。

      ,      ,         。

      :       ,         ,             (    )。

  •          -      -          
  •          -      -       

   

    

1.   :                       ,         (       ,       ),             (     ,              )。

           。

2.   :       ,                    (  ,    ID    )。

              ,                       (         ,        )。                            ,     。

3.    :               json 

  •       (bP):16,              。
  •       (bE):16,        。
  •      (pP)  (pE):        (tick)           。
  •      (pD):                 。
  •      :            ,               。
  •        。

    

1.           ID                 ,            。

  •    = floor(P/E)*    

                        ,             。

  • P +=          (      *3)
  • E = P_old*E/P

        ,                  。

2.         n          :

  •      ,             ( =     (pD))      ,     ,              。

3.       n          :

  •      ,       (pP)           ,         (bP)   。

4.       n          :

  •                   ,       (pE)      ,                    (bE)。

python demo

import math
import tkinter as tk

bP, bE = 16, 16  # 本底污染和能量
P = [[bP for _ in range(10)] for _ in range(10)]  # 污染地图
E = [[1, 1, bE], [5, 5, bE], [3, 3, bE]]  # 制造器的坐标和能量
pP, pE = 0.1, 0.06  # 净化速度
pD = 0.5  # 扩散速度
current_iteration = 0  # 当前迭代计数

def make(index):  # 一次制造过程
    global P, E
    price = getPrice(index)
    xy = (E[index][0], E[index][1])

    cP = P[xy[0]][xy[1]]
    cE = E[index][2]
    
    make_info = f"迭代: {current_iteration}, 点({xy[0]}, {xy[1]}) 污染: {cP:.2f}, 能量: {cE:.2f}, 价值: {price}"

    if(price<=256):
        _P = P[xy[0]][xy[1]]
        P[xy[0]][xy[1]] += price
        if P[xy[0]][xy[1]] > 0:
            E[index][2] = _P * E[index][2] / P[xy[0]][xy[1]]
        
    return make_info

def getPrice(index):
    xy = (E[index][0], E[index][1])
    return max(math.floor(P[xy[0]][xy[1]] / E[index][2]), 0) * 3

def purify(dtime=1):  # 净化污染和能量
    global P, E
    for x in range(len(P)):
        for y in range(len(P[x])):
            P[x][y] = max(P[x][y] - dtime * pP, bP)  # 确保不低于bP
    
    for e in E:
        e[2] = min(e[2] + dtime * pE, bE)

def diff(dtime=1):  # 污染扩散
    global P
    new_P = [row[:] for row in P]
    for x in range(10):
        for y in range(10):
            x1, x2 = max(x-1, 0), min(x+1, 9)
            y1, y2 = max(y-1, 0), min(y+1, 9)
            new_P[x][y] = (P[x][y] +
                           P[x1][y] * pD +
                           P[x2][y] * pD +
                           P[x][y1] * pD +
                           P[x][y2] * pD) / (1 + 4 * pD)

    P[:] = new_P  

def update_display(window, make_info):  # 在tk窗口中显示污染和能量
    for widget in window.winfo_children():
        widget.destroy()  # 清空窗口内容

    pollution_label = tk.Label(window, text="污染:")
    pollution_label.pack()

    # 绘制灰度图
    canvas = tk.Canvas(window, width=200, height=200)
    canvas.pack()

    # 渲染灰度值,min 固定为 0,max 固定为 255
    for x in range(10):
        for y in range(10):
            # 计算灰度值
            # 这里将污染值归一化到 [0, 255]
            gray_value = int(255-min(255, max(0, P[x][y])))  # 污染值范围限制在0到255之间
            color = f'#{gray_value:02x}{gray_value:02x}{gray_value:02x}'  # 转换为颜色格式
            canvas.create_rectangle(y * 20, x * 20, (y + 1) * 20, (x + 1) * 20, fill=color, outline='')  # 绘制方块

    energy_text = "能量:\n" + "\n".join([f"点({e[0]}, {e[1]}): {e[2]:.2f}" for e in E])
    energy_label = tk.Label(window, text=energy_text)
    energy_label.pack()

    # 添加当前迭代数的标签
    iteration_label = tk.Label(window, text=f"当前迭代数: {current_iteration}")
    iteration_label.pack()

    make_label = tk.Label(window, text=make_info)
    make_label.pack()

def run_simulation_step(window):  
    global current_iteration
    if current_iteration >= 1000:
        return  

    diff()  # 先扩散
    purify()  # 后净化
    
    make_info = ""   
    if current_iteration in range(30, 1000):
        make_info += make(1) + "\n"
    if current_iteration in range(0, 1000):
        make_info += make(0) + "\n"   

    update_display(window, make_info)  # 更新窗口内容
    current_iteration += 1

def on_key_press(event):  # 处理按键事件
    run_simulation_step(root)  # 用户按键时执行下一步

root = tk.Tk()
root.title("污染和能量模拟")

root.bind("<Key>", on_key_press)  # 绑定按键事件

# 启动主事件循环
root.mainloop()

     (  ) 2025 1 16  ( ) 05:06 (CST)

           。                       。--QWERTY_52_38       2025 1 23  ( ) 23:57 (CST)