Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'malia015'
- Size = 3
- Grid = [["" for n in range(Size)] for n in range(Size)]
- Players = ["X", "O"]
- Turn = 0
- TurnSign = Players[Turn % len(Players)]
- def checkdir(down, right):
- for n in range(Size):
- m = 0
- while Grid[(n*down + m*right)][(n*right + m*down)] == TurnSign:
- m += 1
- if m >= Size:
- return True
- return False
- def check():
- if checkdir(1, 0) or checkdir(0, 1) or \
- {Grid[n][n] for n in range(Size)} == {TurnSign} or \
- {Grid[-(n+1)][n] for n in range(Size)} == {TurnSign}:
- return True
- def out():
- for n in range(Size):
- print("\n+" + "---+"*Size, end="\n|")
- for m in range(Size):
- print("{:^3}".format(Grid[n][m]), end="|")
- print("\n+" + "---+"*Size)
- out()
- while Turn < Size**2:
- Move = input("{}'s turn: ".format(TurnSign))
- Move = [int(n)-1 for n in Move if n in {"1", "2", "3"}]
- if len(Move) != 2:
- print("Try again; 1, 2 or 3, two integers.")
- out()
- continue
- Move.reverse()
- Move[0] = (Move[0] - 1) * (-1) + 1
- if Grid[Move[0]][Move[1]] != "":
- print("Try again; that space is taken.")
- out()
- continue
- Grid[Move[0]][Move[1]] = TurnSign
- out()
- if check():
- print(str(TurnSign) + " wins!")
- break
- Turn += 1
- if Turn >= Size**2:
- print("It's a draw!")
- TurnSign = Players[Turn % len(Players)]
- input(str(8*7*6*5*4*3*2))
- for n in range(400000):
- check()
- print("Fett!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement