---
# System prepended metadata

title: 請教 game 本身與 ai程式的互動

---

# 請教 game 本身與 ai程式的互動

從影片說明的一張圖表看來
game 每一 frame 更新都會和 ai程式的 update() 互動
可是我照著新版說明把程式 key 進去
發現打磚塊的板子都沒有移動
最簡單的在每個 method 上加了log
結果是這樣

```
===========Game is started at 2023-01-05 08:59:30.033772===========
1P
axl-init
axl-update
             AI Client ends
Warning: The object queue for the process '1P' is full. Drop the oldest object.
Warning: The object queue for the process '1P' is full. Drop the oldest object.
Warning: The object queue for the process '1P' is full. Drop the oldest object.
Warning: The object queue for the process '1P' is full. Drop the oldest object.
...
以下略(相同的warning應該有一兩百行)
```

update只有進去一次
reset都沒有
而且好像 ai程式就結束了
請問這是哪兒出了問題
版本問題 ? 還是少了什麻設定 ?

麻煩提點了, 謝謝 ~~

我的環境是 mac, python版本如下
```
> python --version
Python 3.9.6
> python -m mlgame -v
10.0.1
```


ai程式碼 :
```python
"""
The template of the main script of the machine learning process
"""
import os
import pickle
from datetime import datetime

class MLPlay:
    def __init__(self, ai_name, *args, **kwargs):
        """
        Constructor
        """
        print(ai_name)
        print("axl-init")
        self.scene_info = []
        self.commands = []
        self.data = {"scene_info":[], "command": []}
        self.ball_served = False
        self.previous_ball = (0, 0)
        self.pred = 100             #預設板子位置為100
        self.platform_y = 400       #板子y位置
        self.ball_speedy = 7        #frme球在y軸向移速度為+-7
        self.platform_width = 200   #板寛

    def update(self, scene_info, *args, **kwargs):
        """
        Generate the command according to the received `scene_info`.
        """
        # Make the caller to invoke `reset()` for the next round.
        print("axl-update")
        if (scene_info["status"] == "GAME_OVER" or
                scene_info["status"] == "GAME_PASS"):
            return "RESET"

        if not self.ball_served:
            self.ball_served = True
            self.previous_ball = scene_info["ball"]
            command = "SERVE_TO_RIGHT"
        else:   # rule code
            print("axl-move-left")
            command = "MOVE_LEFT"

        self.scene_info.append(scene_info)
        self.commands.append(command)
        self.previous_ball = scene_info["ball"]
        return command

    def reset(self):
        """
        Reset the status
        """
        print("axl-reset")
        self.ball_served = False

        self.data["scene_info"] = self.scene_info
        self.data["command"] = self.commands

        filepath = "log/"
        if not os.path.exists(filepath):
            os.makedirs(filepath)
        with open(os.path.join(os.path.dirname(__file__), \
            'log/scene_info_{:%Y_%m_%d_%H_%S}.pickle'.format(datetime.now())), \
                'wb') as f:
            pickle.dump(self.data, f)
            print("axl-dump")


```