rastgele x o ataması yapmıyor, oyuncu A x, oyuncu B o oynuyor.
çapraz xox saymıyor
performansı düşük
oyunun bitip bitmediğini bulmanın daha farklı yolları var
Kod:
class TicTacToe:
wall = "||"
userA = "x"
userB = "o"
played = []
game = [["#", "1", "2", "3"], ["a", ".", ".", "."], ["b", ".", ".", "."], ["c", ".", ".", "."]]
blocks = 9
vloc = {"a":1, "b":2, "c":3}
@
classmethod
def check(self):
posi = (TicTacToe.game[1][1]+TicTacToe.game[1][2]+TicTacToe.game[1][3],
TicTacToe.game[2][1]+TicTacToe.game[2][2]+TicTacToe.game[2][3],
TicTacToe.game[3][1]+TicTacToe.game[3][2]+TicTacToe.game[3][3],
TicTacToe.game[1][1]+TicTacToe.game[2][1]+TicTacToe.game[3][1],
TicTacToe.game[1][2]+TicTacToe.game[2][2]+TicTacToe.game[3][2],
TicTacToe.game[1][3]+TicTacToe.game[2][3]+TicTacToe.game[3][3],
)
if "xox" in posi:
return True
return False
@
classmethod
def setup(self):
for i in TicTacToe.game:
print(TicTacToe.wall, i[0], i[1], i[2], i[3], TicTacToe.wall)
print("")
@
classmethod
def aPlay(self, loc: str, aorb: str):
if len(loc) != 2:
return False
if loc in TicTacToe.played:
return False
if aorb == "b":
user = TicTacToe.userB
else:
user = TicTacToe.userA
try:
TicTacToe.game[TicTacToe.vloc[loc[0]]][int(loc[1])] = user
except:
pass
TicTacToe.blocks -= 1
TicTacToe.played.append(loc)
return True
@
classmethod
def TurnA(self):
if not TicTacToe.blocks:
return False
TicTacToe.setup()
a = input(f"[ + ] Oyuncu A sırası ({TicTacToe.userA}): ")
s = TicTacToe.aPlay(a, "a")
if not s:
print("[ + ] Bir şeyler yanlıştı")
TicTacToe.TurnA()
TicTacToe.setup()
if TicTacToe.check():
print("[ + ] A oyuncusu Kazandı !")
return True
return False
@
classmethod
def TurnB(self):
if not TicTacToe.blocks:
return False
b = input(f"[ + ] Oyuncu B sırası ({TicTacToe.userB}): ")
s = TicTacToe.aPlay(b, "b")
if not s:
print("[ + ] Bir şeyler yanlıştı")
TicTacToe.TurnB()
if TicTacToe.check():
print("[ + ] B oyuncusu Kazandı !")
return True
return False
while TicTacToe.blocks != 0:
a = TicTacToe.TurnA()
if a:
break
a = TicTacToe.TurnB()
if a:
break