Python Forum
Text Based Tic Tac Toe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text Based Tic Tac Toe
#1
I've been given an assignment that utilises the random function in python to make a simple game. I've chosen to make a text based tic tac toe, player vs AI game. Ive gotten the board up by:
x = ['1','2','3','4','5','6','7','8','9'] #values to be inserted to                     the board per layer from left to right. 
Layer1 = '[ ' + x[0] + ' ] ' + ' [ ' + x[1] + ' ] ' + ' [ ' + x[2] + ' ]'
Layer2 = '[ ' + x[3] + ' ] ' + ' [ ' + x[4] + ' ] ' + ' [ ' + x[5] + ' ]'
Layer3 = '[ ' + x[6] + ' ] ' + ' [ ' + x[7] + ' ] ' + ' [ ' + x[8] + ' ]' 
print(Layer1 + '\n' + Layer2 + 'n' + Layer3)

Then I would have all the contents of 'x' replaced with '', and have the user input from 1 - 9 and verify if that slot has already been taken, and if not replace it with an 'x', but somehow when I print out Layer1 to Layer3, it still shows the values of 1 to 9 even though it says that the array has been replaced.
I should also state that this is in 2.7 and this is occuring inside a non repeating function.
Reply
#2
Study this: http://inventwithpython.com/chapter10.html
or that: http://www.practicepython.org/solution/2...tions.html
Reply
#3
(Nov-11-2017, 03:13 PM)heiner55 Wrote: Study this: http://inventwithpython.com/chapter10.html
or that: http://www.practicepython.org/solution/2...tions.html

Thank you, but im looking for why my code didnt run as intended, not how to make one, as they both dont have the same concept as mine.
Reply
#4
Quote:why my code didnt run as intended, not how to make one

Without showing us your code, we can not help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  beginner having text based adventure trouble mrgee 2 2,032 Dec-16-2021, 05:07 AM
Last Post: buran
  Random Math Text Based Game captainflint 2 4,441 Aug-05-2018, 05:40 PM
Last Post: ahsankhan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020