Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README copy.md

This file was deleted.

6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ services:
container_name: games-api
environment:
- NODE_ENV=production
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=${REDIS_PORT:-1118}
- REDIS_USERNAME=${REDIS_USERNAME:-admin}
- REDIS_PASSWORD=${REDIS_PASSWORD:-default}
- MONGODB=${MONGODB:-mongodb://username:password@host:port}
- BROKER_URL=${BROKER_URL:-ws://localhost:8070}
restart: unless-stopped # options: always, unless-stopped, on-failure
ports:
- '8060:8060' # Expose port 8060 on the host
Expand Down
39 changes: 39 additions & 0 deletions games_ai/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 %
94 changes: 94 additions & 0 deletions games_ai/generate_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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")
75 changes: 75 additions & 0 deletions games_ai/generate_dataset_copy copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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")
75 changes: 75 additions & 0 deletions games_ai/generate_dataset_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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")
2 changes: 2 additions & 0 deletions games_ai/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if __name__ == "__main__":
print("Hello from games_ai/play.py")
4 changes: 4 additions & 0 deletions games_ai/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mlx
pymongo
numpy
pandas
Loading