From f7ebe11837f467472d0f1eaa6b6e8c4f056c83f4 Mon Sep 17 00:00:00 2001 From: Vincent Rodley Date: Tue, 12 Aug 2025 11:04:45 +1200 Subject: [PATCH] ok nvm now it takes free wins --- main.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 5117271..96b6750 100644 --- a/main.py +++ b/main.py @@ -79,9 +79,12 @@ def local_move_provider(player, board): return col def cpu_move_provider(player, board): + # start with a random move col = random.randint(0, 6) while 'O' not in board[col]: col += 1 + if col == 7: + col = 0 # prevent immediate wins other_p = 'Y' if player == 'R' else 'R' @@ -95,6 +98,17 @@ def cpu_move_provider(player, board): col = other_p_col break + # take wins + for possible_col in range(len(board)): + if 'O' not in board[possible_col]: + continue + + new_board = deepcopy(board) + new_board[possible_col][new_board[possible_col].index('O')] = player + if checkWin(new_board, player) != None: + col = possible_col + break + return col # =========================== @@ -150,8 +164,7 @@ def play_lan_client(): return def play_vs_computer(): - # play_game(cpu_move_provider, local_move_provider) - play_game(local_move_provider, cpu_move_provider) + play_game(cpu_move_provider, local_move_provider) # =========================== # | Menu |