Created
July 10, 2013 15:35
-
-
Save joegiralt/5967341 to your computer and use it in GitHub Desktop.
old tictactoe program that ai submitted to get into The Flatiron School.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
from time import sleep | |
print "*********Welcome to Joe's TicTacTAUNT game**********" | |
tictactoe = [ | |
0, 1, 2, | |
3, 4, 5, | |
6, 7, 8 | |
] | |
taunt = ["I thought you were smarter that that!", "Your mother should have thrown you away and kept the stork!", "If you only had a brain....", | |
"Pay attention! Let me show you how it's done.", "Lucky for me. You really suck at this", | |
"I bet you're not going to take this insolence sitting down.", "If your I.Q. doubled, you'd still be a dumbass!", | |
"I've played chimps smarter than you", "Were you dropped as a baby?","Having delusions of adequacy? Hmmm...."] | |
# lines 15 through 22 were for testing the def check_for_draw, random is really stupid maybe build intelligence.... | |
#tictactoe[0] = 'o' | |
#tictactoe[1] = 'o' | |
#tictactoe[2] = 'x' | |
#tictactoe[3] = 'x' | |
#tictactoe[4] = 'x' | |
#tictactoe[5] = 'o' | |
#tictactoe[6] = 'o' | |
#tictactoe[7] = 'o' | |
def board(): | |
print tictactoe[0],"|", tictactoe[1],"|", tictactoe[2] | |
print "----------" | |
print tictactoe[3],"|", tictactoe[4],"|", tictactoe[5] | |
print "__________" | |
print tictactoe[6],"|", tictactoe[7],"|", tictactoe[8] | |
print " " | |
board() | |
print " " | |
def victory_condition(player,loc1,loc2,loc3): | |
if tictactoe[loc1] == player and tictactoe[loc2] == player and tictactoe[loc3] == player: | |
return True | |
def check_loc(player): | |
if victory_condition(player, 0, 1, 2): | |
return True | |
if victory_condition(player, 1, 4, 7): | |
return True | |
if victory_condition(player, 2, 5, 8): | |
return True | |
if victory_condition(player, 6, 7, 8): | |
return True | |
if victory_condition(player, 3, 4, 5): | |
return True | |
if victory_condition(player, 0, 3, 6): | |
return True | |
if victory_condition(player, 2, 4, 6): | |
return True | |
if victory_condition(player, 0, 4, 8): | |
return True | |
def check_for_draw(): | |
for location in tictactoe: | |
if location == "x" or location == "o": | |
pass | |
else: | |
return False | |
print " " | |
print " The game is a draw " | |
print " " | |
return True | |
while True: | |
if check_for_draw(): | |
sys.exit() | |
########## all the code below is crap ############## | |
#input = raw_input("Player 1's turn: GO 'X,' GO!") | |
# def check_input(): | |
# if (input.isdigit() and int(input) < 9) == False: | |
# print " Try again! " | |
# check_input() | |
# if input.isdigit() and int(input) < 9: | |
#input = raw_input("Player 1's turn: GO 'X,' GO!") | |
#this is the procedure to check input | |
########### ############## | |
def shit_input(): | |
if input.isdigit() and int(input) < 9: | |
return False | |
else: #this is the condition that input is not # < 9 | |
return True | |
input = raw_input("Player 1's turn: GO 'X,' GO! ") | |
shit_input() | |
while shit_input(): | |
for moving_dot in range(6): | |
print ".", | |
sleep(.5) | |
sys.stdout.flush() # Yay stackoverflow! | |
print " " | |
input = raw_input("Try a valid input 0-8. ") | |
else: | |
input = int(input) | |
if tictactoe[input] != 'x' and tictactoe[input] != 'o': | |
tictactoe[input] = 'x' | |
# board() | |
print " " | |
print "Player 2's turn: GO 'O,' GO" | |
for moving_dot in range(6): | |
print ".", | |
sleep(.7) | |
sys.stdout.flush() # Yay stackoverflow! | |
print " " | |
print " " | |
print taunt[0 + random.randint(0,9)] | |
print " " | |
if check_loc('x') == True: | |
print '--- X (Player 1 ) WINS ---' | |
print " " | |
board() | |
print " " | |
sys.exit() | |
break; | |
# imbedded while so that player 2 can go after player 1 unless player | |
# 1 which will break the loop and exit the program | |
while True: | |
if check_for_draw(): | |
sys.exit() | |
op = random.randint(0,8) | |
for player in ["o", "x"]: | |
if (tictactoe[0] == tictactoe[1] == player) and str(tictactoe[2]).isdigit() != False: op = 2 | |
elif (tictactoe[0] == tictactoe[1] == player) and str(tictactoe[2]).isdigit() != False: op = 2 | |
elif (tictactoe[1] == tictactoe[2] == player) and str(tictactoe[0]).isdigit() != False: op = 0 | |
elif (tictactoe[0] == tictactoe[2] == player) and str(tictactoe[1]).isdigit() != False: op = 1 | |
elif (tictactoe[3] == tictactoe[4] == player) and str(tictactoe[5]).isdigit() != False: op = 5 | |
elif (tictactoe[4] == tictactoe[5] == player) and str(tictactoe[3]).isdigit() != False: op = 3 | |
elif (tictactoe[5] == tictactoe[3] == player) and str(tictactoe[4]).isdigit() != False: op = 4 | |
elif (tictactoe[6] == tictactoe[7] == player) and str(tictactoe[8]).isdigit() != False: op = 8 | |
elif (tictactoe[6] == tictactoe[8] == player) and str(tictactoe[7]).isdigit() != False: op = 7 | |
elif (tictactoe[7] == tictactoe[8] == player) and str(tictactoe[6]).isdigit() != False: op = 6 | |
elif (tictactoe[0] == tictactoe[3] == player) and str(tictactoe[6]).isdigit() != False: op = 6 | |
elif (tictactoe[3] == tictactoe[6] == player) and str(tictactoe[0]).isdigit() != False: op = 0 | |
elif (tictactoe[6] == tictactoe[0] == player) and str(tictactoe[3]).isdigit() != False: op = 3 | |
elif (tictactoe[1] == tictactoe[4] == player) and str(tictactoe[7]).isdigit() != False: op = 7 | |
elif (tictactoe[7] == tictactoe[4] == player) and str(tictactoe[1]).isdigit() != False: op = 1 | |
elif (tictactoe[1] == tictactoe[7] == player) and str(tictactoe[4]).isdigit() != False: op = 4 | |
elif (tictactoe[2] == tictactoe[5] == player) and str(tictactoe[8]).isdigit() != False: op = 8 | |
elif (tictactoe[8] == tictactoe[5] == player) and str(tictactoe[2]).isdigit() != False: op = 2 | |
elif (tictactoe[2] == tictactoe[8] == player) and str(tictactoe[5]).isdigit() != False: op = 5 | |
elif (tictactoe[0] == tictactoe[4] == player) and str(tictactoe[8]).isdigit() != False: op = 8 | |
elif (tictactoe[8] == tictactoe[4] == player) and str(tictactoe[0]).isdigit() != False: op = 0 | |
elif (tictactoe[0] == tictactoe[8] == player) and str(tictactoe[4]).isdigit() != False: op = 4 | |
elif (tictactoe[2] == tictactoe[4] == player) and str(tictactoe[6]).isdigit() != False: op = 6 | |
elif (tictactoe[6] == tictactoe[2] == player) and str(tictactoe[4]).isdigit() != False: op = 4 | |
elif (tictactoe[6] == tictactoe[4] == player) and str(tictactoe[2]).isdigit() != False: op = 2 | |
elif tictactoe[4] != "x" and tictactoe[4] != "o": op = 4 # always grab middle square if it's unoccupied | |
#op = the player 2, "O" next move | |
if tictactoe[op] != 'o' and tictactoe[op] != 'x': | |
tictactoe[op] = 'o' | |
print " " | |
board() | |
if check_loc('o') == True: | |
print '--- O (Player 2 ) WINS ---' | |
print " " | |
board() | |
print " " | |
sys.exit() | |
break; | |
break; | |
else: | |
print " " | |
print "Oops, try a location that doesn't have an 'X' or an 'O' in it" | |
print " " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment