mardi 14 juin 2016

Defensive TicTacToe computer Python


I am trying to figure out why my tic tac toe game will not play defensively, I'm not so familiar with Stackoverflow. So if you need more information please let me know and I will give you more code.

def play_defense(board, player):

This is the for loop for going through the board and looking for if I am in a position to win and to block me but its not doing it.

for i in [1,2,3]:
    if board[i] == player and board[i+3] == player and board[i+6] == " ":
        return i+6
    if board[i+3] == player and board[i+6] == player and board[i] == " ":
        return i
    if board[i] == player and board[i+6] == player and board[i+3] == " ":
        return i+3

Aucun commentaire:

Enregistrer un commentaire