<jupyter_start><jupyter_text>Tic Tac Toe<jupyter_code>def display_board() :
    print(' |  | ')
    print('------')   
    print(' |  | ')
    print('------')
    print(' |  | ')
display_board()
board = ['O','X','O','X','O','X','O','X','O','X']
from IPython.display import clear_output
def display_board(board) :
    clear_output()
    print('  | | ')
    print(' '+board[7]+'|'+board[8]+'|'+board[9])
    print(' -------')
    print(' '+board[4]+'|'+board[5]+'|'+board[6])
    print(' -------')
    print(' '+board[1]+'|'+board[2]+'|'+board[3])
display_board(board)<jupyter_output>| | 
 x|o|x
 -------
 o|x|o
 -------
 x|o|x<jupyter_text>Assigning of the marker to the player<jupyter_code>def player_input():
    marker = ''
    while not (marker == 'X' or marker =='O') :
        marker = input('Player One : Player enter your marker X or O :').upper()
    
    if marker == 'X' :
       return ('X','O')
    else :
        return ('O','X')
player_input()<jupyter_output>Player One : Player enter your marker X or O :k
Player One : Player enter your marker X or O :w
Player One : Player enter your marker X or O :x<jupyter_text>Step 3 -Placing the Marker<jupyter_code>def place_marker(board,marker,position) :
    board[position] = marker
    
board
place_marker(board,'X',2)
board<jupyter_output><empty_output><jupyter_text>Step 4 - Check if we have any winner<jupyter_code>def win_check(board,marker) :
    my_boolean = ((board[1] == marker and board[2] == marker and board[3] == marker) or
                  (board[4] == marker and board[5] == marker and board[6] == marker) or 
                  (board[7] == marker and board[8] == marker and board[9] == marker) or
                  (board[7] == marker and board[4] == marker and board[1] == marker) or
                  (board[8] == marker and board[5] == marker and board[2] == marker) or
                  (board[9] == marker and board[6] == marker and board[3] == marker) or
                  (board[7] == marker and board[5] == marker and board[3] == marker) or
                  (board[9] == marker and board[5] == marker and board[1] == marker))   
    return my_boolean
win_check(board,'O')

display_board(board)<jupyter_output>| | 
 X|O|X
 -------
 O|X|O
 -------
 X|O|X<jupyter_text>Step 5 - Randomly selecting a player to go first<jupyter_code>import random
def choose_first() :
    if random.randint(1,2) == 1 :
       return 'Player 1'
    else :
        return 'Player 2'
choose_first()
choose_first()<jupyter_output><empty_output><jupyter_text>Step 6 - Check the position is empty or not<jupyter_code>def space_check(board,position) :
    return board[position] == ''
space_check(board,9)<jupyter_output><empty_output><jupyter_text>Step 7 - Check board is full or not<jupyter_code>def full_board_check(board) :
    for i in range(1,10) :       
        if(space_check(board,i)) :
            return False
    else :
        return True
full_board_check(board)<jupyter_output><empty_output><jupyter_text>Step 8 - Players next position and value is available or not<jupyter_code>def next_player_choice(board) :
    position = 0
    while position not in [1,2,3,4,5,6,7,8,9] or not space_check(board,position) :
        position = int(input("Enter the position(1 to 9) : "))
    return position
next_player_choice(board)<jupyter_output>Enter the position(1 to 9) : 3<jupyter_text>Step 9 - Play again or not<jupyter_code>def play_again() :
    return input('Do you wish to play again this game, (yes or no): ').lower().startswith('y')
play_again()<jupyter_output>Do you wish to play again this game, (yes or no): y<jupyter_text>Final Assemble of the code<jupyter_code>print("Welcoming the Player for Tic Tac Toe")
while True :
    newBoard = [''] *10
    player1_marker,player2_marker = player_input()
    turn = choose_first()
    print(turn+ 'Will go first in this game')
    play_game = input('Are you ready? Yes or No')
    if(play_game.lower()[0] =='y') :
        game_on = True
    else :
        game_on = False
     
    while game_on:
        if turn == 'Player 1' :
            display_board(newBoard)
            position = next_player_choice(newBoard)
            place_marker(newBoard,player1_marker,position)
            
            if win_check(newBoard,player1_marker) :
                 display_board(newBoard)
                    print('Congrats! You have won the Game!')
                    game_on = False
            else :
                if full_board_check(newBoard):
                    display_board(newBoard)
                    print('Game has been drawn')
                    break
                else :
                    turn = 'Player 2'
        else :
            display_board(newBoard)
            position = next_player_choice(newBoard)
            place_marker(newBoard,player2_marker,position)
            
            if win_check(newBoard,player2_marker) :
                 display_board(newBoard)
                    print('Congrats! You have won the Game!')
                    game_on = False
            else :
                if full_board_check(newBoard):
                    display_board(newBoard)
                    print('Game has been drawn')
                    break
                else :
                    turn = 'Player 1'
                    
    if not playagain():
        break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13555513948698747, 'fraction_numerical': 0.014416775884665793, 'mean_word_length': 2.471085120207927, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '300492', 'license': 'MIT', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1688, 'n_words': 419, 'path': 'Tic Tac Toe Game.ipynb', 'repo_name': 'Velliyangiri/PythonTraining', 'size': '5341'}