Beispiel #1
0
    import functions as game

    print("\nWelcome to the Tic Tac Toe Game!")

    while True:
        #Creating a board
        board = ['/', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
        #Randomly select what player goes first
        game.choose_first()
        #Asking the player if they want to be X or O
        marker = game.player_input()

        while True:
            #Display the board of the game
            game.display_board(board)
            #Ask to input a number 1-9
            move = game.player_select_move()
            #Check if space is empty, if it's not continue, else save the marker in board
            if not game.space_check(board, move):
                continue
            else:
                game.place_marker(board, marker, move)
            #Check if anyone has won the game and if so, break inner loop
            if game.win_check(board, marker):
                game.display_board(board)
                print("=" * 20 + marker + " has won." + "=" * 20)
                break
            #Check if the board is full, if not, change markers, if it is, it's a tie at this point
            if not game.full_board_check(board):
                if marker == "X":
Beispiel #2
0
""" 
test.py contains various tests for the functions in functions.py
"""

import functions  #import functions modules

print('Test display_board()')
test_board = ['#', 'O', 'O', 'O', 'X', 'O', 'X', 'O', 'X', 'O']
functions.display_board(test_board)

print('Test display_guide()')
functions.display_guide()

print('Test choose_marker()')
functions.choose_marker()

print('Test player2_marker()')
functions.player2_marker('X')

print('Test place_marker()')
functions.place_marker(test_board, 'X', 1)
functions.display_board(test_board)

print('Test choose_first()')
functions.choose_first()

print('Test space_check()')
functions.space_check(test_board, 2)

print('Test full_board_check()')
functions.full_board_check(test_board)
Beispiel #3
0
    f.clear()

    # Set up game components.
    game_markers = f.assign_markers()
    game_board = ['#', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

    # Initialize game flow control variables.
    player_wins = ['#', False, False]
    positions_available = True

    # Play the game.
    while (player_wins[1] == False
           and player_wins[2] == False) and positions_available:
        for player in range(1, 3):
            f.display_board(game_board)
            game_board = f.update_board(game_board, game_markers, player)
            player_wins[player] = f.check_win(game_board, game_markers, player)
            positions_available = f.check_positions_available(game_board)
            if player_wins[player] or positions_available == False:
                break

    f.display_board(game_board)

    # Determine the game winner.
    if player_wins[1] == player_wins[2]:
        print("The game is tied! No one wins. Womp.\n")
    elif player_wins[1] == True:
        print("Player 1 is the winner! Congratulations!\n")
    elif player_wins[2] == True:
        print("Player 2 is the winner! Congratulations!\n")
Beispiel #4
0
            game_on = True
            break

    #**Checker**#
    #print (game_on)

    #---------------------------------- Game On ------------------------------------
    while game_on == True:

        ###***************************###
        ### STEP 2: PRINT EMPTY BOARD ###
        ###***************************###

        gameboard = ['#'] + [' '] * 9  #Create empty board
        print('GAME STARTS!\n')
        functions.display_board(gameboard)  #Print empty board
        print('\n')

        ###**************************###
        ### STEP 3: GAME PLAY STARTS ###
        ###**************************###

        while functions.full_board_check(gameboard) == False:

            #Player 1 Turn

            #Ask for next position
            print(f'{first_plyr} (marker {d_plyr_marker[first_plyr]}):')
            new_position = functions.choose_position(gameboard)
            functions.place_marker(gameboard, d_plyr_marker[first_plyr],
                                   new_position)
Beispiel #5
0
from functions import assign_marker_to_player
from functions import space_check
from functions import mark_board
from functions import tie_game
from functions import winner_check
from functions import play_again
from functions import decide_turn
if __name__ == '__main__':

    while True:

        print('Welcome to the game of TIC TAC TOE')

        board = create_board()

        display_board(board)

        player1_marker, player2_marker = assign_marker_to_player()

        game_mode = True

        turn = decide_turn()

        while game_mode:

            if turn == 'Player 1':

                display_board(board)

                mark_board(board, player1_marker, turn)
                if winner_check(board, player1_marker):