Public Group

# TicTacToe conditional help

This topic is 3807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

oh no i double posted again!!!! I am a begginning python programmer and I need some help with a TicTacToe program I am trying to write. My biggest issue is my innability to make a specific winner. I cannot for the life of me make a way to check if either player wins that works. Right now I only have a broken function that is supposed to check if player 1 'X' wins. here is my code. I couldn't figure out how to make it go into a seperate piece that scrolls down like other people. b = ['_','_','_','_','_','_','_','_','_'] w = 1 check = 0 def printboard(): print '[',b[0],'][',b[1],'][',b[2],']' ' [ 1 ][ 2 ][ 3 ]' print '[',b[3],'][',b[4],'][',b[5],']' ' [ 4 ][ 5 ][ 6 ]' print '[',b[6],'][',b[7],'][',b[8],']' ' [ 7 ][ 8 ][ 9 ]' def plr1(): s = int(raw_input('player 1 make your move')) b[s - 1] = 'X' def plr2(): s = int(raw_input('player 2 make your move')) b[s - 1] = 'O' def winner1(): check = b[0] + b[1] + b[2] checking1() check = b[3] + b[4] + b[5] checking1() check = b[6] + b[7] + b[8] checking1() check = b[0] + b[3] + b[6] checking1() check = b[1] + b[4] + b[7] checking1() check = b[2] + b[5] + b[8] checking1() check = b[0] + b[4] + b[8] checking1() check = b[6] + b[4] + b[2] checking1() def checking1(): if check == 'XXX': print 'player 1 is the winner' w = 2 while True: printboard() plr1() winner1() if w = = 2: break printboard() plr2() if w = = 2: break If someone can point me to a place that gives ideas on ways that I can make an efficient working conditional please post. Any help on making this work is highly appreciated. If anyone needs anymore information I'll gladly post it. [Edited by - steveworks on June 17, 2008 8:11:46 PM]

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633387
• Total Posts
3011608
• ### Who's Online (See full list)

There are no registered users currently online

×