ncn2569 commited on
Commit
1906a6c
·
1 Parent(s): 2c85d6c
src/__pycache__/ai_battle.cpython-312.pyc CHANGED
Binary files a/src/__pycache__/ai_battle.cpython-312.pyc and b/src/__pycache__/ai_battle.cpython-312.pyc differ
 
src/__pycache__/config.cpython-312.pyc CHANGED
Binary files a/src/__pycache__/config.cpython-312.pyc and b/src/__pycache__/config.cpython-312.pyc differ
 
src/__pycache__/engine.cpython-312.pyc CHANGED
Binary files a/src/__pycache__/engine.cpython-312.pyc and b/src/__pycache__/engine.cpython-312.pyc differ
 
src/__pycache__/evaluation.cpython-312.pyc CHANGED
Binary files a/src/__pycache__/evaluation.cpython-312.pyc and b/src/__pycache__/evaluation.cpython-312.pyc differ
 
src/ai_battle.py CHANGED
@@ -8,6 +8,7 @@ from .chess_ML.model import ChessModel
8
  import torch
9
  import pickle
10
  import numpy as np
 
11
  class AIAgent:
12
  """Base class cho các AI agent"""
13
 
@@ -80,13 +81,14 @@ class MLAgent(AIAgent):
80
 
81
  def __init__(self, model=None, move_to_idx: Dict[str, int] = None, idx_to_move: Dict[int, str] = None):
82
  super().__init__("ML AI", "Machine Learning Agent")
83
- with open("src/chess_ML/models/heavy_move_to_int_1", "rb") as file:
 
84
  self.move_to_int = pickle.load(file) #load mapping
85
  self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # sử dụng GPU nếu có
86
 
87
  # Load the model
88
  self.model = ChessModel(num_classes=len(self.move_to_int))
89
- self.model.load_state_dict(torch.load("src/chess_ML/models/TORCH_1_100EPOCHS.pth"), map_location=self.device)
90
  self.model.to(self.device)
91
  self.model.eval() # Set the model to evaluation mode (it may be reductant)
92
 
 
8
  import torch
9
  import pickle
10
  import numpy as np
11
+ import os
12
  class AIAgent:
13
  """Base class cho các AI agent"""
14
 
 
81
 
82
  def __init__(self, model=None, move_to_idx: Dict[str, int] = None, idx_to_move: Dict[int, str] = None):
83
  super().__init__("ML AI", "Machine Learning Agent")
84
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
85
+ with open(os.path.join(BASE_DIR, "src/chess_ML/models/heavy_move_to_int_1"), "rb") as file:
86
  self.move_to_int = pickle.load(file) #load mapping
87
  self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # sử dụng GPU nếu có
88
 
89
  # Load the model
90
  self.model = ChessModel(num_classes=len(self.move_to_int))
91
+ self.model.load_state_dict(torch.load(os.path.join(BASE_DIR, 'src/chess_ML/models/TORCH_1_100EPOCHS.pth'), map_location=self.device))
92
  self.model.to(self.device)
93
  self.model.eval() # Set the model to evaluation mode (it may be reductant)
94
 
src/chess_ML/__pycache__/model.cpython-312.pyc CHANGED
Binary files a/src/chess_ML/__pycache__/model.cpython-312.pyc and b/src/chess_ML/__pycache__/model.cpython-312.pyc differ
 
src/streamlit_app.py CHANGED
@@ -234,7 +234,7 @@ with col_ctrl:
234
  piece = board.piece_at(chess.parse_square(from_sq))
235
  if piece and piece.piece_type == chess.PAWN:
236
  if (board.turn == chess.WHITE and to_sq[1] == "8") or \
237
- (board.turn == chess.BLACK and to_sq[1] == "1"):
238
  uci += "q"
239
  try:
240
  move = chess.Move.from_uci(uci)
 
234
  piece = board.piece_at(chess.parse_square(from_sq))
235
  if piece and piece.piece_type == chess.PAWN:
236
  if (board.turn == chess.WHITE and to_sq[1] == "8") or \
237
+ (board.turn == chess.BLACK and to_sq[1] == "1"):
238
  uci += "q"
239
  try:
240
  move = chess.Move.from_uci(uci)