repl.it
@DARKLORD6474/

Tic-Tac-Toe (Python 3)

Python

My cat is smarter than the AI here, and I don't even have a cat

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
"""
Made by richtan
If you want to use the code, please give credit.

I definitely shouldn't have put this in a class :(
I had to copy and paste all the "self"s
And I'm not gonna bother changing the redefine variable method to creating a new object. (You know, laziness over quality)

Commands:
"quit": to quit, there will be confirmation
"help": to get help on how to play
"funfacts": learn some fun facts about Tic-tac-toe
"restart": restart the game, there will be confirmation
"""

try:
  from replit import clear
except ImportError:
  import os
  import platform
  if platform.system() in ["Linux", "Darwin"]:
    clear = lambda: os.system('clear')
  elif platform.system() == "Windows":
    clear = lambda: os.system('cls')
  else:
    clear = lambda: print("\n"*100)

#clear = lambda: print("\n"*100)

import sys, random, time

try:
  from colorama import Fore, Style
except ImportError:
  sys.stdout.write("You need to have 'colorama' installed on your computer.")
  sys.exit(0)

class Tictactoe:
  def __init__(self):
    self.oppui = ""
    self.difu = ""
    self.bob4 = ""
    self.last2turn = 0
    self.turn = 0
    self.samesettings = False
    self.ttr = ""
    self.randomfact = ""
    self.restarts = "try again, restart, retry, r".split(", ")
    self.quits = "q, qu, qui, quit".split(", ")
    self.helps = "help, h, save me, help my poor soul, pls help, help pls, please help, help please".split(", ")
    self.funfacts = "fact, facts, funfact, funfacts, f".split(", ")
    self.funfacs = ["In 1975, MIT students created a computer that could play tic-tac-toe perfectly with Tinkertoys.", "25,168 unique games of tic-tac-toe can be played. The first player wins 131,184 of them, the second player wins 66,904 of them, and the last 46,080 of them are drawn.", "Many more..."]
    self.board = "1,2,3,4,5,6,7,8,9".split(",")
    self.pos1 = "hu, human, friend, man, woman, girl, boy, person, hum".split(", ")
    self.pos2 = ", computer, ai, bot, robot, my computer, you".split(", ")
    self.diffs1 = "b, easy, beginner, simple".split(", ")
    self.diffs2 = "m, medium, intermediate, normal".split(", ")
    self.diffs3 = "d, hard, difficult, challenging".split(", ")
    self.diffs4 = "e, insane, extreme, harder".split(", ")
    self.diffs5 = "i, unbeatable, impossible, god, hardest".split(", ")
    self.player = ""
    self.sady = random.randint(1, 4)
    self.othyu = ""
    self.facts = ["The first computer programmer was a female, named Ada Lovelace.", "The first game was created in 1961. Fun facts are that it didn’t earn any money.", "The first virus was created in 1983.", "The first computer was actually a loom called the Jacquard loom, an automated, mechanical loom, which didn’t use any electricity.", "The first high-level (very close to real English that we use to communicate) programming language was FORTRAN, invented in 1954 by IBM’s John Backus.", "Computer programming is one of the fastest growing occupations currently.", "Majors related to computer programming are among the highest paying in colleges and universities.", "A programming language is basically a language that allows a human being to communicate with a computer.", "The lifestyle we live today with our tablets, and mobile phones wouldn’t be possible without computer programming.", "Did you know how many total programming languages? "+ u"\u2015" +" it’s 688.", "Most people are intimidated by the thought of learning how to program, however as with anything, the more you practice and repeatedly do that task, the easier it gets.", "Did you know first computer bug was named due to a real bug? Grace Hopper recorded the first computer ‘bug’ in the book as she was working for the MARK II computer."]
    self.insults = """If laughter is the best medicine, your face must be curing the world.^^You're so ugly, you scared the crap out of the toilet.^^Your family tree must be a cactus because everybody on it is a prick.^^No I'm not insulting you, I'm describing you.^^It's better to let someone think you are an Idiot than to open your mouth and prove it.^^If I had a face like yours, I'd sue my parents.^^I guess you prove that even god makes mistakes sometimes.^^The only way you'll ever get laid is if you crawl up a chicken's ass and wait.^^You're so fake, Barbie is jealous.^^I’m jealous of people that don’t know you!^^My psychiatrist told me I was crazy and I said I want a second opinion. He said okay, you're ugly too.^^You're so ugly, when your mom dropped you off at school she got a fine for littering.^^If I wanted to kill myself I'd climb your ego and jump to your IQ.^^You must have been born on a highway because that's where most accidents happen.^^Brains aren't everything. In your case they're nothing.^^I don't know what makes you so stupid, but it really works.^^I can explain it to you, but I can’t understand it for you.^^Roses are red violets are blue, God made me pretty, what happened to you?^^Behind every fat woman there is a beautiful woman. No seriously, your in the way.^^Calling you an idiot would be an insult to all the stupid people.^^You, sir, are an oxygen thief!^^Some babies were dropped on their heads but you were clearly thrown at a wall.^^Don't like my sarcasm, well I don't like your stupid.^^Why don't you go play in traffic.^^Please shut your mouth when you’re talking to me.^^I'd slap you, but that would be animal abuse.^^They say opposites attract. I hope you meet someone who is good-looking, intelligent, and cultured.^^Stop trying to be a smart ass, you're just an ass.^^The last time I saw something like you, I flushed it.^^'m busy now. Can I ignore you some other time?^^You have Diarrhea of the mouth; constipation of the ideas.^^If ugly were a crime, you'd get a life sentence.^^Your mind is on vacation but your mouth is working overtime.^^I can lose weight, but you’ll always be ugly.^^Why don't you slip into something more comfortable... like a coma.^^Shock me, say something intelligent.^^If your gonna be two faced, honey at least make one of them pretty.^^Keep rolling your eyes, perhaps you'll find a brain back there.""".split("^^")
    self.dif = ""
    self.byus = []
    self.baty = False
    self.bodt = random.randint(1, 4)
    self.xos = ["X", "O"]
    self.gona = False
    self.sath = random.randint(1, 4)
    self.cotu = random.randint(1, 4)
    self.cobt = random.randint(1, 4)
    self.ct1 = ""
    self.typ = ""
    self.quitcheck = ""
    self.aifirst = False
    self.plyturn = 0
    self.tankr = 0
    self.randominsult = ""
    self.count = 0
    self.mistermk = ""
    self.ggyhaha = ""
    self.ront = 0
    self.cobr = random.randint(1, 4)
    self.ytp = ""
    self.othtyp = ""
    self.terf = 0
    self.bob = ""
    self.circ = [1, 2, 3, 6, 9, 8, 7, 4]
    self.ftd = str(
      " " + self.board[0] + " | " + self.board[1] + " | " + self.board[2] +
      " \n―――|―――|―――\n " + self.board[3] + " | " + self.board[4] + " | " +
      self.board[5] + " \n―――|―――|―――\n " + self.board[6] + " | " +
      self.board[7] + " | " + self.board[8] + " \n")
    self.guy = ""
    self.yeps = "y, yes, ye, ya, yap, yeah, yep, sure, of course, why not".split(
      ", ")
    self.nahs = "n, no, not yet, wait a bit, nah, probably not, bye, see ya, im outta here, get lost, nooooo".split(", ")
    self.wincombos = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))
    
  def redef(self):
    self.byus = []
    self.baty = False
    self.bodt = random.randint(1, 4)
    self.xos = ["X", "O"]
    self.gona = False
    self.sath = random.randint(1, 4)
    self.cotu = random.randint(1, 4)
    self.cobt = random.randint(1, 4)
    self.ct1 = ""
    self.quitcheck = ""
    self.aifirst = False
    self.plyturn = 0
    self.tankr = 0
    self.oppui = ""
    self.difu = ""
    self.bob4 = ""
    self.last2turn = 0
    self.turn = 0
    self.mistermk = ""
    self.randominsult = ""
    self.count = 0
    self.sady = random.randint(1, 4)
    self.othyu = ""
    self.ront = 0
    self.cobr = random.randint(1, 4)
    self.ytp = ""
    self.board = "1,2,3,4,5,6,7,8,9".split(",")
    self.ttr = ""
    self.randomfact = ""
    self.terf = 0
    self.bob = ""

  def printBoard(self):
    self.byus = self.board[:]
    for i in range(len(self.byus)):
      if self.byus[i] == "X":
        self.byus[i] = Style.BRIGHT + Fore.GREEN + self.byus[i] + Style.RESET_ALL
      elif self.byus[i] == "O":
        self.byus[i] = Fore.RED + self.byus[i] + Style.RESET_ALL
    self.ftd = str(
      " " + self.byus[0] + " | " + self.byus[1] + " | " + self.byus[2] +
      " \n―――|―――|―――\n " + self.byus[3] + " | " + self.byus[4] + " | " +
      self.byus[5] + " \n―――|―――|―――\n " + self.byus[6] + " | " +
      self.byus[7] + " | " + self.byus[8] + " \n")
    self.send(self.ftd)
    
  def send(self, text, other=""):
    if other == "":
      sys.stdout.write(text.replace("Player X", Style.BRIGHT + Fore.GREEN + "Player X" + Style.RESET_ALL).replace("Player O", Fore.RED + "Player O" + Style.RESET_ALL).replace(" X ", Style.BRIGHT + Fore.GREEN + " X " + Style.RESET_ALL).replace(" O ", Fore.RED + " O " + Style.RESET_ALL))
    elif other == "":
      sys.stdout.write(text)

  def ask(self, text, bores=False, other=""):
    while True:
      if other == "":
        self.bob4 = input(text.replace("Player X", Style.BRIGHT + Fore.GREEN + "Player X" + Style.RESET_ALL).replace("Player O", Fore.RED + "Player O" + Style.RESET_ALL).replace(" X ", Style.BRIGHT + Fore.GREEN + " X " + Style.RESET_ALL).replace(" O ", Fore.RED + " O " + Style.RESET_ALL)).lower()
      else:
        self.bob4 = input(text)
      if self.bob4 in self.quits:
        while True:
          clear()
          self.quitcheck = input(Fore.RED + "Are you sure you want to quit? (Y/n)\n>>> " + Style.RESET_ALL).lower()
          clear()
          if self.quitcheck in self.yeps or self.quitcheck == "":
            clear()
            self.randomfact = random.choice(self.facts)
            self.randominsult = random.choice(self.insults)
            sys.stdout.write("Thank you for playing Tic-Tac-Toe!\n\n" + Style.BRIGHT + Fore.GREEN + "Random Fun Fact:\n\n{}".format(self.randomfact) + Style.RESET_ALL + Fore.MAGENTA + "\n\nRandom Insult (Please don't take this seriously!):\n\n{}".format(self.randominsult) + Style.RESET_ALL + Fore.BLUE + "\n\nSource(s):\nhttps://www.improgrammer.net/programming-facts/\nhttp://pun.me/pages/funny-insults.php" + Style.RESET_ALL + "\n")
            sys.exit(0)
          elif self.quitcheck in self.nahs:
            clear()
            break
        if bores:
          self.printBoard()
      elif self.bob4 in self.helps:
        clear()
        input(Fore.CYAN + "This version of the game Tic-tac-toe is made by richtan. The original game was thought to be created as early as 1300 BCE in ancient Egypt.\n\nTo start, choose who you want to play with and your marker to use. To play, choose one of the squares in the 3 by 3 grid to place your marker in by typing one of the numbers from one to nine corresponding to the square you want to pick. The goal of the game is to get three of your markers in a row either horizontally, vertically, or diagonally before your opponent does. For more information, go to this website:\n\n https://en.wikipedia.org/wiki/Tic-tac-toe.\n\nCommands:\n'quit': to quit, there will be confirmation\n'help': to get help on how to play\n'funfacts': learn some fun facts about Tic-tac-toe\n'restart': restart the game, there will be confirmation\n\nHave fun!\n\n(Press enter to continue)\n" + Style.RESET_ALL)
        clear()
        if bores:
          self.printBoard()
      elif self.bob4 in self.funfacts:
        for i in self.funfacs:
          self.ttr += "\n" + u"\u2022" + i
        clear()
        input(Fore.CYAN + "Here are some fun facts about Tic-tac-toe:\n{}\n\nSources:\nhttps://en.wikipedia.org/wiki/Tic-tac-toe\nhttps://www.jesperjuul.net/ludologist/2003/12/28/255168-ways-of-playing-tic-tac-toe/\n\n(Press enter to continue)".format(self.ttr) + Style.RESET_ALL)
        clear()
        if bores:
          self.printBoard()
      elif self.bob4 in self.restarts:
        while True:
          clear()
          self.quitcheck = input(Fore.MAGENTA + "Are you sure you want to restart the game? (Y/n)\n>>> " + Style.RESET_ALL).lower()
          clear()
          if self.quitcheck in self.yeps or self.quitcheck == "":
            if not "" in [self.oppui, self.mistermk, self.typ, self.difu, self.ggyhaha]:
              while True:
                try:
                  self.guy = self.ask("Would you like to use the same settings? (Y/n)\n>>> ").lower()
                  if self.guy in self.yeps or self.guy == "":
                    self.samesettings = True
                    break
                  elif self.guy in self.nahs:
                    self.samesettings = False
                    break
                  raise ValueError
                except ValueError:
                  clear()
                  self.send("Please enter a valid input.\n")
            clear()
            self.send("Restarting...\n")
            time.sleep(0.5)
            clear()
            self.start()
          elif self.quitcheck in self.nahs:
            clear()
            break
        if bores:
          self.printBoard()
      else:
        return self.bob4

  def start(self):
    self.send(Style.RESET_ALL)
    if not self.samesettings:
      self.__init__()
      clear()
      self.send("Welcome to (or back to) Tic-Tac-Toe by richtan!\n697 lines of code were used to make this game.\n\n")
      while True:
        try:
          self.player = self.ask("Would you like to play against a human or against the computer? (Ai/hum)\n>>> ").lower()
          if self.player in self.pos1 + self.pos2:
            break
          else:
            raise ValueError
        except ValueError:
          clear()
          self.send("Please enter a valid input.\n")
      if self.player in self.pos2:
        clear()
        while True:
          try:
            self.dif = self.ask("Please select a diffuculty (Easy -b, for beginner-, Medium -m-, Hard -d-, Extreme -e-, or Impossible -i-):\n>>> ").lower()
            if self.dif in self.diffs1 + self.diffs2 + self.diffs3 + self.diffs4 + self.diffs5:
              break
            else:
              raise ValueError
          except ValueError:
            clear()
            self.send("Please enter a valid input.\n")
    elif self.samesettings:
      self.redef()
      clear()
      if self.player in self.pos1:
        self.oppui = "Human"
        self.mistermk = "Player 1's marker"
        self.ggyhaha = "\nPlayer 2's marker: " + self.othtyp
        self.ask("Settings have been saved from the last game.\n\nThe settings saved are:\n\nOpponent: {opponent}\n{person}: {marker}{pertrand}\n\nNo need to thank me :)\n\n(Press enter to continue)".format(opponent=self.oppui, person=self.mistermk, marker=self.typ, pertrand=self.ggyhaha).replace(" X", Style.BRIGHT + Fore.GREEN + " X " + Style.RESET_ALL).replace(" O", Fore.RED + " O " + Style.RESET_ALL), other="plsno")
      elif self.player in self.pos2:
        self.oppui = "Computer/AI"
        self.mistermk = "Your marker"
        self.ggyhaha = "\nComputer/AI's marker: " + self.othtyp
        if self.dif in self.diffs1:
          self.difu = "Easy"
        elif self.dif in self.diffs2:
          self.difu = "Medium"
        elif self.dif in self.diffs3:
          self.difu = "Hard"
        elif self.dif in self.diffs4:
          self.difu = "Extreme"
        elif self.dif in self.diffs5:
          self.difu = "Impossible"
        self.ask("Settings have been saved from the last game.\n\nThe settings saved are:\n\nOpponent: {opponent}\nDifficulty: {difficulty}\n{person}: {marker}{pertrand}\n\nNo need to thank me :)\n\n(Press enter to continue)".format(opponent=self.oppui, difficulty=self.difu, person=self.mistermk, marker=self.typ, pertrand=self.ggyhaha).replace(" X", Style.BRIGHT + Fore.GREEN + " X " + Style.RESET_ALL).replace(" O", Fore.RED + " O " + Style.RESET_ALL), other="plsno")
        
      clear()
    self.play(self.player)

  def play(self, oppn):
    clear()
    if oppn in self.pos2:
      self.aifirst = (random.randint(1, 2) == 1)
      #self.aifirst = False # for testing xxx
      self.agcom()
    elif oppn in self.pos1:
      self.aghum()
    while True:
      try:
        self.guy = self.ask("Would you like to play again? (Y/n)\n>>> ").lower()
        if self.guy in self.yeps or self.guy == "":
          break
        elif self.guy in self.nahs:
          while True:
            clear()
            self.quitcheck = input(Fore.RED + "Are you sure you want to quit? (Y/n)\n>>> " + Style.RESET_ALL).lower()
            clear()
            if self.quitcheck in self.yeps or self.quitcheck == "":
              clear()
              self.randomfact = random.choice(self.facts)
              self.randominsult = random.choice(self.insults)
              sys.stdout.write("Thank you for playing Tic-Tac-Toe!\n\n" + Style.BRIGHT + Fore.GREEN + "Random Fun Fact:\n\n{}".format(self.randomfact) + Style.RESET_ALL + Fore.MAGENTA + "\n\nRandom Insult (Please don't take this seriously!):\n\n{}".format(self.randominsult) + Style.RESET_ALL + Fore.BLUE + "\n\nSource(s):\nhttps://www.improgrammer.net/programming-facts/\nhttp://pun.me/pages/funny-insults.php" + Style.RESET_ALL + "\n")
              sys.exit(0)
            elif self.quitcheck in self.nahs:
              clear()
              break
        raise ValueError
      except ValueError:
        clear()
        self.send("Please enter a valid input.\n")
    clear()
    while True:
      try:
        self.guy = self.ask("Would you like to use the same settings? (Y/n)\n>>> ").lower()
        if self.guy in self.yeps or self.guy == "":
          self.samesettings = True
          break
        elif self.guy in self.nahs:
          self.samesettings = False
          break
        raise ValueError
      except ValueError:
        clear()
        self.send("Please enter a valid input.\n")
    self.start()

  def agcom(self):
    if not self.samesettings:
      while True:
        try:
          self.typ = self.ask(
            "Would you like to use an X (the letter) or an O (the letter) as your marker?\n>>> "
          ).upper()
          if not (self.typ == "X" or self.typ == "O"):
            raise ValueError
          if self.typ == "X":
            self.othtyp = "O"
          elif self.typ == "O":
            self.othtyp = "X"
          break
        except ValueError:
          clear()
          self.send("Please enter a valid input.\n")
    clear()
    self.send("Player {} has been chosen to play first!\n\n".format(self.othtyp if self.aifirst else self.typ))
    if not self.aifirst:
      while True:
        self.playerMove()
        if not self.checkWin():
          self.bob = "Player "+ self.typ+ " has placed a marker at spot "+ str(self.ct1) + ".\n"
          self.send(self.bob)
        else:
          break
        self.aiMove()
        if not self.checkWin():
          self.bob = "Player "+ self.othtyp+" has placed a marker at spot "+ str(self.ront)+ ".\n"
          self.send(self.bob)
        else:
          break
    elif self.aifirst:
      while True:
        self.aiMove()
        if not self.checkWin():
          self.bob = "Player "+ self.othtyp+" has placed a marker at spot "+ str(self.ront)+ ".\n"
          self.send(self.bob)
        else:
          break
        self.playerMove()
        if not self.checkWin():
          self.bob = "Player "+ self.typ+ " has placed a marker at spot "+ str(self.ct1) + ".\n"
          self.send(self.bob)
        else:
          break

  def aghum(self):
    if not self.samesettings:
      while True:
        try:
          self.typ = self.ask("Player 1, would you like to use an X or an O as your marker?\n>>> ").upper()
          if not self.typ in self.xos:
            raise ValueError
          if self.typ == "X":
            self.othtyp = "O"
          elif self.typ == "O":
            self.othtyp = "X"
          clear()
          self.othyu = "Player 1, you will be using an " + self.typ + " as your marker.\nPlayer 2, you will be using an " + self.othtyp + " as your marker.\n"
          self.send(self.othyu)
          break
        except ValueError:
          clear()
          self.send("Please enter a valid input.\n")
    self.send("\nPlayer {} has been chosen to play first!\n".format(self.othtyp if self.aifirst else self.typ))
    while True:
      self.player1move()
      if not self.checkWin():
        self.bob = "Player "+ self.typ+ " has placed a marker at spot "+ str(self.ct1) + ".\n"
        self.send(self.bob)
      else:
        break
      self.player2move()
      if not self.checkWin():
        self.bob = "Player "+ self.othtyp+" has placed a marker at spot "+ str(self.ct1)+ ".\n"
        self.send(self.bob)
      else:
        break
  
  def player1move(self):
    self.printBoard()
    while True:
      try:
        self.ct1 = int(
          self.ask(
            "Player "+ self.typ+", please select a number from 1 to 9 to place one of your markers in that location:\n>>> "
          , True))
        if not int(self.ct1) - 1 in range(9) or self.board[self.ct1 - 1] in self.xos:
          raise TypeError
        self.board[self.ct1 - 1] = self.typ
        clear()
        break
      except (ValueError, TypeError):
        clear()
        self.printBoard()
        self.send("Please enter a valid input.\nThat spot may have been taken. If so, please choose another spot.\n\n")
        
  def player2move(self):
    self.printBoard()
    while True:
      try:
        self.ct1 = int(
          self.ask(
            "Player "+ self.othtyp+", please select a number from 1 to 9 to place one of your markers in that location:\n>>> "
          , True))
        if not int(self.ct1) - 1 in range(9) or self.board[self.ct1 - 1] in self.xos:
          raise TypeError
        self.board[self.ct1 - 1] = self.othtyp
        clear()
        break
      except (ValueError, TypeError):
        clear()
        self.printBoard()
        self.send("Please enter a valid input.\nThat spot may have been taken. If so, please choose another spot.\n\n")

  def playerMove(self):
    self.printBoard()
    while True:
      try:
        self.ct1 = int(
          self.ask(
            "Player "+ self.typ+", please select a number from 1 to 9 to place one of your markers in that location:\n>>> "
          , True))
        if not int(self.ct1) - 1 in range(9) or (self.board[self.ct1 - 1] == "X" or self.board[self.ct1 - 1] == "O"):
          raise TypeError
        self.board[self.ct1 - 1] = self.typ
        clear()#wwwe
        self.plyturn += 1
        break
      except (ValueError, TypeError):
        clear()
        self.printBoard()
        self.send("Please enter a valid input.\nThat spot may have been taken. If so, please choose another spot.\n\n")

  def aiMove(self):
    self.ytp == ""
    self.ront = None
    self.gona = False
    self.cobr = random.randint(1, 4)
    self.cobt = random.randint(1, 4)
    if self.dif in self.diffs1:
      #print(1)
      self.dif1()
    elif self.dif in self.diffs2:
      #print(2)
      self.dif2()
    elif self.dif in self.diffs3:
      #print(3)
      self.dif3()
    elif self.dif in self.diffs4:
      #print(4)
      self.dif4()
    elif self.dif in self.diffs5:
      #print(5)
      self.dif5()

  def dif1(self):
    while True:
      self.ront = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9])
      if self.board[self.ront-1] in self.xos:
        continue
      self.board[self.ront-1] = self.othtyp
      self.gona = True
      break
        
  def checkwincom(self):
    for a, b, c in self.wincombos:
      if self.board[a] == self.board[b] == self.othtyp and not self.board[c] in self.xos:
        self.ront = c+1
        self.ytp = "haha"
        #print("1")
        break
      elif self.board[a] == self.board[c] == self.othtyp and not self.board[b] in self.xos:
        self.ront = b+1
        self.ytp = "haha"
        #print("2")
        break
      elif self.board[b] == self.board[c] == self.othtyp and not self.board[a] in self.xos:
        self.ront = a+1
        self.ytp = "haha"
        #print("3")
        break
    else:
      for a, b, c in self.wincombos:
        if self.board[a] == self.board[c] == self.typ and not self.board[b] in self.xos:
          self.ront = b+1
          self.ytp = "haha"
          #print("4")
          break
        elif self.board[b] == self.board[c] == self.typ and not self.board[a] in self.xos:
          self.ront = a+1
          self.ytp = "haha"
          #print("5")
          break
        elif self.board[a] == self.board[b] == self.typ and not self.board[c] in self.xos:
          self.ront = c+1
          self.ytp = "haha"
          #print("6")
          break

  def dif2(self):
    self.ytp = ""
    self.checkwincom()
    if self.ytp == "haha":
      pass
    else:
      self.dif1()
    if not self.gona:
      self.board[self.ront-1] = self.othtyp
    
  def dif3(self):
    self.ytp = ""
    self.checkwincom()
    if self.ytp == "haha":
      pass
    while not self.ytp == "haha":
      if not self.board[4] in self.xos:
        self.ront = 5
        break
      elif self.cobr == 1 and not self.board[0] in self.xos:
        self.ront = 1
        break
      elif self.cobr == 2 and not self.board[2] in self.xos:
        self.ront = 3
        break
      elif self.cobr == 3 and not self.board[6] in self.xos:
        self.ront = 7
        break
      elif self.cobr == 4 and not self.board[8] in self.xos:
        self.ront = 9
        break
      elif self.cobt == 1 and not self.board[1] in self.xos:
        self.ront = 2
        break
      elif self.cobt == 2 and not self.board[3] in self.xos:
        self.ront = 4
        break
      elif self.cobt == 3 and not self.board[5] in self.xos:
        self.ront = 6
        break
      elif self.cobt == 4 and not self.board[7] in self.xos:
        self.ront = 8
        break
      else:
        self.dif1()
        break
    if not self.gona:
      self.board[self.ront-1] = self.othtyp

  def dif4(self):
    self.ytp = ""
    self.checkwincom()
    if self.ytp == "haha":
      #print("11111")
      pass
    elif not self.board[4] in self.xos:
      self.ront = 5
      #print("22222")
    elif int(self.ct1) - 1 in [0, 2, 6, 8] and not self.board[{0:8,8:0,2:6,6:2,1:"X",3:"X",4:"X",5:"X",7:"X"}[int(self.ct1) - 1]] in self.xos:
      self.ront = {0:8,8:0,2:6,6:2}[int(self.ct1) - 1] + 1
      #print("33333")
    elif not self.board[0] in self.xos or not self.board[2] in self.xos or not self.board[6] in self.xos or not self.board[8] in self.xos:
      while True:
        self.ront = random.choice([1, 3, 7, 9])
        if not self.board[self.ront-1] in self.xos:
          break
      #print("44444")
    elif not self.board[1] in self.xos or not self.board[3] in self.xos or not self.board[5] in self.xos or not self.board[7] in self.xos:
      while True:
        self.ront = random.choice([2, 4, 6, 8])
        if not self.board[self.ront-1] in self.xos:
          break
      #print("55555")
    else:
      self.dif1()
      #print("66666")
    if not self.gona:
      self.board[self.ront-1] = self.othtyp
  
  def dif5(self):
    self.turn += 1
    self.ytp = ""
    self.checkwincom()
    if self.ytp == "haha":
      pass
    elif self.aifirst:
      if self.turn == 1:
        self.ront = 5
      elif self.turn == 2:
        if self.ct1 in [2, 4, 6, 8]:
          if self.ct1 in [2, 4]:
            self.ront = 9
          elif self.ct1 in [6, 8]:
            self.ront = 1
        elif self.ct1 in [1, 3, 7, 9]:
          self.ront = {0:8,8:0,2:6,6:2}[int(self.ct1) - 1] + 1
      else:
        self.dif1()
    elif not self.aifirst:
      if self.turn == 1:
        if self.ct1 in [1, 3, 7, 9]:
          self.ront = 5
        elif self.ct1 in [2, 4, 6, 8]:
          if self.ct1 in [2, 4]:
            self.ront = 1
          elif self.ct1 in [6, 8]:
            self.ront = 9
        elif self.ct1 == 5:
          while True:
            self.ront = random.choice([1, 3, 7, 9])
            if not self.board[self.ront-1] in self.xos:
              break
      elif self.turn == 2:
        if self.last2turn == 5:
          if self.ct1 in [1, 3, 7, 9]:
            while True:
              self.ront = random.choice([1, 3, 7, 9])
              if not self.board[self.ront-1] in self.xos:
                break
        elif self.last2turn in [1, 3, 7, 9]:
          if self.ct1 in [1, 3, 7, 9]:
            while True:
              self.ront = random.choice([2, 4, 6, 8])
              if not self.board[self.ront-1] in self.xos:
                break
          elif self.ct1 in [2, 4, 6, 8]:
            if [self.last2turn, self.ct1] in [[3,4],[7,2]]:
              self.ront = 1
            elif [self.last2turn, self.ct1] in [[1,6],[9,2]]:
              self.ront = 3
            elif [self.last2turn, self.ct1] in [[9,4],[1,8]]:
              self.ront = 7
            elif [self.last2turn, self.ct1] in [[3,8],[7,6]]:
              self.ront = 9
            else:
              self.dif1()
        elif self.last2turn in [2, 4, 6, 8]:
          self.ront = 5
        else:
          self.dif1()
      else:
        self.dif1()
    else:
      self.dif1()
    if not self.gona:
      self.board[self.ront-1] = self.othtyp
    self.last2turn = self.ct1

  def checkWin(self):
    self.count = 0
    for a in self.wincombos:
      if self.board[a[0]] == self.board[a[1]] == self.board[a[2]] == "X":
        self.printBoard()
        self.send("Player X Wins! Congratulations, Player X!\n")
        return True
      if self.board[a[0]] == self.board[a[1]] == self.board[a[2]] == "O":
        self.printBoard()
        self.send("Player O Wins! Congratulations, Player O!\n")
        return True
    for a in range(9):
      if self.board[a] == "X" or self.board[a] == "O":
        self.count += 1
      if self.count == 9:
        self.printBoard()
        self.send("The game ends in a Tie. Better luck next time!\n")
        return True

game = Tictactoe()
game.start()
?