Skip to content

Commit f66531e

Browse files
committed
Merge pull request #2 from Benjamintf1/NoPrints
YEAH
2 parents ca6cf9e + c872dac commit f66531e

File tree

1 file changed

+113
-122
lines changed

1 file changed

+113
-122
lines changed

TicTacToe.py

Lines changed: 113 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,131 +3,122 @@
33
import os #for making folders and links
44

55
os.mkdir("Moves")
6-
for x in range(0,(19684)): #should be 3^9 possibilities 3, possibilities for 9 squares
7-
os.mkdir("Moves/" + str(x)) #Make directories for gamestate so they can be moved into and linked to
8-
os.symlink("Moves/0", "START") #link's to first state
6+
for x in range(0,(19684)): #should be 3^9 possibilities 3, possibilities for 9 squares
7+
os.mkdir("Moves/" + str(x)) #Make directories for gamestate so they can be moved into and linked to
8+
os.symlink("Moves/0", "START") #link's to first state
99

1010
os.chdir("Moves") #yeah, way better then borking your system
1111
os.mkdir("Invalid_Move") #folder for invalid moves
1212
open("Invalid_Move/Invalid_Move", 'w').close()
13-
for gamestate in range(19684): #create gamestate's
14-
board = [] #gamestate as a list
15-
os.chdir(str(gamestate)) #Get ready to make gamestate
16-
print(os.getcwd()) #tells debugger where they are
17-
for square in range(0,9):
18-
board.append((gamestate/(3**square))%3) #gamestate is in ternary
19-
numo = 0 #num of O's
20-
numx = 0 #num of X's
21-
numun = 0 #num of un-used squares
13+
for gamestate in range(19684):
14+
if (gamestate % 703) == 0:
15+
print(str(gamestate/703) + " / 28 done")#create gamestate's
16+
board = [] #gamestate as a list
17+
os.chdir(str(gamestate)) #Get ready to make gamestate
18+
for square in range(0,9):
19+
board.append((gamestate/(3**square))%3) #gamestate is in ternary
20+
numo = 0 #num of O's
21+
numx = 0 #num of X's
22+
numun = 0 #num of un-used squares
2223

23-
for x in board: #count to figure out who's turn it is
24-
if x == 2:
25-
numo += 1
26-
elif x == 1:
27-
numx += 1
28-
else:
29-
numun += 1
30-
#1 = player1
31-
#2 = player2
32-
#3 = Invalid State
33-
#4 = no moves left
34-
#5 = winnerx
35-
#6 = winnero
36-
print("numx: " + str(numx)) #debugger count
37-
print("numo: " + str(numo))
38-
print("numun: " + str(numun))
39-
print(board)
40-
41-
if numx == numo: #Checks who's turn it is/for invalid states
42-
PlayersTurn = 1
43-
elif (numun == 0):
44-
PlayersTurn = 4
45-
elif numx == (numo + 1):
46-
PlayersTurn = 2
47-
else:
48-
PlayersTurn = 3
49-
50-
#Screw it, I'll do 8 checks by hand checks for winning
51-
if (PlayersTurn != 3):
52-
if (board[0] == board[1] == board[2] != 0):
53-
if (numx == numo):
54-
PlayersTurn=6
55-
else:
56-
PlayersTurn=5
57-
elif (board[3] == board[4] == board[5] != 0):
58-
if (numx == numo):
59-
PlayersTurn=6
60-
else:
61-
PlayersTurn=5
62-
elif (board[6] == board[7] == board[8] != 0):
63-
if (numx == numo):
64-
PlayersTurn=6
65-
else:
66-
PlayersTurn=5
67-
elif (board[0] == board[3] == board[6] != 0):
68-
if (numx == numo):
69-
PlayersTurn=6
70-
else:
71-
PlayersTurn=5
72-
elif (board[1] == board[4] == board[7] != 0):
73-
if (numx == numo):
74-
PlayersTurn=6
75-
else:
76-
PlayersTurn=5
77-
elif (board[2] == board[5] == board[8] != 0):
78-
if (numx == numo):
79-
PlayersTurn=6
24+
for x in board: #count to figure out who's turn it is
25+
if x == 2:
26+
numo += 1
27+
elif x == 1:
28+
numx += 1
8029
else:
81-
PlayersTurn=5
82-
elif (board[0] == board[4] == board[8] != 0):
83-
if (numx == numo):
84-
PlayersTurn=6
85-
else:
86-
PlayersTurn=5
87-
elif (board[2] == board[4] == board[6] != 0):
88-
if (numx == numo):
89-
PlayersTurn=6
90-
else:
91-
PlayersTurn=5
92-
93-
if PlayersTurn < 3:
94-
for makelinks in range(0,9): #make the board if not winner
95-
filename = ""
96-
if board[makelinks] == 0:
97-
98-
filename = str(makelinks) + "--"
99-
linknum = 0
100-
101-
for x in range(0,9):
102-
if x == makelinks:
103-
linknum += PlayersTurn * 3**x
104-
else:
105-
linknum += board[x] * 3**x
106-
os.symlink("../" + str(linknum), filename)
107-
108-
elif board[makelinks] == 1:
109-
filename = str(makelinks) + "X"
110-
os.symlink("../Invalid_Move", filename)
111-
else:
112-
filename = str(makelinks) + "O"
113-
os.symlink("../Invalid_Move", filename)
114-
else:
115-
if (PlayersTurn == 3): #makes end game files and a link to initial state
116-
open("cheater", 'w').close()
117-
os.symlink("../0", "Play_Again?")
118-
elif (PlayersTurn == 4):
119-
open("cats game", 'w').close()
120-
os.symlink("../0", "Play_Again?")
121-
elif (PlayersTurn == 5):
122-
open("X wins!!", 'w').close()
123-
os.symlink("../0", "Play_Again?")
124-
elif (PlayersTurn == 6):
125-
open("O wins!!", 'w').close()
126-
os.symlink("../0", "Play_Again?")
127-
print("end of game")
128-
os.chdir("..") #gets ready for making next game state
129-
130-
131-
132-
133-
30+
numun += 1
31+
#1 = player1
32+
#2 = player2
33+
#3 = Invalid State
34+
#4 = no moves left
35+
#5 = winnerx
36+
#6 = winnero
37+
38+
if numx == numo: #Checks who's turn it is/for invalid states
39+
PlayersTurn = 1
40+
elif (numun == 0):
41+
PlayersTurn = 4
42+
elif numx == (numo + 1):
43+
PlayersTurn = 2
44+
else:
45+
PlayersTurn = 3
46+
47+
#Screw it, I'll do 8 checks by hand checks for winning
48+
if (PlayersTurn != 3):
49+
if (board[0] == board[1] == board[2] != 0):
50+
if (numx == numo):
51+
PlayersTurn=6
52+
else:
53+
PlayersTurn=5
54+
elif (board[3] == board[4] == board[5] != 0):
55+
if (numx == numo):
56+
PlayersTurn=6
57+
else:
58+
PlayersTurn=5
59+
elif (board[6] == board[7] == board[8] != 0):
60+
if (numx == numo):
61+
PlayersTurn=6
62+
else:
63+
PlayersTurn=5
64+
elif (board[0] == board[3] == board[6] != 0):
65+
if (numx == numo):
66+
PlayersTurn=6
67+
else:
68+
PlayersTurn=5
69+
elif (board[1] == board[4] == board[7] != 0):
70+
if (numx == numo):
71+
PlayersTurn=6
72+
else:
73+
PlayersTurn=5
74+
elif (board[2] == board[5] == board[8] != 0):
75+
if (numx == numo):
76+
PlayersTurn=6
77+
else:
78+
PlayersTurn=5
79+
elif (board[0] == board[4] == board[8] != 0):
80+
if (numx == numo):
81+
PlayersTurn=6
82+
else:
83+
PlayersTurn=5
84+
elif (board[2] == board[4] == board[6] != 0):
85+
if (numx == numo):
86+
PlayersTurn=6
87+
else:
88+
PlayersTurn=5
89+
if PlayersTurn < 3:
90+
for makelinks in range(0,9): #make the board if not winner
91+
filename = ""
92+
if board[makelinks] == 0:
93+
94+
filename = str(makelinks) + "--"
95+
linknum = 0
96+
97+
for x in range(0,9):
98+
if x == makelinks:
99+
linknum += PlayersTurn * 3**x
100+
else:
101+
linknum += board[x] * 3**x
102+
os.symlink("../" + str(linknum), filename)
103+
104+
elif board[makelinks] == 1:
105+
filename = str(makelinks) + "X"
106+
os.symlink("../Invalid_Move", filename)
107+
else:
108+
filename = str(makelinks) + "O"
109+
os.symlink("../Invalid_Move", filename)
110+
else:
111+
if (PlayersTurn == 3): #makes end game files and a link to initial state
112+
open("cheater", 'w').close()
113+
os.symlink("../0", "Play_Again?")
114+
elif (PlayersTurn == 4):
115+
open("cats game", 'w').close()
116+
os.symlink("../0", "Play_Again?")
117+
elif (PlayersTurn == 5):
118+
open("X wins!!", 'w').close()
119+
os.symlink("../0", "Play_Again?")
120+
elif (PlayersTurn == 6):
121+
open("O wins!!", 'w').close()
122+
os.symlink("../0", "Play_Again?")
123+
os.chdir("..") #gets ready for making next game state
124+

0 commit comments

Comments
 (0)