You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Code-Sleep-Python/tic-tac-toe/code.py
+55-50Lines changed: 55 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,44 @@
1
1
importnumpyasnp
2
+
importrandom
3
+
importtime
4
+
importmatplotlib.pyplotasplt
5
+
6
+
2
7
defcreate_board():
3
-
x=np.zeros((3,3))
8
+
x=np.zeros((3,3))
4
9
returnx
5
10
6
11
board=create_board()
7
12
13
+
14
+
defplace(board, player, position):
15
+
ifboard[position] ==0:
16
+
board[position] =player
17
+
returnboard
18
+
19
+
8
20
defpossibilities(board):
9
-
y=np.where(board==0 ) #it gives the indices wherever there are zeros in the form of 2 seperate arrays in a tuple. (array([0, 0, 1, 1, 1, 2, 2, 2]), array([1, 2, 0, 1, 2, 0, 1, 2]))
10
-
y=np.array(y) # convert it into array.
11
-
z=list(map(tuple, np.transpose(y))) #transpose it to get [0,1],[0,2],[1,0] ... and so on. Then using map function convert each of them to tuple. And keep it totally as a list.
21
+
# it gives the indices wherever there are zeros in the form of 2 seperate
0 commit comments