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:
Executable
+68
@@ -0,0 +1,68 @@
|
||||
from random import randint
|
||||
|
||||
"""def player(start_board):
|
||||
player_choice = input("Pick a place: ")
|
||||
if start_board.count(player_choice) == 1:
|
||||
start_board[start_board.index(player_choice)] = "X"
|
||||
else:
|
||||
player(start_board)"""
|
||||
|
||||
|
||||
def player(start_board):
|
||||
com_choice = str(randint(1, 9))
|
||||
if start_board.count(com_choice) == 1:
|
||||
start_board[start_board.index(com_choice)] = "X"
|
||||
else:
|
||||
player(start_board)
|
||||
|
||||
|
||||
def com(start_board):
|
||||
com_choice = str(randint(1, 9))
|
||||
if start_board.count(com_choice) == 1:
|
||||
start_board[start_board.index(com_choice)] = "O"
|
||||
else:
|
||||
com(start_board)
|
||||
|
||||
|
||||
def print_board(s_board):
|
||||
board = "".join(s_board)
|
||||
print(board)
|
||||
|
||||
|
||||
def check(s_b):
|
||||
if s_b[0] == s_b[2] == s_b[4] == 'X' or s_b[6] == s_b[8] == s_b[10] == 'X' or s_b[12] == s_b[14] == s_b[16] == 'X' \
|
||||
or s_b[0] == s_b[6] == s_b[12] == 'X' or s_b[2] == s_b[8] == s_b[14] == 'X' or s_b[4] == s_b[10] == s_b[16] \
|
||||
== 'X' or s_b[0] == s_b[8] == s_b[16] == 'X' or s_b[4] == s_b[8] == s_b[12] == 'X':
|
||||
print("you won")
|
||||
main()
|
||||
elif s_b[0] == s_b[2] == s_b[4] == 'O' or s_b[6] == s_b[8] == s_b[10] == 'O' or s_b[12] == s_b[14] == s_b[16] == 'O' \
|
||||
or s_b[0] == s_b[6] == s_b[12] == 'O' or s_b[2] == s_b[8] == s_b[14] == 'O' or s_b[4] == s_b[10] == s_b[16] \
|
||||
== 'O' or s_b[0] == s_b[8] == s_b[16] == 'O' or s_b[4] == s_b[8] == s_b[12] == 'O':
|
||||
print('computer won')
|
||||
print_board(s_b)
|
||||
main()
|
||||
|
||||
|
||||
def main():
|
||||
# main program
|
||||
start_board = ["1", "|", "2", "|", "3", "\n",
|
||||
"4", "|", "5", "|", "6", "\n",
|
||||
"7", "|", "8", "|", "9", "\n", ]
|
||||
print_board(start_board)
|
||||
while 1:
|
||||
try:
|
||||
player(start_board)
|
||||
check(start_board)
|
||||
|
||||
com(start_board)
|
||||
check(start_board)
|
||||
|
||||
print_board(start_board)
|
||||
except RecursionError:
|
||||
print_board(start_board)
|
||||
print("draw")
|
||||
main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user