#๐Ÿ”’ tictactoe Qlearning not working

12 messages ยท Page 1 of 1 (latest)

arctic current
#

I'm trying to make a simple tictactoe Qlearning bot, but it seems like he's not evolving, i probably messed with the saving or the upadting of the qtable, but i can't find the bug myself (I tried...for several hours actually)
I'm sorry if my code is messy :
Qlearn.py
import numpy as np
import coregame
import AIbasiques

class QlearnAI:
def init(self, alpha=0.9, gamma=0.9, epsilon=0.1, n_actions=9):
self.alpha = alpha
self.gamma = gamma
self.epsilon = epsilon
self.n_actions = n_actions
self.q_table = np.zeros((3**n_actions, n_actions))
self.load("Qtable.npy")

def get_state(self, state):
    return np.sum([3**i * s for i, s in enumerate(state)])

def get_action(self, state):
    if np.random.rand() < self.epsilon:
        return np.random.randint(self.n_actions)
    else:
        state = self.get_state(state)
        return int(np.argmax(self.q_table[state]))

def update(self, state, action, reward, next_state):
    state = self.get_state(state)
    next_state = self.get_state(next_state)
    self.q_table[state, action] = (1 - self.alpha) * self.q_table[state, action] + self.alpha * (reward + self.gamma * np.max(self.q_table[next_state]))

def save(self, filename):
    np.save(filename, self.q_table)
def load(self, filename):
    try:
        self.q_table = np.load(filename,allow_pickle=True)
    except FileNotFoundError:
        self.q_table = {}
def print(self):
    print(self.q_table)

This is my first file, i got an other one where the pb may be, but 100 lines, discord didn't wanted ...

jagged kestrelBOT
#

@arctic current

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

arctic current
#

perhaps better like that :

#

the other file :

buoyant iris
arctic current
#

i do know that

arctic current
#

and while it doesn't even work for something as simple as tictactoe, idk how i could make it work for something harder

jagged kestrelBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.