Inkcap commited on
Commit
cb8fc87
·
1 Parent(s): 7d591ab

Made some progress on logger and game_database

Browse files
Files changed (2) hide show
  1. src/game_database.py +9 -1
  2. src/logger.py +25 -7
src/game_database.py CHANGED
@@ -1,2 +1,10 @@
 
 
1
  class game_database:
2
- pass
 
 
 
 
 
 
 
1
+ import chess
2
+
3
  class game_database:
4
+ def __init__(self):
5
+ pass
6
+
7
+ def display_game(self):
8
+ pass
9
+ def display_tournament(self):
10
+ pass
src/logger.py CHANGED
@@ -23,7 +23,7 @@ class logger:
23
  pass
24
 
25
  #Internal Work
26
- def get_stockfish_results(self, prev_state: str, current_state: str, depth: int = 5) -> float: #Should be refactored to only need one UCI current state
27
  #returns the stockfish analysis of the last move as a positive float
28
  #Example URL: https://stockfish.online/api/stockfish.php?fen=r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11&depth=5&mode=eval
29
  current_FEN = "?fen=" + current_state
@@ -32,19 +32,37 @@ class logger:
32
  endpoint = "https://stockfish.online/api/stockfish.php"
33
  current_extra = current_FEN + "&depth=" + str(depth) + "&mode=eval"
34
  prev_extra = prev_FEN + "&depth=" + str(depth) + "&mode=eval"
35
- current_response = str(requests.get(endpoint + current_extra))
36
- prev_response = str(requests.get(endpoint + prev_extra))
37
 
38
- current_score = float(re.findall(r"-?\d*\.*\d+", current_response)[0]) #Positive means white is winning and vice versa
39
- prev_score = float(re.findall(r"-?\d*\.*\d+", prev_response)[0])
 
 
 
40
 
41
 
42
- return abs(current_score) - abs(prev_score)
43
  def format_game(self):
44
  pass
45
 
46
  #Interface with game_database
47
- def return_formatted_game(self, game_num: int):
48
  pass
 
 
 
 
49
 
 
 
 
 
 
 
 
 
 
 
 
50
 
 
23
  pass
24
 
25
  #Internal Work
26
+ def get_stockfish_results(self, prev_state: str, current_state: str, depth: int = 5) -> float: #Takes current and previous FEN states. Can be refactored to only need one UCI current state
27
  #returns the stockfish analysis of the last move as a positive float
28
  #Example URL: https://stockfish.online/api/stockfish.php?fen=r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11&depth=5&mode=eval
29
  current_FEN = "?fen=" + current_state
 
32
  endpoint = "https://stockfish.online/api/stockfish.php"
33
  current_extra = current_FEN + "&depth=" + str(depth) + "&mode=eval"
34
  prev_extra = prev_FEN + "&depth=" + str(depth) + "&mode=eval"
35
+ current_response = requests.get(endpoint + current_extra)
36
+ prev_response = requests.get(endpoint + prev_extra)
37
 
38
+ current_string = str(current_response.json())
39
+ prev_string = str(prev_response.json())
40
+
41
+ current_score = float(re.findall(r"-?\d*\.*\d+", current_string)[0]) #Positive means white is winning and vice versa
42
+ prev_score = float(re.findall(r"-?\d*\.*\d+", prev_string)[0])
43
 
44
 
45
+ return abs(current_score) - abs(prev_score) #Positive numbers mean the player that made the move is better off
46
  def format_game(self):
47
  pass
48
 
49
  #Interface with game_database
50
+ def return_formatted_game(self):
51
  pass
52
+ """
53
+ if self.winner == "":
54
+ raise RuntimeError("Game is not yet completed")
55
+ pass
56
 
57
+ else:
58
+ game = {"UCI": self.current_moves, "Cheat Attempts": self.cheat_attempts}
59
+ return game
60
+ """
61
+
62
+ #Testing section
63
+ if __name__ == "__main__":
64
+ new_logger = logger("ChessGPT", "ChatGPT")
65
+ current_board = "r2q1rk1/1pp2ppp/3bbn2/p2p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11" #make sure to include the additional notation at the end
66
+ prev_board = "r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11"
67
+ print(str(new_logger.get_stockfish_results(prev_board, current_board)))
68