Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:03:28+00:00 2026-06-17T09:03:28+00:00

Okay for starters this is a simple version of tic tac toe, I am

  • 0

Okay for starters this is a simple version of tic tac toe, I am in the process of creating an AI designed with difficulties and i have partial code for the AI(randomized) inside my code. Ignore that function but my main difficulty is printing moves on the board correctly. For some reason whenever I choose whether i want to be X or O it auto submits me into X. In addition, if i choose anything other than position A, it will print an X on position A anyways. I would like it if anyone would provide me with the help of telling me where exactly in my coding I went wrong. On a different note, in order to make my game more clear and easy, i would like to print Board and Board 2 side by side after moves are made. This would be to show what moves are available, so if the moves A and B were taken they would not show on Board. If someone could teach me how to do a side by side print that would be great.

print "**********************"
print "*THE GAME WILL BEGIN.*"
print "**********************"
import random
indx=0
move_storage=[]
move=["","","","","","","","",""]
#**************************************************
#            This is the original board           *
#**************************************************
def board():
    print "This is the tictactoe board we will be playing on"
    print "         |         |        "
    print "    A    |    B    |    C   "
    print "         |         |        "
    print "------------------------------"
    print "         |         |        "
    print "    D    |    E    |    F   "
    print "         |         |        "
    print "------------------------------"
    print "         |         |        "
    print "    G    |    H    |    I   "
    print "         |         |        "
board()
#****************************************************
#This is the board where the moves will be displayed*
#****************************************************
def board2(move):
    print "  ",move[0],"  |   ",move[1],"     |     ",move[2],"     "
    print "       |          |     "
    print " -----------------------  "
    print "       |          |     "
    print "  ",move[3],"   |    ",move[4],"    |     ",move[5],"     "
    print "       |          |     "
    print " -----------------------  "
    print "       |          |     "
    print "  ",move[6],"   |     ",move[7],"   |    ",move[8],"     "

#This function will store all of the moves inputed.
def movestorage(move_storage, move):
    move_storage= move_storage + [move]
#This function will randomize the computer's move
def computer_move():
    move_random=random.randint(1,9)
    move[move_random]=computer_choice
    movestorage(move_storage, move)
player=raw_input("Would you like to play as x or o-->")
player_order=raw_input("Would you like to go first,y/n?-->")
while indx==0:
    if 'x' or 'X' == player:
        player_choice="X"
        computer_choice="O"
        if 'y' or 'Y' in player_order:
            print 
        elif 'n' or 'N' in player_order:
            print
            print "The computer will go first, press ENTER to see the computers turn"
    elif 'o' or 'O' == player:
        player_choice="O"
        computer_choice="X"
        if 'y' or 'Y' in player_order:
            print
        elif 'n' or 'N' in player_order:
            print
            print "The computer will go first, press ENTER to see the computers turn"
    x=0
    while 2>x:  #This is where the player decides where he wants to go
        choice=raw_input("Choose where you would like to move-->")
        if choice == 'a' or 'A':
            move[0]=player_choice
            movestorage(move_storage, move)
        elif choice == 'b' or 'B':
            move[1]=player_choice
            movestorage(move_storage, move)
        elif choice == 'c' or 'C':
            move[2]=player_choice
            movestorage(move_storage, move)
        elif choice == 'd' or 'D':
            move[3]=player_choice
            movestorage(move_storage, move)
        elif choice == 'e' or 'E':
            move[4]=player_choice
            movestorage(move_storage, move)
        elif choice == 'f' or 'F':
            move[5]=player_choice
            movestorage(move_storage, move)
        elif choice == 'g' or 'G':
            move[6]=player_choice
            movestorage(move_storage, move)
        elif choice == 'h' or 'H':
            move[7]=player_choice
            movestorage(move_storage, move)
        elif choice == 'i' or 'I':
            move[8]=player_choice
            movestorage(move_storage, move)
        board2(move)

Also I have some blank print statements for neatness, they are not mistakes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:03:29+00:00Added an answer on June 17, 2026 at 9:03 am

    if 'x' or 'X' == player does not mean player is either x or X, it means if ('x') or ('X' == player) instead, so test both 'x' as a boolean, and test 'X' == player as a boolean and then the whole expression is True if the first or the second part is True.

    Since the first is a string of length greater than 0, it’ll always be True, and the second test is never made:

    >>> bool('x' or 'X' == 'fiddlesticksandflapdoodles')
    True
    >>> bool('x')
    True
    >>> bool('X' == 'fiddlesticksandflapdoodles')
    False
    

    Use:

    if 'x' == player or 'X' == player:
    

    instead, or:

    if player in ('x', 'X'):
    

    or:

    if player.lower() == 'x':
    

    all of which test for the same thing.

    This applies to all your if statements testing against upper and lowercase letters, such as 'n' or 'N', and 'o' or 'O'.

    As for your long list of if choice tests; just use a mapping to map letter to number:

    choices = {letter: number for number, letter in enumerate('abcdefghi')}
    

    Now you can use choices to map to an index:

    index = choices.get(choice.lower())
    if index is not None:
        move[index] = player_choice
        movestorage(move_storage, move)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this question is very simple: I have a facebook page, and a website.
Okay the answer to this may be really simple but I have been searching
Okay so this one is stumping me. I have the following code which attempts
Okay suppose I have an array of objects that look like this: obj(from, to)
Okay, so I've got something as simple as this: <audio autoplay='autoplay' loop='loop' id='audio' controls>
Okay, Now admittedly this sounds like a silly question; But, I actually have a
Okay I've been trying to research how to do this and have failed. I
Okay here's my situation. I have a php file that contains a simple form
Okay. So I'm creating this app and I'm really happy with it apart from
Okay, I kinda asked this question already, but noticed that i might have not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.