|
| 1 | +""" |
| 2 | +author: shreyansh kushwaha |
| 3 | +made on : 08.09.2020 |
| 4 | +""" |
| 5 | +board = {'1' : ' ','2' : ' ','3' : ' ','4' : ' ','5' : ' ','6' : ' ','7' : ' ','8' : ' ','9' : ' '} |
| 6 | +import random, os, check, time |
| 7 | +p1 = input("Enter your name player 1 (symbol X):\n") |
| 8 | +p2 = input("Enter your name player 2 (symbol O):\n") |
| 9 | +score1, score2, score_tie = [], [], [] |
| 10 | +total_moves =0 |
| 11 | +player = random.randint(1, 2) |
| 12 | +time.sleep(2.6) |
| 13 | +os.system("cls") |
| 14 | +if player == 1: |
| 15 | + print(f" {p1} won the toss.") |
| 16 | +else: |
| 17 | + print(f" {p2} won the toss") |
| 18 | +time.sleep(3) |
| 19 | +print(" Let us begin") |
| 20 | +time.sleep(2) |
| 21 | +def toggaleplayer(player): |
| 22 | + if player == 1: |
| 23 | + player = 2 |
| 24 | + elif player == 2: |
| 25 | + player = 1 |
| 26 | +def playagain(): |
| 27 | + inp = input("Do you want to play again??(Y/N)\n") |
| 28 | + if inp.upper() == "Y": |
| 29 | + a = toggaleplayer(player) |
| 30 | + restart(a) |
| 31 | + elif inp.upper() == "N": |
| 32 | + os.system("cls") |
| 33 | + print("Thanks for playing") |
| 34 | + print(f"Number of times {p1} won : {len(score1)}.") |
| 35 | + print(f"Number of times {p2} won : {len(score2)}.") |
| 36 | + print(f"Number of ties: {len(score_tie)}.") |
| 37 | + abc = input() |
| 38 | + quit() |
| 39 | + else: |
| 40 | + print("Invalid input") |
| 41 | + quit() |
| 42 | +def restart(a): |
| 43 | + total_moves, board =0, {'1' : ' ','2' : ' ','3' : ' ','4' : ' ','5' : ' ','6' : ' ','7' : ' ','8' : ' ','9' : ' '} |
| 44 | + while True: |
| 45 | + os.system("cls") |
| 46 | + print(board['1'] + '|' + board['2'] + '|' + board['3'] ) |
| 47 | + print('-+-+-') |
| 48 | + print(board['4'] + '|' + board['5'] + '|' + board['6'] ) |
| 49 | + print('-+-+-') |
| 50 | + print(board['7'] + '|' + board['8'] + '|' + board['9'] ) |
| 51 | + check.check(total_moves,score1, score2, score_tie, playagain, board, p1, p2) |
| 52 | + while True: |
| 53 | + if a == 1: |
| 54 | + p1_input = input(f"Its {p1}'s chance..\nwhere do you want to place your move:") |
| 55 | + if p1_input.upper() in board and board[p1_input.upper()] == " ": |
| 56 | + board[p1_input.upper()] = 'X' |
| 57 | + a = 2 |
| 58 | + break |
| 59 | + else: # on wrong input |
| 60 | + print("Invalid input \n Enter again. ") |
| 61 | + continue |
| 62 | + else: |
| 63 | + p2_input = input(f"Its {p2}'s chance..\nwhere do you want to place your move:") |
| 64 | + if p2_input.upper() in board and board[p2_input.upper()] == " ": |
| 65 | + board[p2_input.upper()] = 'O' |
| 66 | + a = 1 |
| 67 | + break |
| 68 | + else: |
| 69 | + print("Invalid Input") |
| 70 | + continue |
| 71 | + total_moves += 1 |
| 72 | +while True: |
| 73 | + os.system("cls") |
| 74 | + print(board['1'] + '|' + board['2'] + '|' + board['3'] ) |
| 75 | + print('-+-+-') |
| 76 | + print(board['4'] + '|' + board['5'] + '|' + board['6'] ) |
| 77 | + print('-+-+-') |
| 78 | + print(board['7'] + '|' + board['8'] + '|' + board['9'] ) |
| 79 | + check.check(total_moves,score1, score2, score_tie, playagain, board, p1, p2) |
| 80 | + while True: |
| 81 | + if player == 1: |
| 82 | + p1_input = input(f"Its {p1}'s chance..\nwhere do you want to place your move:") |
| 83 | + if p1_input.upper() in board and board[p1_input.upper()] == " ": |
| 84 | + board[p1_input.upper()] = 'X' |
| 85 | + player = 2 |
| 86 | + break |
| 87 | + else: # on wrong input |
| 88 | + print("Invalid input ") |
| 89 | + continue |
| 90 | + else: |
| 91 | + p2_input = input(f"Its {p2}'s chance..\nwhere do you want to place your move:") |
| 92 | + if p2_input.upper() in board and board[p2_input.upper()] == " ": |
| 93 | + board[p2_input.upper()] = 'O' |
| 94 | + player = 1 |
| 95 | + break |
| 96 | + else: |
| 97 | + print("Invalid Input") |
| 98 | + continue |
| 99 | + total_moves += 1 |
0 commit comments