Skip to content

Instantly share code, notes, and snippets.

@gauravpatt92
Created May 7, 2017 03:35
Show Gist options
  • Save gauravpatt92/bb536bef5a81469236b795e40afb52a3 to your computer and use it in GitHub Desktop.
Save gauravpatt92/bb536bef5a81469236b795e40afb52a3 to your computer and use it in GitHub Desktop.
Tic Tac Toe full game
print ("TIC TAC TOE board. Rows and Columns starting from 1,1. Chances over after every place filled and not when someone wins.")
print ("Game board is printed after each chance to show progress!")
def print_game(game):
print ("\n")
for i in range(3):
print (" | ".join(str(x) for x in game[i]))
if i<2:
print("-------------")
def game_winner(game):
for i in range(3):
row = set(game[i])
if len(row)==1 and game[i][2]!=0:
return game[i][2]
for j in range(3):
column = set([game[0][j], game[1][j], game[2][j]])
if len(column)==1 and game[1][j]!=0:
return game[1][j]
diag1 = set([game[0][0], game[1][1], game[2][2]])
diag2 = set([game[0][2], game[1][1], game[2][0]])
if len(diag1)==1 or len(diag2)==1 and game[1][1]!=0:
return game[1][1]
return "No One"
if __name__=="__main__":
ans='y'
count_x=0
count_o=0
while ans!='n':
game=[[" "," "," "], [" "," "," "], [" "," "," "]]
print_game(game)
count = 0
chance = True
while chance:
spot = input("Enter the row,column in same format as given: ")
spot = spot.split(",") #gives strings
row = int(spot[0]) -1
column = int(spot[1]) -1
if count%2==0:
print ("\nPlayer 1 chance!")
if game[row][column]==" ":
game[row][column] = 'X'
else:
print ("Already Filled. Try Again!")
count-=1
print_game(game)
else:
print ("\nPlayer 2 chance!")
if game[row][column]==" ":
game[row][column]='O'
else:
print ("Already Filled. Try Again!")
count-=1
print_game(game)
count+=1
if " " in game[0] or " " in game[1] or " " in game[2]:
chance = True
else:
chance = False
print ("Chances Over!")
if game_winner(game)=='X':
print ("Winner is ",game_winner(game))
count_x+=1
break
elif game_winner(game)=='O':
print ("Winner is ",game_winner(game))
count_o+=1
break
else:
print ("No winner yet! Carry on.")
ans=input("Do you want to play again (y/n): ")
print ("Thnakyou for playing!")
print ("Score is... \nPlayer 1: %s \nPlayer 2: %s"%(count_x, count_o))
@power2425
Copy link

The object of this game is to guess the word or phrase by selecting one letter at a time until the entire word is displayed.
There is file of short phrases that you will load into an array. You must use this file.
You must display a string that shows the player how many characters are in the phrase.

There are two players
You may assign them names or just call them Player One and Player Two
When it is Player One’s turn – you will randomly assign a point value for each letter that he guesses correctly. It will continue to be his turn until he guesses a letter that is not in the word or phrase. (don’t change the point value until they guess a letter that is not in the word.)
Then it is Player Two’s turn. This player will continue with the word/phrase that the last Player started with and can continue guessing letters until there are none to guess or the player asked for a letter that is not in the phrase.
If a player guesses a letter that is not there – the point value for the next player’s guess will be altered with a random number.
The total that a player scored will continue to be accumulated

phrase.text
One Bad Apple
The Tears of a Clown
Mission Impossible
Without You
how can i do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment