Refactor bot server setup to use Waitress for production; fallback to Flask dev server for local development. Added timeout to HTTP requests in Fun and Test cogs. Improved error handling for missing environment variables. Enhanced secret key management in Flask app. Added request timeout configuration. Introduced new experimental features including user profile and balance cards, and a Tic-Tac-Toe game with Minimax AI. Addressed various database and security issues, and improved code quality across multiple files.

This commit is contained in:
2026-05-31 12:01:12 +00:00
parent be89cc3acd
commit 1b91cbcb2f
17 changed files with 284 additions and 61 deletions
+93
View File
@@ -0,0 +1,93 @@
import random
win_states = [
(0, 1, 2), (3, 4, 5), (6, 7, 8), # horizontal
(0, 3, 6), (1, 4, 7), (2, 5, 8), # vertical
(0, 4, 8), (2, 4, 6) # diagonal
]
def Terminal(state: list):
for win_state in win_states:
if all(state[i] == "O" for i in win_state) or all(state[i] == "X" for i in win_state):
return True
if state.count(" ") == 0:
return True
else:
return False
def Value(state):
for win_state in win_states:
if all(state[i] == "O" for i in win_state):
return -1
elif all(state[i] == "X" for i in win_state):
return 1
if state.count(" ") == 0:
return 0
def Player(state: list):
if state.count("X") == state.count("O"):
return "X"
else:
return "O"
def Actions(state):
indexes = []
for i in range(9):
if state[i] == " ":
indexes.append(i)
return indexes
def Result(state, index, player):
state[index] = player
return state
def Minimax(state):
if Terminal(state):
return Value(state)
if Player(state) == "X":
value = -9999
for a in Actions(state):
value = max(value, Minimax(Result(state.copy(), a, "X")))
return value
elif Player(state) == "O":
value = 9999
for a in Actions(state):
value = min(value, Minimax(Result(state.copy(), a, "O")))
return value
def aiO(state):
best_score = float('inf')
best_move = None
for move in Actions(state):
state[move] = 'O'
score = Minimax(state)
state[move] = ' '
if score < best_score:
best_score = score
best_move = move
return best_move
def aiX(state):
best_score = float('-inf')
best_move = None
for move in Actions(state):
state[move] = 'X'
score = Minimax(state)
state[move] = ' '
if score > best_score:
best_score = score
best_move = move
return best_move
def aiRandom(state):
return random.choice(Actions(state))