-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathttt.py
66 lines (58 loc) · 2.03 KB
/
ttt.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
import random
from printBoard import printBoard
from winChecker import winChecker, winnerPrinter
from thinking_process import think, randomMove
#-----------------------------------------------------------------------------------------------
print('+--------------------------------------------------------------------')
print('| Welcome to Akylus\' Tic-Tac-Toe.')
print('| This is a basic render of the game and is not very smart as of now.')
print('| But feel free to play and give your opinion.')
print('+--------------------------------------------------------------------')
print()
print('Game works like this. Below is the code you need to put for that corresponding box.')
print('top-L','|','top-M','|','top-R')
print('---------------------')
print('mid-L','|','mid-M','|','mid-R')
print('---------------------')
print('low-L','|','low-M','|','low-R')
print()
#-----------------------------------------------------------------------------------------------
ipvalues = [
'top-L', 'top-M', 'top-R',
'mid-L', 'mid-M', 'mid-R',
'low-L', 'low-M', 'low-R'
]
board = {
'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '
}
print('Choose: X or O?')
while(1):
player = input().upper()
if(player != 'X' and player != 'O'):
print('Enter X or O only! Please Try Again. :)')
else:
break
if(player == 'X'):
cpu = 'O'
else:
cpu = 'X'
while(1):
print("Enter move:")
while(1):
temp = input()
temp = temp[:4] + temp[-1].capitalize()
if(temp not in ipvalues):
print('Enter valid input! Please Try Again. :)')
elif(board[temp] != ' '):
print('Already placed. Please Try Again. :)')
else:
break
board[temp] = player
if(winnerPrinter(board,player,cpu)):
break
board[think(board,temp,player)] = cpu
if(winnerPrinter(board,player,cpu)):
break
printBoard(board)