From b8d20470c30e3aa8e484556403facaf3efdd2a54 Mon Sep 17 00:00:00 2001 From: Pedro Darma <7318917+pedrodarma@users.noreply.github.com> Date: Tue, 25 Nov 2025 10:35:10 -0300 Subject: [PATCH 1/2] chore: Remove Games AI --- games_ai/doc.md | 39 ---- games_ai/generate_dataset.py | 94 --------- games_ai/generate_dataset_copy copy.py | 75 ------- games_ai/generate_dataset_copy.py | 75 ------- games_ai/play.py | 2 - games_ai/requirements.txt | 4 - games_ai/tictactoe_dataset.csv | 259 ------------------------- games_ai/tictactoe_model.safetensors | Bin 3888 -> 0 bytes games_ai/train.py | 116 ----------- 9 files changed, 664 deletions(-) delete mode 100644 games_ai/doc.md delete mode 100644 games_ai/generate_dataset.py delete mode 100644 games_ai/generate_dataset_copy copy.py delete mode 100644 games_ai/generate_dataset_copy.py delete mode 100644 games_ai/play.py delete mode 100644 games_ai/requirements.txt delete mode 100644 games_ai/tictactoe_dataset.csv delete mode 100644 games_ai/tictactoe_model.safetensors delete mode 100644 games_ai/train.py 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_5,cell_6,cell_7,cell_8,player,move,winner -0,0,0,0,0,0,0,0,0,1,2,1 -0,0,1,0,0,0,0,0,0,-1,7,-1 -0,0,1,0,0,0,0,-1,0,1,1,1 -0,1,1,0,0,0,0,-1,0,-1,5,-1 -0,1,1,0,0,-1,0,-1,0,1,4,1 -0,1,1,0,1,-1,0,-1,0,-1,3,-1 -0,1,1,-1,1,-1,0,-1,0,1,0,1 -0,0,0,0,0,0,0,0,0,1,1,1 -0,1,0,0,0,0,0,0,0,-1,0,-1 --1,1,0,0,0,0,0,0,0,1,4,1 --1,1,0,0,1,0,0,0,0,-1,5,-1 --1,1,0,0,1,-1,0,0,0,1,7,1 -0,0,0,0,0,0,0,0,0,1,3,1 -0,0,0,1,0,0,0,0,0,-1,8,-1 -0,0,0,1,0,0,0,0,-1,1,4,1 -0,0,0,1,1,0,0,0,-1,-1,5,-1 -0,0,0,1,1,-1,0,0,-1,1,2,1 -0,0,1,1,1,-1,0,0,-1,-1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,-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 bcb0cfe9c7fb75e98a0fd67594ea54580b793d17..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3888 zcmaKuc{JAR7RTw76cIuRbzVoJS7mD8efCd-A%&s{l_^CkGZpF}b286~N>ZYvOuf(k zDM|_rrf8sBQbLqSb?SERS@*x&eg4~Pul-q{?_TR!Yv&6J{O1L7?Ctlt_&V-%^mVki z=jiVD+q;*`+2yRU*vZY&hoc+F`A^4V*DfCy-=DReHdjMSb32!_)AyjK3rCk@sHMr_ za(rAJ|E}zQwu1i|4{&kY?dtnK0Ge7$S8%nomo5E25bnxTEFsG%GLh${67j>i+`!`bCcYkNq$Y>{+%QE(jAy;( zJ-PfR9j#HNpQK-s;!o?r+asSw_kM*WgJ!6E}*K(ll@+0V$tAYEiYH(~*JEVpSu@{bJZNC zxiOd+c9v?5T*Qtm%CJ+u3xXZ5!h}gX#9AE3rFO2kakUY6E4G68{V=Gob)@T_tK#8D zMyOPn%G2t2fevbSAv5U?T;%^i&HPciWl0?7p&cIJ{~GbFVlTZp>3* zc20bOuMTzSvq_d`rSJhR8Jpu4p~cuE*squ8d57n@N&`nZ{$znp7V%A&!x%YRTApWw zXF9&|h_NijT;WoP8s>$`RnrwxlK9tGG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MvMN!^}M{1#X}BpkLQ)w!Bn?b&tQxoYAUgOojrP z1RD#Q;2Xx))P^%=9@`nyghIwzF@kZ-u4G*1&%?#tZ^2cyno*D_V=BAtSvQZlNc#OC z+~py8yx0al7~EtSN5aUurLp=is2*=P>#XkJ; zY3g`V_AETpzYp)<*OSn)UDSa;K^r$tf+(I1?C9x-cm5@?prsnRbfc+Zt1$%ac7)-} zEQs`RP{`p2Z#ASquW1Xd&?@6O`1HdCRRRmAyI~zx!hx}Vs-+f;?ulaTB9lgB4U*8< zb_TQMNF=^fuf{h5(_p~`N;`a#bh*n*aL$T3Y}joNjBA?D_{)|Po8NxJ8fzh_yWNL* zr!PZJZXVcuUC4xU<7tMK7RDYyEQnWw#-#-ivD^n&E^EaTJY{^o@Guz4-yll$mr={L zg=BiGFe;{D!2Z0azE3H~Q)f@1+YBqnw{XR^zZ-*O&0+>e3Se$SCwb603X0MmZ7}-kA#8qa023c%(EGtOwn5@04U`%oYdj}24I@uLeCG)GJA8ycxx3*) zM-E1qe?#ATaWXC_!7h3sh3woSFz}2grtuDW4fVG zHHI#f&46nbRkZh|4KB*l!~SdG@cD@gnnhh9P7kKToHwSFEB+E2d=rUllnn??Ou%RF zY%-L=CxFN87(T;B&>F$d6mZY}xRXN7`br*|MIv_6ai2_Rhn&Td%R9qZ@_xWP;As zEL)-v;gB=o&i~oZ}Ccu zEOKu(!oD^U24v4b_5KLB>XE{`I3Pp5+0J71GvDIu;U~0k#w0L#76neRJBdBkgNdIK yRHw~`vrpwQplSfNjtubEZhwmgL9V!YM;2*ZX#;|tE1|tEkmgp%Fva@v?7so&+$!Jz 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() From fdfa9961505c84446704f61296d5249da885908e Mon Sep 17 00:00:00 2001 From: Pedro Darma <7318917+pedrodarma@users.noreply.github.com> Date: Tue, 25 Nov 2025 10:35:10 -0300 Subject: [PATCH 2/2] Upgrade API version to 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {