Guest User

Untitled

a guest
Jan 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. #ufirat117
  2. #12/27/17
  3.  
  4. import sys
  5.  
  6. # getting input
  7. def getInput():
  8. flag= True
  9. while flag:
  10. #making a right choice
  11. choiceFlag= True
  12. while choiceFlag:
  13. choice= input("X-O: ")
  14. if choice == 'X' or choice == 'x' or choice == 'O' or choice == 'o':
  15. choiceFlag= False
  16. #making a right position
  17. posFlag= True
  18. while posFlag:
  19. pos= input("what pos u want to make {}: ".format(choice.upper()))
  20. if pos in '123456789':
  21. posFlag= False
  22. #for the getting out of while loop
  23. if choiceFlag == False and posFlag == False:
  24. flag= False
  25.  
  26. return choice.upper(), int(pos)
  27.  
  28. # table list
  29. def creatingTableList(choice,pos,liste,counter,chaseList):
  30. flag= True
  31. while flag:
  32. if liste[pos] == ' ' and (choice != chaseList[counter-1]):
  33. liste.pop(pos) #erasing position for the choice
  34. liste.insert(pos,choice) #replace with choice
  35. chaseList.append(choice)
  36. flag= False
  37.  
  38. else:
  39. print("u are cheater ~{}~ and u lose this game!!!".format(choice))
  40. sys.exit()
  41.  
  42. #create table
  43. def table(liste):
  44. liste= liste
  45. print(" {} | {} | {} ".format(liste[1],liste[2],liste[3]))
  46. print("-----------")
  47. print(" {} | {} | {} ".format(liste[4],liste[5],liste[6]))
  48. print("-----------")
  49. print(" {} | {} | {} ".format(liste[7],liste[8],liste[9]))
  50.  
  51. #gameover function
  52. def gameOver(choice):
  53. print("winner is {}".format(choice))
  54. print("Hope you enjoy!")
  55.  
  56. flag= True
  57. while flag:
  58. yn= input("do you want to play again (Y-N)?: ")
  59.  
  60. if yn[0] == 'Y' or yn[0] == 'y':
  61. flag= False
  62. tictactoe()
  63. elif yn[0] == 'N' or yn[0] == 'n':
  64. flag= False
  65. sys.exit()#exit console
  66. else:
  67. print("its just a yes or no question as you can see!!!")
  68. flag=True
  69.  
  70. def tictactoe():
  71. chaseList=['NONE']# for the cheaters :))
  72. counter=1
  73. liste=['NONE',' ',' ',' ',' ',' ',' ',' ',' ',' ','NONE']
  74. while counter<10:
  75. choice,pos= getInput()
  76. creatingTableList(choice,pos,liste,counter,chaseList)
  77. counter+=1
  78. table(liste)
  79. if (liste[1] == liste[2] == liste[3] == 'X' or\
  80. liste[1] == liste[2] == liste[3] == 'O' or\
  81. liste[1] == liste[4] == liste[7] == 'X' or\
  82. liste[1] == liste[4] == liste[7] == 'O' or\
  83. liste[1] == liste[5] == liste[9] == 'X' or\
  84. liste[1] == liste[5] == liste[9] == 'O' or\
  85. liste[4] == liste[5] == liste[6] == 'X' or\
  86. liste[4] == liste[5] == liste[6] == 'O' or\
  87. liste[7] == liste[8] == liste[9] == 'X' or\
  88. liste[7] == liste[8] == liste[9] == 'O' or\
  89. liste[3] == liste[6] == liste[9] == 'X' or\
  90. liste[3] == liste[6] == liste[9] == 'O' or\
  91. liste[3] == liste[5] == liste[7] == 'X' or\
  92. liste[3] == liste[5] == liste[7] == 'O' or\
  93. liste[2] == liste[5] == liste[8] == 'X' or\
  94. liste[2] == liste[5] == liste[8] == 'O'):
  95. gameOver(choice)
  96. else:
  97. print("there is no winner")
  98.  
  99. if __name__ == "__main__": tictactoe()
Add Comment
Please, Sign In to add comment