Tic Tac Toe Modified questions about it's code...

This is the place for queries that don't fit in any of the other categories.

Tic Tac Toe Modified questions about it's code...

Postby shimmyshimmy » Sat Oct 19, 2013 11:43 pm

Basically it's tic tac toe, except you can cover up an opponent's x and o's with larger x and o's mediums cover up the small and larger ones cover up the mediums.
whenever i run this program it doesn't update the board and doesn't declare a winner. not sure what to do truthfully.


Code: Select all
#Winner checker.

def player_done(playerSym, board):
    return ((board[6] == playerSym and board[7] == playerSym and board[8] == playerSym) or # across the top
    (board[3] == playerSym and board[4] == playerSym and board[5] == playerSym) or # across the middle
    (board[0] == playerSym and board[1] == playerSym and board[2] == playerSym) or # across the bottom
    (board[6] == playerSym and board[3] == playerSym and board[0] == playerSym) or # down the left side
    (board[7] == playerSym and board[4] == playerSym and board[3] == playerSym) or # down the middle
    (board[8] == playerSym and board[5] == playerSym and board[2] == playerSym) or # down the right side
    (board[6] == playerSym and board[4] == playerSym and board[2] == playerSym) or # diagonal
    (board[8] == playerSym and board[4] == playerSym and board[0] == playerSym)) # diagonal

def opponent_done(oppSym, board):
    return ((board[6] == oppSym and board[7] == oppSym and board[8] == oppSym) or # across the top
    (board[3] == oppSym and board[4] == oppSym and board[5] == oppSym) or # across the middle
    (board[0] == oppSym and board[1] == oppSym and board[2] == oppSym) or # across the bottom
    (board[6] == oppSym and board[3] == oppSym and board[0] == oppSym) or # down the left side
    (board[7] == oppSym and board[4] == oppSym and board[1] == oppSym) or # down the middle
    (board[8] == oppSym and board[5] == oppSym and board[2] == oppSym) or # down the right side
    (board[6] == oppSym and board[4] == oppSym and board[2] == oppSym) or # diagonal
    (board[8] == oppSym and board[4] == oppSym and board[0] == oppSym)) # diagonal

# Sets up the Board

def drawBoard(board):
    print('   |   |')
    print(' ' + board[6] + ' | ' + board[7] + ' | ' + board[8])
    print('   |   |')
    print('-----------')
    print('   |   |')
    print(' ' + board[5] + ' | ' + board[4] + ' | ' + board[3])
    print('   |   |')
    print('-----------')
    print('   |   |')
    print(' ' + board[0] + ' | ' + board[1] + ' | ' + board[2])
    print('   |   |')

#Prints the current board
   
def print_board(board):
    # Make a duplicate of the board list and return it the duplicate.
    dupeBoard = []
    for i in board:
        dupeBoard.append(i)
    return dupeBoard

#The Board

board = ["0", "1", "2", "3", "4", "5", "6", "7", "8"]

done = False

#The Move list for X's and O's

xmovesList = ["*","x","X"]
omovesList = [".","o","O"]

#Greeting message and choosing the initial X and O assignment.
print "Welcome to Tic-Tac-Toe-Cover-Up!"
playerSym = raw_input("Player 1, please select either X or O for your pieces: ")
print

#Player and opponent move assignment
if (playerSym == "X"):
    playerSym = xmovesList
    oppSym = omovesList
    turn = "X"
else:
    playerSym = omovesList
    oppSym = xmovesList
    turn = "O"

#Main game loop.
while not done:
    drawBoard(board)
   
   
    print turn,"'s turn"
    if (turn == "X"):
        player = xmovesList
        opponent = omovesList
    else:
        player = omovesList
        opponent = xmovesList

    print "Select the place you want to play (0-8)"
    print_board(board)

    pos = input("Select: ")
    if pos <=8 and pos >=0:
        Y = pos/3
        X = pos%3
        if X != -1:
            X -=1
        else:
            X = 2
            Y -=1
                   
        if board == " ":
            board = player[9]
            moved = True
            done = player()
        elif board != " ":
            if board == opponent[0]:
                board = player[1]
                moved = True
                done = player_done()
                done = opponent_done()
            if board == opponent[1]:
                board = player[2]
                moved = True
                done = player_done()
                done = opponent_done()

        if done == False:
            if turn == "X":
                turn = "O"
            else:
                turn = "X"
Last edited by Mekire on Sun Oct 20, 2013 1:56 pm, edited 1 time in total.
Reason: First post lock.
shimmyshimmy
 
Posts: 1
Joined: Sat Oct 19, 2013 11:40 pm

Re: Tic Tac Toe Modified questions about it's code...

Postby Kebap » Sun Oct 20, 2013 1:21 pm

That code is very long. What you need to do is, to shorten the code down to the minimum and see if the error still occurs. This may even help you find the error on your own.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 365
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: snippsat and 2 guests