Inkcap commited on
Commit
9115421
·
1 Parent(s): 6ff217d

Tested game_database, began analytics

Browse files
Files changed (3) hide show
  1. requirements.txt +3 -1
  2. src/game_database.py +36 -2
  3. src/logger.py +27 -12
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  #To download requirements, use 'python -m pip install -r requirements.txt'
2
- #python-chess==1.10.0
 
 
 
1
  #To download requirements, use 'python -m pip install -r requirements.txt'
2
+ python-chess==1.10.0
3
+ matplotlib==3.8.2
4
+ requests==2.28.2
src/game_database.py CHANGED
@@ -1,10 +1,44 @@
1
  import chess
 
 
 
 
2
 
3
- class game_database:
4
  def __init__(self):
 
5
  pass
6
 
 
 
 
7
  def display_game(self, game_num: int): #Displays analytics for a specific game
8
  pass
9
  def display_tournament(self): #Displays analytics for the entire tournament
10
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import chess
2
+ import matplotlib.pyplot as pyplot
3
+ import pandas as pd
4
+ from typing import Dict
5
+ from logger import Logger
6
 
7
+ class GameDatabase:
8
  def __init__(self):
9
+ self.db = []
10
  pass
11
 
12
+ def add_game(self, game: Dict[str, str]):
13
+ self.db.append(game)
14
+
15
  def display_game(self, game_num: int): #Displays analytics for a specific game
16
  pass
17
  def display_tournament(self): #Displays analytics for the entire tournament
18
+
19
+ df = pd.DataFrame(self.db)
20
+ print(df)
21
+
22
+ #heatmap of tournament winrates
23
+
24
+ #bar chart of tournament winrates
25
+
26
+ pass
27
+
28
+ if __name__ == "__main__":
29
+ test_logger = Logger("ChessGPT", "ChatGPT")
30
+ test_logger.add_cheat("ChessGPT")
31
+ test_logger.add_legal_move("e4")
32
+ test_logger.add_checkmate("ChessGPT")
33
+ #test_logger.add_legal_move("e4 e5")
34
+ formatted = test_logger.return_formatted_game()
35
+
36
+ test_logger_2 = Logger("ChessGPT", "BERT")
37
+ test_logger_2.add_checkmate("BERT")
38
+ formatted_2 = test_logger_2.return_formatted_game()
39
+
40
+ db = GameDatabase()
41
+ db.add_game(formatted)
42
+ db.add_game(formatted_2)
43
+
44
+ db.display_tournament()
src/logger.py CHANGED
@@ -1,25 +1,36 @@
1
  import requests
2
  import re
3
 
4
- class logger:
5
  def __init__(self, model_1: str, model_2: str):
6
  self.model_1 = model_1
7
  self.model_2 = model_2
8
-
9
- current_moves = "" #UCI notation
10
- cheat_attempts = [0] #logs the number of cheat attempts for every move in order
11
- winner = ""
12
 
13
  #Interface with the Model Interface
14
  def add_legal_move(self, current_moves: str): #current_moves should be all moves so far, in UCI notation
15
- self.current_moves = current_moves
16
- self.cheat_attempts.append(0)
17
-
 
 
 
18
  def add_cheat(self, cheater_name: str):
19
- self.cheat_attempts[-1] += 1
 
 
 
20
 
21
  def add_checkmate(self, winner_name: str):
22
- self.winner = winner_name
 
 
 
 
 
23
 
24
 
25
  #Internal Work
@@ -54,12 +65,16 @@ class logger:
54
  pass
55
 
56
  else:
57
- game = {"UCI": self.current_moves, "Cheat Attempts": self.cheat_attempts}
 
 
 
 
58
  return game
59
 
60
  #Testing section
61
  if __name__ == "__main__":
62
- new_logger = logger("ChessGPT", "ChatGPT")
63
  current_board = "r2q1rk1/1pp2ppp/3bbn2/p2p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11" #make sure to include the additional notation at the end
64
  prev_board = "r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11"
65
  print(str(new_logger.get_stockfish_results(prev_board, current_board)))
 
1
  import requests
2
  import re
3
 
4
+ class Logger:
5
  def __init__(self, model_1: str, model_2: str):
6
  self.model_1 = model_1
7
  self.model_2 = model_2
8
+ self.current_moves = ""
9
+ self.cheat_attempts = [0]
10
+ self.winner = ""
11
+ self.checkmate = False
12
 
13
  #Interface with the Model Interface
14
  def add_legal_move(self, current_moves: str): #current_moves should be all moves so far, in UCI notation
15
+ if self.checkmate:
16
+ raise RuntimeError("This game has already reached checkmate")
17
+ else:
18
+ self.current_moves = current_moves
19
+ self.cheat_attempts.append(0)
20
+
21
  def add_cheat(self, cheater_name: str):
22
+ if self.checkmate:
23
+ raise RuntimeError("This game has already reached checkmate")
24
+ else:
25
+ self.cheat_attempts[-1] += 1
26
 
27
  def add_checkmate(self, winner_name: str):
28
+ if winner_name != self.model_1 and winner_name != self.model_2:
29
+ raise RuntimeError("Not a valid winner for this logger")
30
+ else:
31
+ self.winner = winner_name
32
+ self.checkmate = True
33
+
34
 
35
 
36
  #Internal Work
 
65
  pass
66
 
67
  else:
68
+ game = {"Model 1": self.model_1,
69
+ "Model 2": self.model_2,
70
+ "Winner": self.winner,
71
+ "UCI": self.current_moves,
72
+ "Cheat Attempts": self.cheat_attempts}
73
  return game
74
 
75
  #Testing section
76
  if __name__ == "__main__":
77
+ new_logger = Logger("ChessGPT", "ChatGPT")
78
  current_board = "r2q1rk1/1pp2ppp/3bbn2/p2p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11" #make sure to include the additional notation at the end
79
  prev_board = "r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11"
80
  print(str(new_logger.get_stockfish_results(prev_board, current_board)))