File size: 1,980 Bytes
00727a4
7d591ab
00727a4
 
 
 
 
 
7d591ab
 
00727a4
 
7d591ab
 
 
 
 
 
 
 
 
 
 
 
00727a4
7d591ab
 
00727a4
 
 
 
 
 
 
7d591ab
 
00727a4
7d591ab
 
 
00727a4
7d591ab
00727a4
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
import re

class logger:
    def __init__(self, model_1: str, model_2: str):
        self.model_1 = model_1
        self.model_2 = model_2

    current_moves = "" #UCI notation
    cheat_attempts = [0] #logs the number of cheat attempts for every move in order 
    winner = ""

    #Interface with the Model Interface
    def add_legal_move(self, current_moves: str): #current_moves should be all moves so far, in UCI notation
        self.current_moves = current_moves
        self.cheat_attempts.append(0)
        
    def add_cheat(self, cheater_name: str):
        self.cheat_attempts[-1] += 1

    def add_checkmate(self, winner_name: str):
        #logs the winner and stops recording
        pass

    #Internal Work
    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
        #returns the stockfish analysis of the last move as a positive float
        #Example URL: https://stockfish.online/api/stockfish.php?fen=r2q1rk1/ppp2ppp/3bbn2/3p4/8/1B1P4/PPP2PPP/RNB1QRK1 w - - 5 11&depth=5&mode=eval
        current_FEN = "?fen=" + current_state
        prev_FEN = "?fen=" + prev_state
        
        endpoint = "https://stockfish.online/api/stockfish.php"
        current_extra = current_FEN + "&depth=" + str(depth) + "&mode=eval"
        prev_extra = prev_FEN + "&depth=" + str(depth) + "&mode=eval"
        current_response = str(requests.get(endpoint + current_extra))
        prev_response = str(requests.get(endpoint + prev_extra))

        current_score = float(re.findall(r"-?\d*\.*\d+", current_response)[0]) #Positive means white is winning and vice versa
        prev_score = float(re.findall(r"-?\d*\.*\d+", prev_response)[0])
        
        
        return abs(current_score) - abs(prev_score)
    def format_game(self):
        pass

    #Interface with game_database
    def return_formatted_game(self, game_num: int):
        pass