Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created September 21, 2017 21:56
Show Gist options
  • Select an option

  • Save Gwith/65a693bd86bd9e2704f9201975df8eb9 to your computer and use it in GitHub Desktop.

Select an option

Save Gwith/65a693bd86bd9e2704f9201975df8eb9 to your computer and use it in GitHub Desktop.
import random
ai_marker = 'X'
matrix = [
['7', '8', '9'],
['4', '5', '6'],
['1', '2', '3']
]
marked_spots = []
tries = 0
while (tries != 1):
location = random.choice(list(range(1, 9)))
for i, row in enumerate(matrix):
for j, value in enumerate(row):
if (location != 'X') and (location != 'O') and (location not in marked_spots) and (value == location):
matrix[i][j] = ai_marker
marked_spots.append(location)
tries += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment