ok nvm now it takes free wins
This commit is contained in:
parent
de0ad5a005
commit
f7ebe11837
17
main.py
17
main.py
|
|
@ -79,9 +79,12 @@ def local_move_provider(player, board):
|
||||||
return col
|
return col
|
||||||
|
|
||||||
def cpu_move_provider(player, board):
|
def cpu_move_provider(player, board):
|
||||||
|
# start with a random move
|
||||||
col = random.randint(0, 6)
|
col = random.randint(0, 6)
|
||||||
while 'O' not in board[col]:
|
while 'O' not in board[col]:
|
||||||
col += 1
|
col += 1
|
||||||
|
if col == 7:
|
||||||
|
col = 0
|
||||||
|
|
||||||
# prevent immediate wins
|
# prevent immediate wins
|
||||||
other_p = 'Y' if player == 'R' else 'R'
|
other_p = 'Y' if player == 'R' else 'R'
|
||||||
|
|
@ -95,6 +98,17 @@ def cpu_move_provider(player, board):
|
||||||
col = other_p_col
|
col = other_p_col
|
||||||
break
|
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
|
return col
|
||||||
|
|
||||||
# ===========================
|
# ===========================
|
||||||
|
|
@ -150,8 +164,7 @@ def play_lan_client():
|
||||||
return
|
return
|
||||||
|
|
||||||
def play_vs_computer():
|
def play_vs_computer():
|
||||||
# play_game(cpu_move_provider, local_move_provider)
|
play_game(cpu_move_provider, local_move_provider)
|
||||||
play_game(local_move_provider, cpu_move_provider)
|
|
||||||
|
|
||||||
# ===========================
|
# ===========================
|
||||||
# | Menu |
|
# | Menu |
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user