import random

home = random.randint(0,100)
spawn = random.randint(0,100)

Q = [[0, 0] for _ in range(100)]
# Q[pos][0] = 左
# Q[pos][1] = 右
print(f"ホーム:{home} スポーン:{spawn}")
for _ in range(100):

    pos = spawn

    while pos != home:

        # AIが行動選択
        action = random.choice([0, 1])

        if action == 0:
            next_pos = max(0, pos - 1)
        else:
            next_pos = min(99, pos + 1)

        # 報酬
        if next_pos == home:
            reward = 100
        else:
            reward = -5

        # 学習
        Q[pos][action] = reward + max(Q[next_pos])

        pos = next_pos

print(Q)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: