fix: general bugfixes

This commit is contained in:
mnjx
2023-03-09 21:33:59 -10:00
parent 0a9d91af04
commit 723867ac65
2 changed files with 44 additions and 128 deletions
+22 -64
View File
@@ -1,10 +1,8 @@
# TODO - __DONE__ variable symbol count needed to win
# - __DONE__ selecting the position of the new symbol by moving a cursor with arrow keys inside the playfield, press space to place the symbol
# - __DONE__ when a game ends, the winning symbols will blink a few times
# TODO -
# add: variable symbol count needed to win, selecting the position of the new symbol by moving a cursor with arrow keys inside the playfield, press space to place the symbol, when a game ends, the winning symbols will blink a few times
# add:
# fix: general bugfixes
# update: comments
# update:
# algorithm steps
#
@@ -137,6 +135,8 @@ def _print(pf, name1, name2, blink = 0):
print("o won!")
elif blink == 3:
print("x won!")
elif blink == 4:
print("Draw!")
print(name1, "(o) vs", name2, "(x)")
for i in range(len(pf)):
@@ -175,6 +175,8 @@ def gameState(pf, name1, name2, blink = 0):
_print(pf, name1, name2, 2)
elif blink == 3:
_print(pf, name1, name2, 3)
elif blink == 4:
_print(pf, name1, name2, 4)
# checks whether someone has won
def check(pf):
@@ -255,106 +257,68 @@ def check(pf):
for i in range(len(pf)):
for j in range(len(pf)):
if pf[i][j] == 'o':
try:
if pf[i-1][j-1] == 'o':
for k in range(symbolCount):
if pf[i-k][j-k] == 'o':
temp.append([i-k, j-k])
o += 1
else:
temp = []
o = 0
except IndexError:
continue
try:
if pf[i-1][j+1] == 'o':
for k in range(symbolCount):
if pf[i-k][j+k] == 'o':
temp.append([i-k, j+k])
o += 1
else:
temp = []
o = 0
except IndexError:
continue
try:
if pf[i+1][j-1] == 'o':
for k in range(symbolCount):
if pf[i+k][j-k] == 'o':
if pf[i+k][j-k] == 'o' and 0 <= i+k < _size and 0 <= j-k < _size:
temp.append([i+k, j-k])
o += 1
else:
winLine = []
temp = []
o = 0
except IndexError:
continue
pass
try:
if pf[i+1][j+1] == 'o':
for k in range(symbolCount):
if pf[i+k][j+k] == 'o':
if pf[i+k][j+k] == 'o' and 0 <= i+k < _size and 0 <= j+k < _size:
temp.append([i+k, j+k])
o += 1
else:
winLine = []
temp = []
o = 0
except IndexError:
continue
pass
if o == symbolCount:
winLine = temp
return 0
elif o < symbolCount:
winLine = []
temp = []
o = 0
if pf[i][j] == 'x':
try:
if pf[i-1][j-1] == 'x':
for k in range(symbolCount):
if pf[i-k][j-k] == 'x':
temp.append([i-k, j-k])
x += 1
else:
temp = []
x = 0
except IndexError:
continue
try:
if pf[i-1][j+1] == 'x':
for k in range(symbolCount):
if pf[i-k][j+k] == 'x':
temp.append([i-k, j+k])
x += 1
else:
temp = []
x = 0
except IndexError:
continue
try:
if pf[i+1][j-1] == 'x':
for k in range(symbolCount):
if pf[i+k][j-k] == 'x':
if pf[i+k][j-k] == 'x' and 0 <= i+k < _size and 0 <= j-k < _size:
temp.append([i+k, j-k])
x += 1
else:
winLine = []
temp = []
x = 0
except IndexError:
continue
pass
try:
if pf[i+1][j+1] == 'x':
for k in range(symbolCount):
if pf[i+k][j+k] == 'x':
if pf[i+k][j+k] == 'x' and 0 <= i+k < _size and 0 <= j+k < _size:
temp.append([i+k, j+k])
x += 1
else:
winLine = []
temp = []
x = 0
except IndexError:
continue
pass
if x == symbolCount:
winLine = temp
return 1
elif x < symbolCount:
winLine = []
temp = []
x = 0
@@ -457,24 +421,18 @@ def gameRound(pf, name1, name2):
if won == 0:
# 5.1 -> if yes -> end the game
clearScreen()
gameState(pf, name1, name2, 1)
print("o won!")
gameState(pf, name1, name2, 2)
end = 1
# 5.2 -> if no -> jump to step 1
if won == 1:
clearScreen()
gameState(pf, name1, name2, 1)
print("x won!")
gameState(pf, name1, name2, 3)
end = 1
if won == 2:
clearScreen()
print("Draw!")
gameState(pf, name1, name2)
gameState(pf, name1, name2, 4)
end = 1
# driver code
@@ -1,10 +1,8 @@
# TODO - __DONE__ variable symbol count needed to win
# - __DONE__ selecting the position of the new symbol by moving a cursor with arrow keys inside the playfield, press space to place the symbol
# - __DONE__ when a game ends, the winning symbols will blink a few times
# TODO -
# add: variable symbol count needed to win, selecting the position of the new symbol by moving a cursor with arrow keys inside the playfield, press space to place the symbol, when a game ends, the winning symbols will blink a few times
# add:
# fix: general bugfixes
# update: comments
# update:
# algorithm steps
#
@@ -137,6 +135,8 @@ def _print(pf, name1, name2, blink = 0):
print("o won!")
elif blink == 3:
print("x won!")
elif blink == 4:
print("Draw!")
print(name1, "(o) vs", name2, "(x)")
for i in range(len(pf)):
@@ -175,6 +175,8 @@ def gameState(pf, name1, name2, blink = 0):
_print(pf, name1, name2, 2)
elif blink == 3:
_print(pf, name1, name2, 3)
elif blink == 4:
_print(pf, name1, name2, 4)
# checks whether someone has won
def check(pf):
@@ -255,106 +257,68 @@ def check(pf):
for i in range(len(pf)):
for j in range(len(pf)):
if pf[i][j] == 'o':
try:
if pf[i-1][j-1] == 'o':
for k in range(symbolCount):
if pf[i-k][j-k] == 'o':
temp.append([i-k, j-k])
o += 1
else:
temp = []
o = 0
except IndexError:
continue
try:
if pf[i-1][j+1] == 'o':
for k in range(symbolCount):
if pf[i-k][j+k] == 'o':
temp.append([i-k, j+k])
o += 1
else:
temp = []
o = 0
except IndexError:
continue
try:
if pf[i+1][j-1] == 'o':
for k in range(symbolCount):
if pf[i+k][j-k] == 'o':
if pf[i+k][j-k] == 'o' and 0 <= i+k < _size and 0 <= j-k < _size:
temp.append([i+k, j-k])
o += 1
else:
winLine = []
temp = []
o = 0
except IndexError:
continue
pass
try:
if pf[i+1][j+1] == 'o':
for k in range(symbolCount):
if pf[i+k][j+k] == 'o':
if pf[i+k][j+k] == 'o' and 0 <= i+k < _size and 0 <= j+k < _size:
temp.append([i+k, j+k])
o += 1
else:
winLine = []
temp = []
o = 0
except IndexError:
continue
pass
if o == symbolCount:
winLine = temp
return 0
elif o < symbolCount:
winLine = []
temp = []
o = 0
if pf[i][j] == 'x':
try:
if pf[i-1][j-1] == 'x':
for k in range(symbolCount):
if pf[i-k][j-k] == 'x':
temp.append([i-k, j-k])
x += 1
else:
temp = []
x = 0
except IndexError:
continue
try:
if pf[i-1][j+1] == 'x':
for k in range(symbolCount):
if pf[i-k][j+k] == 'x':
temp.append([i-k, j+k])
x += 1
else:
temp = []
x = 0
except IndexError:
continue
try:
if pf[i+1][j-1] == 'x':
for k in range(symbolCount):
if pf[i+k][j-k] == 'x':
if pf[i+k][j-k] == 'x' and 0 <= i+k < _size and 0 <= j-k < _size:
temp.append([i+k, j-k])
x += 1
else:
winLine = []
temp = []
x = 0
except IndexError:
continue
pass
try:
if pf[i+1][j+1] == 'x':
for k in range(symbolCount):
if pf[i+k][j+k] == 'x':
if pf[i+k][j+k] == 'x' and 0 <= i+k < _size and 0 <= j+k < _size:
temp.append([i+k, j+k])
x += 1
else:
winLine = []
temp = []
x = 0
except IndexError:
continue
pass
if x == symbolCount:
winLine = temp
return 1
elif x < symbolCount:
winLine = []
temp = []
x = 0
@@ -457,24 +421,18 @@ def gameRound(pf, name1, name2):
if won == 0:
# 5.1 -> if yes -> end the game
clearScreen()
gameState(pf, name1, name2, 1)
print("o won!")
gameState(pf, name1, name2, 2)
end = 1
# 5.2 -> if no -> jump to step 1
if won == 1:
clearScreen()
gameState(pf, name1, name2, 1)
print("x won!")
gameState(pf, name1, name2, 3)
end = 1
if won == 2:
clearScreen()
print("Draw!")
gameState(pf, name1, name2)
gameState(pf, name1, name2, 4)
end = 1
# driver code