late commit; add: general bugfixes
This commit is contained in:
+25
-17
@@ -27,7 +27,7 @@ error = 0
|
||||
# 3 - index/position occupied
|
||||
|
||||
def init():
|
||||
global end, turn
|
||||
global end, turn, pf
|
||||
|
||||
# prerequisite 01 -> clear the screen
|
||||
clearScreen()
|
||||
@@ -74,6 +74,13 @@ def clearScreen():
|
||||
if os.name == "nt":
|
||||
os.system("cls")
|
||||
|
||||
def inBound(a, b, c, d):
|
||||
global pf
|
||||
|
||||
if len(pf) <= a >= 0 or len(pf) <= b >= 0 and len(pf) <= c >= 0 or len(pf) <= d >= 0:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def gameState(pf, name1, name2):
|
||||
global error
|
||||
@@ -103,9 +110,9 @@ def check(pf):
|
||||
o += 1
|
||||
if pf[i][j] == 'x':
|
||||
x += 1
|
||||
if o >= 3:
|
||||
if o == 3:
|
||||
return 0
|
||||
elif x >= 3:
|
||||
elif x == 3:
|
||||
return 1
|
||||
if o < 3 or x < 3:
|
||||
o = x = 0
|
||||
@@ -118,9 +125,9 @@ def check(pf):
|
||||
o += 1
|
||||
if pf[j][i] == 'x':
|
||||
x += 1
|
||||
if o >= 3:
|
||||
if o == 3:
|
||||
return 0
|
||||
elif x >= 3:
|
||||
elif x == 3:
|
||||
return 1
|
||||
if o < 3 or x < 3:
|
||||
o = x = 0
|
||||
@@ -131,32 +138,32 @@ def check(pf):
|
||||
if pf[i][j] == 'o':
|
||||
# only 6 possibilities, so the program will try all of them
|
||||
try:
|
||||
if pf[i-1][j-1] == 'o' and pf[i-2][j-2] == 'o':
|
||||
if pf[i-1][j-1] == 'o' and pf[i-2][j-2] == 'o' and inBound(i-1, j-1, i-2, j-2) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j+1] == 'o' and pf[i-2][j+2] == 'o':
|
||||
if pf[i-1][j+1] == 'o' and pf[i-2][j+2] == 'o' and inBound(i-1, j+1, i-2, j+2) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i+1][j-1] == 'o' and pf[i+2][j-2] == 'o':
|
||||
if pf[i+1][j-1] == 'o' and pf[i+2][j-2] == 'o' and inBound(i+1, j-1, i+2, j-2) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i+1][j+1] == 'o' and pf[i+2][j+2] == 'o':
|
||||
if pf[i+1][j+1] == 'o' and pf[i+2][j+2] == 'o' and inBound(i+1, j+1, i+2, j+2) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j-1] == 'o' and pf[i+1][j+1] == 'o':
|
||||
if pf[i-1][j-1] == 'o' and pf[i+1][j+1] == 'o' and inBound(i-1, j-1, i+1, j+1) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j+1] == 'o' and pf[i+1][j-1] == 'o':
|
||||
if pf[i-1][j+1] == 'o' and pf[i+1][j-1] == 'o' and inBound(i-1, j+1, i+1, j-1) == 1:
|
||||
return 0
|
||||
except IndexError:
|
||||
continue
|
||||
@@ -164,33 +171,34 @@ def check(pf):
|
||||
for i in range(len(pf)):
|
||||
for j in range(len(pf)):
|
||||
if pf[i][j] == 'x':
|
||||
# only 6 possibilities, so the program will try all of them
|
||||
try:
|
||||
if pf[i-1][j-1] == 'x' and pf[i-2][j-2] == 'x':
|
||||
if pf[i-1][j-1] == 'x' and pf[i-2][j-2] == 'x' and inBound(i-1, j-1, i-2, j-2) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j+1] == 'x' and pf[i-2][j+2] == 'x':
|
||||
if pf[i-1][j+1] == 'x' and pf[i-2][j+2] == 'x' and inBound(i-1, j+1, i-2, j+2) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i+1][j-1] == 'x' and pf[i+2][j-2] == 'x':
|
||||
if pf[i+1][j-1] == 'x' and pf[i+2][j-2] == 'x' and inBound(i+1, j-1, i+2, j-2) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i+1][j+1] == 'x' and pf[i+2][j+2] == 'x':
|
||||
if pf[i+1][j+1] == 'x' and pf[i+2][j+2] == 'x' and inBound(i+1, j+1, i+2, j+2) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j-1] == 'x' and pf[i+1][j+1] == 'x':
|
||||
if pf[i-1][j-1] == 'x' and pf[i+1][j+1] == 'x' and inBound(i-1, j-1, i+1, j+1) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
try:
|
||||
if pf[i-1][j+1] == 'x' and pf[i+1][j-1] == 'x':
|
||||
if pf[i-1][j+1] == 'x' and pf[i+1][j-1] == 'x' and inBound(i-1, j+1, i+1, j-1) == 1:
|
||||
return 1
|
||||
except IndexError:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user