import time
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
print("****************Tic Tac Toe********************")
print()
player1 = input("Enter Player1's name:")
player2 = input("Enter PLayer2's name:")
player = 1
Running = 0
Win = 1
Draw = -1
Game = Running
Mark = 'X'
def CheckPosition(position):
if (board[position] == " "):
return True
else:
return False
def CheckWin():
global Game
# Horizontal winning condition
if (board[1] == board[2] and board[2] == board[3] and board[1] != ' '):
Game = Win
elif (board[4] == board[5] and board[5] == board[6] and board[4] != ' '):
Game = Win
elif (board[7] == board[8] and board[8] == board[9] and board[7] != ' '):
Game = Win
# Vertical Winning Condition
elif (board[1] == board[4] and board[4] == board[7] and board[1] != ' '):
Game = Win
elif (board[2] == board[5] and board[5] == board[8] and board[2] != ' '):
Game = Win
elif (board[3] == board[6] and board[6] == board[9] and board[3] != ' '):
Game = Win
# Diagonal Winning Condition
elif (board[1] == board[5] and board[5] == board[9] and board[5] != ' '):
Game = Win
elif (board[3] == board[5] and board[5] == board[7] and board[5] != ' '):
Game = Win
# Match Tie or Draw Condition
elif (board[1] != ' ' and board[2] != ' ' and board[3] != ' ' and board[4] != ' ' and board[5] != ' ' and board[
6] != ' ' and board[7] != ' ' and board[8] != ' ' and board[9] != ' '):
Game = Draw
else:
Game = Running
def DrawBoard():
print(" %c | %c | %c " % (board[1], board[2], board[3]))
print("___|___|___")
print(" %c | %c | %c " % (board[4], board[5], board[6]))
print("___|___|___")
print(" %c | %c | %c " % (board[7], board[8], board[9]))
print(" | | ")
print()
print(f"{player1} [X] {player2} [0]")
print()
print()
print("Please wait.....")
time.sleep(3)
while (Game == Running):
DrawBoard()
if (player % 2 != 0):
print(f"{player1}'s chance")
Mark = 'X'
else:
print(f"{player2}'s chance")
Mark = '0'
choice = int(input("Enter the position between [1-9] where you want to mark : "))
if (CheckPosition(choice) == True):
board[choice] = Mark
player += 1
CheckWin()
DrawBoard()
print()
if (Game == Draw):
print("Game Draw")
elif (Game == Win):
player = 1
if (player % 2 != 0):
print(f"{player1} won!")
else:
print(f"{player2} won!")
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}