Spaces:
Runtime error
Runtime error
Fixing print -> st.write after weird revert
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ generator = pipeline('text-generation', model='gpt2')
|
|
8 |
|
9 |
def cleanup_output(text, prompt):
|
10 |
section = text[len(prompt):len(prompt) + 7]
|
11 |
-
|
12 |
valid_letters = ['A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h']
|
13 |
valid_pieces = ['p','P','k','K','q','Q','r','R','b','B', 'n', 'N']
|
14 |
valid_numbers = ['1','2','3','4','5','6','7','8']
|
@@ -79,39 +79,39 @@ class AInstance:
|
|
79 |
|
80 |
def verify_move(string):
|
81 |
board = chess.Board()
|
82 |
-
|
83 |
for move in string.split():
|
84 |
#if this move makes no sense it will return false and the game will try again to generate a good move
|
85 |
try:
|
86 |
board.push_san(move)
|
87 |
except:
|
88 |
-
|
89 |
return False
|
90 |
if(board.is_valid):
|
91 |
-
|
92 |
return True
|
93 |
return False
|
94 |
|
95 |
def check_mate(string):
|
96 |
#simulates mate idk
|
97 |
if(random.randrange(0,100) == 4):
|
98 |
-
|
99 |
return True
|
100 |
return False
|
101 |
|
102 |
def print_game(string):
|
103 |
-
|
104 |
|
105 |
def make_move(instance, game_state):
|
106 |
-
print("\n
|
107 |
return_state = game_state
|
108 |
return_state = instance.move(game_state)
|
109 |
game_ongoing = True
|
110 |
if(instance.check_if_end()):
|
111 |
-
|
112 |
game_ongoing = False
|
113 |
if(check_mate(return_state)):
|
114 |
-
|
115 |
game_ongoing = False
|
116 |
return(return_state, game_ongoing)
|
117 |
|
@@ -120,11 +120,11 @@ def main():
|
|
120 |
if(random.randrange(0,1)):
|
121 |
white = AInstance("gpt2", generator)
|
122 |
black = AInstance("gpt2-medium-chess", generator2)
|
123 |
-
|
124 |
else:
|
125 |
white = AInstance("gpt2-medium-chess", generator2)
|
126 |
black = AInstance("gpt2", generator)
|
127 |
-
|
128 |
|
129 |
game_state = "e4 e5"
|
130 |
game_ongoing = True
|
|
|
8 |
|
9 |
def cleanup_output(text, prompt):
|
10 |
section = text[len(prompt):len(prompt) + 7]
|
11 |
+
st.write("Proposed Move: " + section)
|
12 |
valid_letters = ['A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h']
|
13 |
valid_pieces = ['p','P','k','K','q','Q','r','R','b','B', 'n', 'N']
|
14 |
valid_numbers = ['1','2','3','4','5','6','7','8']
|
|
|
79 |
|
80 |
def verify_move(string):
|
81 |
board = chess.Board()
|
82 |
+
st.write("Board: " + string)
|
83 |
for move in string.split():
|
84 |
#if this move makes no sense it will return false and the game will try again to generate a good move
|
85 |
try:
|
86 |
board.push_san(move)
|
87 |
except:
|
88 |
+
st.write("Invalid Move\n")
|
89 |
return False
|
90 |
if(board.is_valid):
|
91 |
+
st.write("Valid Move\n")
|
92 |
return True
|
93 |
return False
|
94 |
|
95 |
def check_mate(string):
|
96 |
#simulates mate idk
|
97 |
if(random.randrange(0,100) == 4):
|
98 |
+
st.write("H")
|
99 |
return True
|
100 |
return False
|
101 |
|
102 |
def print_game(string):
|
103 |
+
st.write("Some kind of visualization for the chess board based on this string: " + string)
|
104 |
|
105 |
def make_move(instance, game_state):
|
106 |
+
print("\n" + instance.type + "s's move")
|
107 |
return_state = game_state
|
108 |
return_state = instance.move(game_state)
|
109 |
game_ongoing = True
|
110 |
if(instance.check_if_end()):
|
111 |
+
st.write("This player claims countr > 50: " + instance.type)
|
112 |
game_ongoing = False
|
113 |
if(check_mate(return_state)):
|
114 |
+
st.write("This player claims mates: " + instance.type)
|
115 |
game_ongoing = False
|
116 |
return(return_state, game_ongoing)
|
117 |
|
|
|
120 |
if(random.randrange(0,1)):
|
121 |
white = AInstance("gpt2", generator)
|
122 |
black = AInstance("gpt2-medium-chess", generator2)
|
123 |
+
st.write("Gpt2 is White and Gpt2 Optimized is Black")
|
124 |
else:
|
125 |
white = AInstance("gpt2-medium-chess", generator2)
|
126 |
black = AInstance("gpt2", generator)
|
127 |
+
st.write("Gpt2 is Black and Gpt2 Optimized is White")
|
128 |
|
129 |
game_state = "e4 e5"
|
130 |
game_ongoing = True
|