Inkcap commited on
Commit
7d591ab
1 Parent(s): 00727a4

Updated diagram

Browse files
README.md CHANGED
@@ -12,4 +12,4 @@ license: cc-by-4.0
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
- ![Alt text](mermaid-diagram-2024-01-15-121058-1.png)
 
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
+ ![Alt text](mermaid-diagram-2024-01-16-104433.png)
architecture_diagram.md CHANGED
@@ -4,22 +4,22 @@ config:
4
  flowchart:
5
  defaultRenderer: elk
6
  ---
7
- flowchart TB
8
  interface(Model \n Interface)
9
  model(Chosen Model)
10
- logger(Logger)
11
  coordinator(Game \n Coordinator)
12
  database("Game Database \n display_analytics()")
13
 
14
- coordinator --model_vs_model(model names)-->interface
15
- coordinator --human_vs_model(model name) -->interface
16
 
17
  interface --send_move(model_name, UCI_notation) \n returns response-->model
18
 
19
- interface --create(model_names) \n creates a few logger for each game--> logger
20
- interface --new_move(FEN_notation)-->logger
21
- interface--cheated(model_name)-->logger
22
- interface--checkmate(winner)-->logger
23
 
24
- logger --add_game(game_in_FEN, time_of_cheating)-->database
25
  ```
 
4
  flowchart:
5
  defaultRenderer: elk
6
  ---
7
+ flowchart LR
8
  interface(Model \n Interface)
9
  model(Chosen Model)
10
+ logger("Logger\nget_stockfish_results()")
11
  coordinator(Game \n Coordinator)
12
  database("Game Database \n display_analytics()")
13
 
14
+ coordinator --model_vs_model(model_1: str, model_2:str)-->interface
15
+ coordinator --human_vs_model(model name: str) -->interface
16
 
17
  interface --send_move(model_name, UCI_notation) \n returns response-->model
18
 
19
+ interface --create(model_1: str, model_2: str) \n creates a few logger for each game--> logger
20
+ interface --add_legal_move(UCI_notation_of_game: str)-->logger
21
+ interface--add_cheat(cheater_name: str)-->logger
22
+ interface--add_checkmate(winner_name: str)-->logger
23
 
24
+ logger --return_formatted_game(game_in_UCI: str, cheat_log: [int])-->database
25
  ```
mermaid-diagram-2024-01-15-121058-1.png DELETED
Binary file (48.2 kB)
 
mermaid-diagram-2024-01-15-121058.png DELETED
Binary file (48.2 kB)
 
mermaid-diagram-2024-01-16-104433.png ADDED
src/logger.py CHANGED
@@ -1,17 +1,30 @@
1
  import requests
 
2
 
3
  class logger:
4
  def __init__(self, model_1: str, model_2: str):
5
  self.model_1 = model_1
6
  self.model_2 = model_2
7
 
8
- current_moves = "" #FEN notation
9
- cheat_attempts = "" #format?
10
  winner = ""
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  #Internal Work
13
- def get_stockfish_results(self, prev_state: str, current_state: str, depth: int = 5) -> float:
14
- #returns the stockfish analysis of the last move
15
  #Example URL: https://stockfish.online/api/stockfish.php?fen=r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11&depth=5&mode=eval
16
  current_FEN = "?fen=" + current_state
17
  prev_FEN = "?fen=" + prev_state
@@ -19,26 +32,17 @@ class logger:
19
  endpoint = "https://stockfish.online/api/stockfish.php"
20
  current_extra = current_FEN + "&depth=" + str(depth) + "&mode=eval"
21
  prev_extra = prev_FEN + "&depth=" + str(depth) + "&mode=eval"
22
- current_response = requests.get(endpoint + current_extra)
23
- prev_response = requests.get(endpoint + prev_extra)
24
 
25
- #response format is: {'success': True, 'data': 'Total evaluation: -1.79 (white side)'}
 
 
26
 
27
- #return current_score - prev_score
28
  def format_game(self):
29
  pass
30
 
31
- #Interface with the Model Interface
32
- def add_legal_move(self, current_moves: str): #current_moves should be all moves so far, in FEN notation
33
- #updates sequence of moves stored
34
- pass
35
- def add_cheat(self, cheater_name: str):
36
- #adds cheats parallel to the sequence of moves
37
- pass
38
- def add_checkmate(self, winner_name: str):
39
- #logs the winner and stops recording
40
- pass
41
-
42
  #Interface with game_database
43
  def return_formatted_game(self, game_num: int):
44
  pass
 
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
+ #logs the winner and stops recording
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
30
  prev_FEN = "?fen=" + prev_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 = 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