Python Forum
Tic tac toe win Condition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tic tac toe win Condition
#1
Hey I'd like to keep a majority of my code the same but my group is really having trouble making a win condition for my code can anybody help?

# tic tac toe
import random
import time

#initial gameboard 
txt = "[ 1 | 2 | 3 ] \n[ 4 | 5 | 6 ] \n[ 7 | 8 | 9 ]"
print(txt)
gamespaces = [1, 2, 3, 4, 5, 6, 7, 8, 9]
in_use = [1, 2, 3, 4, 5, 6, 7, 8, 9]

#win function
xwin = []
owin = []
wincon1 = ["1", "2", "3"]
wincon2 = [4, 5, 6]
wincon3 = [7, 8, 9]
wincon4 = [1, 5, 9]
wincon5 = [3, 5, 7]
wincon6 = [1, 4, 7]
wincon7 = [2, 5, 8]
wincon8 = [3, 6, 9]
winpath1 =  all(elem in xwin  for elem in wincon1)
winpath2 =  all(elem in xwin  for elem in wincon2)
winpath3 =  all(elem in xwin  for elem in wincon3)
winpath4 =  all(elem in xwin  for elem in wincon4)
winpath5 =  all(elem in xwin  for elem in wincon5)
winpath6 =  all(elem in xwin  for elem in wincon6)
winpath7 =  all(elem in xwin  for elem in wincon7)
winpath8 =  all(elem in xwin  for elem in wincon8)

if winpath1:
  print("gamer win")

def winchk(checkwin):
  checkwin

#player input sequence
while True:
  inputvar = str(input("Pick a space: "))
  if inputvar in str(in_use):
    in_use.remove(int(inputvar))
    xwin.append(str(inputvar))
    Xreplace = txt.replace(inputvar, "x")
    txt = Xreplace
    #print(xwin)
    winchk(winpath1)
    winchk(winpath2)
    winchk(winpath3)
    winchk(winpath4)
    winchk(winpath5)
    winchk(winpath6) 
    winchk(winpath7)
    winchk(winpath8)
    aichoice = str(random.choice(in_use))
    in_use.remove(int(aichoice))
    owin.append(int(aichoice))
    Oreplace = txt.replace(aichoice, "O")
    txt = Oreplace
    print("robot chooses a space...")
    time.sleep(1)
    print(txt)
  else:
    print("that value won't work, choose:")
    for x in range(len(in_use)):
      print(in_use[x])
buran write Mar-18-2021, 07:21 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Tic tac toe win Condition - by Jacobthechosen - Mar-18-2021, 05:46 PM
RE: Tic tac toe win Condition - by Jacobthechosen - Mar-18-2021, 06:03 PM
RE: Tic tac toe win Condition - by deanhystad - Mar-18-2021, 07:19 PM
RE: Tic tac toe win Condition - by BashBedlam - Mar-18-2021, 07:29 PM

Forum Jump:

User Panel Messages

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