diff --git a/games_ai/doc.md b/games_ai/doc.md deleted file mode 100644 index 8a02dd0..0000000 --- a/games_ai/doc.md +++ /dev/null @@ -1,39 +0,0 @@ -# install - -brew update -brew upgrade - -pip3 --version -pip 21.2.4 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9) - -- pip3 install mlx - -# logs - -==> node@20 -node@20 is keg-only, which means it was not symlinked into /opt/homebrew, -because this is an alternate version of another formula. - -If you need to have node@20 first in your PATH, run: -echo 'export PATH="/opt/homebrew/opt/node@20/bin:$PATH"' >> /Users/pedrodarma/.zshrc - -For compilers to find node@20 you may need to set: -export LDFLAGS="-L/opt/homebrew/opt/node@20/lib" -export CPPFLAGS="-I/opt/homebrew/opt/node@20/include" -==> ruby -By default, binaries installed by gem will be placed into: -/opt/homebrew/lib/ruby/gems/3.4.0/bin - -You may want to add this to your PATH. - -ruby is keg-only, which means it was not symlinked into /opt/homebrew, -because macOS already provides this software and installing another version in -parallel can cause all kinds of trouble. - -If you need to have ruby first in your PATH, run: -echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> /Users/pedrodarma/.zshrc - -For compilers to find ruby you may need to set: -export LDFLAGS="-L/opt/homebrew/opt/ruby/lib" -export CPPFLAGS="-I/opt/homebrew/opt/ruby/include" -pedrodarma@Mini-Mini-Darma games-api % diff --git a/games_ai/generate_dataset.py b/games_ai/generate_dataset.py deleted file mode 100644 index 60e7bd1..0000000 --- a/games_ai/generate_dataset.py +++ /dev/null @@ -1,94 +0,0 @@ -# print("Hello from games_ai/play.py") - -from pymongo import MongoClient -import numpy as np -import pandas as pd - - -POSITION_MAP = { - "a0": 0, "a1": 1, "a2": 2, - "b0": 3, "b1": 4, "b2": 5, - "c0": 6, "c1": 7, "c2": 8, -} - -def convert_games_to_samples(): - client = MongoClient("mongodb://admin:G49vm222-3d02ksc!@192.168.15.17:27018/") - db = client["logs"] - # games = db["qtt_logs"].find({"status": "finished", "winner": {"$ne": None}}) - games = db["qtt_logs"].find({"status": "finished", "type": {"$eq": "game_over_win"}}) - - samples = [] - - print("Converting games to samples...") - # print("Total games found:", games.total()) - - for game in games: - board = [0]*9 - winner = game.get("winner") - x_id = game.get("playerXId") - o_id = game.get("playerOId") - - # print(game) - - x_moves = [POSITION_MAP[m] for m in game.get("playerXMoves", [])] - o_moves = [POSITION_MAP[m] for m in game.get("playerOMoves", [])] - - # print("X moves:", x_moves) - # print("O moves:", o_moves) - - board = [0]*9 - for i in range(len(x_moves)): - board[x_moves[i]] = 1 - - for i in range(len(o_moves)): - board[o_moves[i]] = -1 - - state = board.copy() - - print("Final board state:", state) - - # # Reconstroi o jogo movimento a movimento - # for i in range(max(len(x_moves), len(o_moves))): - # # Jogada do X - # if i < len(x_moves): - # move = x_moves[i] - # state = board.copy() - # samples.append({ - # "board": state, - # "player": 1, - # "move": move, - # "winner": 1 if winner == x_id else -1 - # }) - # board[move] = 1 - - # # Jogada do O - # if i < len(o_moves): - # move = o_moves[i] - # state = board.copy() - # samples.append({ - # "board": state, - # "player": -1, - # "move": move, - # "winner": 1 if winner == o_id else -1 - # }) - # board[move] = -1 - - return samples - -# Exemplo de uso: -if __name__ == "__main__": - samples = convert_games_to_samples() - print(samples[:5]) # mostra as 5 primeiras amostras - - rows = [] - for s in samples: - rows.append({ - **{f"cell_{i}": v for i, v in enumerate(s["board"])}, - "player": s["player"], - "move": s["move"], - "winner": s["winner"] - }) - - df = pd.DataFrame(rows) - df.to_csv("tictactoe_dataset.csv", index=False) - print("Dataset salvo com", len(df), "amostras") diff --git a/games_ai/generate_dataset_copy copy.py b/games_ai/generate_dataset_copy copy.py deleted file mode 100644 index e6e1ac2..0000000 --- a/games_ai/generate_dataset_copy copy.py +++ /dev/null @@ -1,75 +0,0 @@ -# print("Hello from games_ai/play.py") - -from pymongo import MongoClient -import numpy as np -import pandas as pd - - -POSITION_MAP = { - "a0": 0, "a1": 1, "a2": 2, - "b0": 3, "b1": 4, "b2": 5, - "c0": 6, "c1": 7, "c2": 8, -} - -def convert_games_to_samples(): - client = MongoClient("mongodb://admin:G49vm222-3d02ksc!@192.168.15.17:27018/") - db = client["logs"] - # games = db["qtt_logs"].find({"status": "finished"}) - games = db["qtt_logs"].find({"status": "finished", "type": {"$eq": "game_over_win"}}) - - samples = [] - - for game in games: - board = [0]*9 - winner = game.get("winner") - x_id = game.get("playerXId") - o_id = game.get("playerOId") - - x_moves = [POSITION_MAP[m] for m in game.get("playerXMoves", [])] - o_moves = [POSITION_MAP[m] for m in game.get("playerOMoves", [])] - - # Reconstroi o jogo movimento a movimento - for i in range(max(len(x_moves), len(o_moves))): - # Jogada do X - if i < len(x_moves): - move = x_moves[i] - state = board.copy() - samples.append({ - "board": state, - "player": 1, - "move": move, - "winner": 1 if winner == x_id else -1 - }) - board[move] = 1 - - # Jogada do O - if i < len(o_moves): - move = o_moves[i] - state = board.copy() - samples.append({ - "board": state, - "player": -1, - "move": move, - "winner": 1 if winner == o_id else -1 - }) - board[move] = -1 - - return samples - -# Exemplo de uso: -if __name__ == "__main__": - samples = convert_games_to_samples() - print(samples[:5]) # mostra as 5 primeiras amostras - - rows = [] - for s in samples: - rows.append({ - **{f"cell_{i}": v for i, v in enumerate(s["board"])}, - "player": s["player"], - "move": s["move"], - "winner": s["winner"] - }) - - df = pd.DataFrame(rows) - df.to_csv("tictactoe_dataset.csv", index=False) - print("Dataset salvo com", len(df), "amostras") diff --git a/games_ai/generate_dataset_copy.py b/games_ai/generate_dataset_copy.py deleted file mode 100644 index e6e1ac2..0000000 --- a/games_ai/generate_dataset_copy.py +++ /dev/null @@ -1,75 +0,0 @@ -# print("Hello from games_ai/play.py") - -from pymongo import MongoClient -import numpy as np -import pandas as pd - - -POSITION_MAP = { - "a0": 0, "a1": 1, "a2": 2, - "b0": 3, "b1": 4, "b2": 5, - "c0": 6, "c1": 7, "c2": 8, -} - -def convert_games_to_samples(): - client = MongoClient("mongodb://admin:G49vm222-3d02ksc!@192.168.15.17:27018/") - db = client["logs"] - # games = db["qtt_logs"].find({"status": "finished"}) - games = db["qtt_logs"].find({"status": "finished", "type": {"$eq": "game_over_win"}}) - - samples = [] - - for game in games: - board = [0]*9 - winner = game.get("winner") - x_id = game.get("playerXId") - o_id = game.get("playerOId") - - x_moves = [POSITION_MAP[m] for m in game.get("playerXMoves", [])] - o_moves = [POSITION_MAP[m] for m in game.get("playerOMoves", [])] - - # Reconstroi o jogo movimento a movimento - for i in range(max(len(x_moves), len(o_moves))): - # Jogada do X - if i < len(x_moves): - move = x_moves[i] - state = board.copy() - samples.append({ - "board": state, - "player": 1, - "move": move, - "winner": 1 if winner == x_id else -1 - }) - board[move] = 1 - - # Jogada do O - if i < len(o_moves): - move = o_moves[i] - state = board.copy() - samples.append({ - "board": state, - "player": -1, - "move": move, - "winner": 1 if winner == o_id else -1 - }) - board[move] = -1 - - return samples - -# Exemplo de uso: -if __name__ == "__main__": - samples = convert_games_to_samples() - print(samples[:5]) # mostra as 5 primeiras amostras - - rows = [] - for s in samples: - rows.append({ - **{f"cell_{i}": v for i, v in enumerate(s["board"])}, - "player": s["player"], - "move": s["move"], - "winner": s["winner"] - }) - - df = pd.DataFrame(rows) - df.to_csv("tictactoe_dataset.csv", index=False) - print("Dataset salvo com", len(df), "amostras") diff --git a/games_ai/play.py b/games_ai/play.py deleted file mode 100644 index 40daf1e..0000000 --- a/games_ai/play.py +++ /dev/null @@ -1,2 +0,0 @@ -if __name__ == "__main__": - print("Hello from games_ai/play.py") \ No newline at end of file diff --git a/games_ai/requirements.txt b/games_ai/requirements.txt deleted file mode 100644 index 0e24e84..0000000 --- a/games_ai/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -mlx -pymongo -numpy -pandas \ No newline at end of file diff --git a/games_ai/tictactoe_dataset.csv b/games_ai/tictactoe_dataset.csv deleted file mode 100644 index a318df8..0000000 --- a/games_ai/tictactoe_dataset.csv +++ /dev/null @@ -1,259 +0,0 @@ -cell_0,cell_1,cell_2,cell_3,cell_4,cell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1 -1,1,0,-1,0,0,0,-1,0,1,2,1 -0,0,0,0,0,0,0,0,0,1,2,1 -0,0,1,0,0,0,0,0,0,-1,6,-1 -0,0,1,0,0,0,-1,0,0,1,1,1 -0,1,1,0,0,0,-1,0,0,-1,7,-1 -0,1,1,0,0,0,-1,-1,0,1,0,1 -0,0,0,0,0,0,0,0,0,1,5,-1 -0,0,0,0,0,1,0,0,0,-1,4,1 -0,0,0,0,-1,1,0,0,0,1,3,-1 -0,0,0,1,-1,1,0,0,0,-1,6,1 -0,0,0,1,-1,1,-1,0,0,1,7,-1 -0,0,0,1,-1,1,-1,1,0,-1,2,1 -0,0,0,0,0,0,0,0,0,1,4,1 -0,0,0,0,1,0,0,0,0,-1,3,-1 -0,0,0,-1,1,0,0,0,0,1,8,1 -0,0,0,-1,1,0,0,0,1,-1,6,-1 -0,0,0,-1,1,0,-1,0,1,1,0,1 -0,0,0,0,0,0,0,0,0,1,5,1 -0,0,0,0,0,1,0,0,0,-1,2,-1 -0,0,-1,0,0,1,0,0,0,1,8,1 -0,0,-1,0,0,1,0,0,1,-1,4,-1 -0,0,-1,0,-1,1,0,0,1,1,6,1 -0,0,-1,0,-1,1,1,0,1,-1,1,-1 -0,-1,-1,0,-1,1,1,0,1,1,7,1 -0,0,0,0,0,0,0,0,0,1,8,1 -0,0,0,0,0,0,0,0,1,-1,5,-1 -0,0,0,0,0,-1,0,0,1,1,4,1 -0,0,0,0,1,-1,0,0,1,-1,7,-1 -0,0,0,0,1,-1,0,-1,1,1,2,1 -0,0,1,0,1,-1,0,-1,1,-1,0,-1 --1,0,1,0,1,-1,0,-1,1,1,6,1 diff --git a/games_ai/tictactoe_model.safetensors b/games_ai/tictactoe_model.safetensors deleted file mode 100644 index bcb0cfe..0000000 Binary files a/games_ai/tictactoe_model.safetensors and /dev/null differ diff --git a/games_ai/train.py b/games_ai/train.py deleted file mode 100644 index 601ea70..0000000 --- a/games_ai/train.py +++ /dev/null @@ -1,116 +0,0 @@ -# train.py -import numpy as np -from pymongo import MongoClient -import mlx.core as mx -import mlx.nn as nn -import mlx.optimizers as optim -import json -import os - -# ======================== -# CONFIGURAÇÕES -# ======================== -MONGO_URI = os.getenv("MONGO_URI", "mongodb://admin:G49vm222-3d02ksc!@192.168.15.17:27018/") -DB_NAME = "logs" -COLLECTION = "qtt_logs" -# MODEL_PATH = "/models/tictactoe_model.mlx" -# MODEL_PATH = "/tictactoe_model.mlx" -MODEL_PATH = "./tictactoe_model.safetensors" - -# ======================== -# FUNÇÕES DE PREPARO -# ======================== - -def position_to_index(pos): - # Converte "a0", "b1", etc. em índice 0..8 - mapping = {'a': 0, 'b': 1, 'c': 2} - col = mapping[pos[0]] - row = int(pos[1]) - return row * 3 + col - -def board_from_moves(moves_x, moves_o): - board = np.zeros(9, dtype=np.float32) - for m in moves_x: - board[position_to_index(m)] = 1 - for m in moves_o: - board[position_to_index(m)] = -1 - return board - -def create_dataset(games): - X, y = [], [] - for g in games: - moves_x = g.get("playerXMoves", []) - moves_o = g.get("playerOMoves", []) - winner = g.get("winner") - - # Cria o estado final do tabuleiro - board = board_from_moves(moves_x, moves_o) - - # Gera um label simples: quem venceu - # 1 = X venceu, -1 = O venceu, 0 = empate - if winner == g.get("playerXId"): - label = 1 - elif winner == g.get("playerOId"): - label = -1 - else: - label = 0 - - X.append(board) - y.append(label) - - return np.array(X), np.array(y, dtype=np.float32).reshape(-1, 1) - -def mse_loss(pred, target): - return mx.mean((pred - target) ** 2) - -# ======================== -# DEFINIÇÃO DO MODELO -# ======================== - -class TicTacToeNet(nn.Module): - def __init__(self): - super().__init__() - self.fc1 = nn.Linear(9, 32) - self.fc2 = nn.Linear(32, 16) - self.fc3 = nn.Linear(16, 1) - self.relu = nn.ReLU() - - def __call__(self, x): - x = self.relu(self.fc1(x)) - x = self.relu(self.fc2(x)) - return mx.sigmoid(self.fc3(x)) # saída entre 0 e 1 - -# ======================== -# TREINAMENTO -# ======================== - -def train(): - print("Conectando ao MongoDB...") - client = MongoClient(MONGO_URI) - db = client[DB_NAME] - games = list(db[COLLECTION].find({"status": "finished"})) - print(f"{len(games)} partidas carregadas.") - - X, y = create_dataset(games) - print("Dataset:", X.shape, y.shape) - - model = TicTacToeNet() - optimizer = optim.Adam(learning_rate=0.001) - - def loss_fn(model, X, y): - preds = model(X) - return mx.mean((preds - y) ** 2) - - # Treino - for epoch in range(10000): - loss, grads = mx.value_and_grad(loss_fn)(model, mx.array(X), mx.array(y)) - optimizer.update(model, grads) - if epoch % 10 == 0: - print(f"Epoch {epoch}: loss={loss.item():.4f}") - - os.makedirs(os.path.dirname(MODEL_PATH), exist_ok=True) - model.save_weights(MODEL_PATH) - print("✅ Modelo salvo em:", MODEL_PATH) - -if __name__ == "__main__": - train() diff --git a/package.json b/package.json index 6dd4de5..e22b1fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "games-api", - "version": "1.0.2", + "version": "1.0.3", "description": "Games API", "main": "index", "scripts": {