-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormal_Python.py
More file actions
65 lines (63 loc) · 2.68 KB
/
Normal_Python.py
File metadata and controls
65 lines (63 loc) · 2.68 KB
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
#Python 3.9.5
#Compute by Ace Fhid
from random import choice
x, o = '\033[038;2;255;102;102mX\033[0;0m', '\033[038;2;102;199;255mO\033[0;0m'
Board = {
'7':' ', '8':' ', '9':' ',
'4':' ', '5':' ', '6':' ',
'1':' ', '2':' ', '3':' ',}
def DisplayBoard(board):
print('\033[038;2;255;175;36m{}\033[038;2;255;175;36m|{}\033[038;2;255;175;36m|{}'.format(board['7'], board['8'], board['9']))
print('\033[038;2;255;175;36m-+-+-')
print('\033[038;2;255;175;36m{}\033[038;2;255;175;36m|{}\033[038;2;255;175;36m|{}'.format(board['4'], board['5'], board['6']))
print('\033[038;2;255;175;36m-+-+-')
print('\033[038;2;255;175;36m{}\033[038;2;255;175;36m|{}\033[038;2;255;175;36m|{}\033[0;0m'.format(board['1'], board['2'], board['3']))
def CheckWin():
return (Board['7'] == Board['8'] == Board['9'] != ' ') or (Board['4'] == Board['5'] == Board['6'] != ' ') or (Board['1'] == Board['2'] == Board['3'] != ' ') or (Board['8'] == Board['5'] == Board['2'] != ' ') or (Board['7'] == Board['4'] == Board['1'] != ' ') or (Board['9'] == Board['6'] == Board['3'] != ' ') or (Board['7'] == Board['5'] == Board['3'] != ' ') or (Board['9'] == Board['5'] == Board['1'] != ' ')
def repeat():
Repeat = input("\033[038;2;128;230;255mWanna Repeat(y/n) : ")
if Repeat.lower() == 'y' or repeat == 1:
for i in Board.keys():
Board[i] = ' '
game()
elif Repeat.lower() == 'n' or repeat == 0:
print("\033[038;2;210;156;255mGood Bye\033[0;0m")
def Player(turn):
DisplayBoard(Board)
running = True
filled = False
while running:
if not filled:
txt = "{}\033[038;2;128;230;255m turn. Move to which place?".format(turn)
else:
txt = "\033[038;2;255;128;128mCan't place there. Move to other place"
print(txt)
next_ = input("Enter Move : ")
if next_.lower() == "end":
raise SystemExit
if Board[next_] == ' ':
return next_
else:
filled = True
def game():
XO = {x:o, o:x}
turn = choice(list(XO.keys()))
run = True
count = 0
while run:
move = Player(turn)
count += 1
Board[move] = turn
win = CheckWin()
if win:
DisplayBoard(Board)
print("\n\033[038;2;255;175;36m-{} \033[038;2;255;175;36mWin-\n\033[0;0m".format(turn))
run = False
if all(Board[i] != ' ' for i in Board.keys()) and not win:
DisplayBoard(Board)
print("\n\033[038;2;255;175;36m-Draw!-\n\033[0;0m".format(turn))
run = False
turn = XO[turn]
repeat()
if __name__ == "__main__":
game()