Monday, 25 January 2016

Tic Tac Toe Game

Hello friends,
Today I came with a complicated program.
You all know about the game tic tac toe.
After a lot of hard work I made this program.
Description:-
It is a two player game.
You can choose any symbol to play.
You can play a number of times in the same python shell.
So let's check out my effort,

print "       Tic  Tac  Toe" 
"This program is created by Sanjay Majhi."
print"""Rules for playing this game:
At first decide who is player 1
and who is player two.
Now start putting O and X in boxes
one by one and
if X or O met diagonally then won."""
def tictactoe():
    P1=raw_input("Player 1 enter your name:")
    P2=raw_input("Player 2 enter your name:")
    X=raw_input("player 1 choose X or O:")
    O=raw_input("Player 2 choose X or O:")
    table=""" 1 | 2 | 3
___|___|___
4 | 5 | 6
___|___|___
7 | 8 | 9
   |   |   """
    print table
    i=1
    while i<=9:
        if i%2!=0 or i==9:
            a=raw_input("Player 1 enter the coloumn number:-")  
            table=table.replace(a,X)
            print table
            if (table[1]==X and table[5]==X and table[9]==X) or (table[25]==X and table[29]==X and table[33]==X) or (table[49]==X and table[53]==X and table[57]==X) or (table[1]==X and table[29]==X and table[57]==X) or (table[9]==X and table[29]==X and table[49]==X) or (table[9]==X and table[33]==X and table[57]==X) or (table[5]==X and table[29]==X and table[53]==X) or (table[1]==X and table[25]==X and table[49]==X):
                print P1,"won"
                break
            elif i==9:
                print "Game had been tie."
                break
            else:
                pass
        else:
            b=raw_input("Player 2 your turn enter the coloumn number:-")
            table=table.replace(b,O)
            print table
            if (table[1]==O and table[5]==O and table[9]==O) or (table[25]==O and table[29]==O and table[33]==O) or (table[49]==O and table[53]==O and table[57]==O) or (table[1]==O and table[29]==O and table[57]==O) or (table[9]==O and table[29]==O and table[49]==O) or (table[9]==O and table[33]==O and table[57]==O) or (table[5]==O and table[29]==O and table[53]==O) or (table[1]==O and table[25]==O and table[49]==O):
                print P2,"won"
                break
            else:
                pass
        i+=1
tictactoe()
again=(raw_input("Do you want to play again:")).lower()
if again=="yes":
    tictactoe()
else:
    quit()

Hope you will like the game.
You can edit it to make it more helpful.
Get in touch with my blog to get new programs.