| | |
Need help with tic tac toe
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
hi
I'm trying to write a game where I play against the computer...and as u see below..I really suck at it..
can someone pleeease help me..I want it to be as simple as possible..
thanks
input random
game = raw_input("Your turn. Input the coordinate for your move on the form x,y: ")
for turn in range(9):
def print_board(board):
board = board.replace("_"," ")
print "." + "---." * 3
for bound in [0,3,6]:
print "|",
for sym in board[bound:bound+3]:
print sym, "|",
if bound < 6:
print "\n|" + "---|" * 3
print "\n'" + "---'" * 3
Empty = ' '
Player_X = 'x'
Computer_O = 'o'
a = 0,0
b = 0,1
c = 0,2
d = 1,0
e = 1,1
f = 1,2
g = 2,0
h = 2,1
i = 2,2
winlist = [(a,b,c), (d,e,f), (g,h,i), (a,d,g,), (b,e,h), (c,f,i), (a,e,i), (g,e,c)]
opponent = { Player_X : Computer_O, Computer_O : Player_X }
if winner == player:
print: ("I win!")
if winner == computer:
print: ("You win!")
if winner == none:
print: ("None")
board ()
raw_input ( 'Remi' )
I'm trying to write a game where I play against the computer...and as u see below..I really suck at it..
can someone pleeease help me..I want it to be as simple as possible..
thanks
input random
game = raw_input("Your turn. Input the coordinate for your move on the form x,y: ")
for turn in range(9):
def print_board(board):
board = board.replace("_"," ")
print "." + "---." * 3
for bound in [0,3,6]:
print "|",
for sym in board[bound:bound+3]:
print sym, "|",
if bound < 6:
print "\n|" + "---|" * 3
print "\n'" + "---'" * 3
Empty = ' '
Player_X = 'x'
Computer_O = 'o'
a = 0,0
b = 0,1
c = 0,2
d = 1,0
e = 1,1
f = 1,2
g = 2,0
h = 2,1
i = 2,2
winlist = [(a,b,c), (d,e,f), (g,h,i), (a,d,g,), (b,e,h), (c,f,i), (a,e,i), (g,e,c)]
opponent = { Player_X : Computer_O, Computer_O : Player_X }
if winner == player:
print: ("I win!")
if winner == computer:
print: ("You win!")
if winner == none:
print: ("None")
board ()
raw_input ( 'Remi' )
Last edited by c_crash; Oct 9th, 2009 at 12:36 pm.
1
#2 Oct 9th, 2009
1) This program has no indentation. To preserve formatting on this forum you must wrap your code in [code=python]#Code tags[/code]. However after looking closer at your post it appears that your code has no indentation even in its original form.
2) You need to learn the difference between defining a function and calling one. You should never ever ever ever ever be defining a function inside a loop or any other regular code unless it truly needs to be a dynamic function (which you'll likely never encounter).
2) You need to learn the difference between defining a function and calling one. You should never ever ever ever ever be defining a function inside a loop or any other regular code unless it truly needs to be a dynamic function (which you'll likely never encounter).
![]() |
Similar Threads
- Tic-Tac-Toe (C++)
- Tic Tac Toe Homework (C++)
- Tic Tac toe help (C)
- Tic Tac Toe AI help, where to reset variables. (C++)
Other Threads in the Python Forum
- Previous Thread: PyGtk progressbar problem
- Next Thread: Getting an input from arrow keys.
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl pysimplewizard python random recursion redirect remote reverse scrolledtext session simple software sprite statictext string strings syntax table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






