def single_player_game_cycle():
    table = functions.get_table()
    win_conditions_list = functions.get_win_conditions_list()
    player1_sign = functions.get_player1_sign()
    player2_sign = functions.get_player2_sign(player1_sign)
    checklist = functions.get_checklist(win_conditions_list)
    for i in range(0, 10):
        if i % 2 == 0:
            print(table)
            print("Player 1:")
            player_input = functions.input_check(functions.get_player_input(),
                                                 checklist)
            checklist = functions.remove_input_from_checklist(
                player_input, checklist)
            table = functions.set_mark_on_table(player_input, table,
                                                player1_sign)
            win_conditions_list = functions.add_sign_to_win_cons(
                win_conditions_list, player_input, player1_sign)
            functions.win_check(win_conditions_list, player1_sign, table)
            os.system('clear')
            time.sleep(1)
        else:
            print(table)
            print("player 2:")
            player_input = ai.defensive_and_offensive_instinct(
                checklist, win_conditions_list, player1_sign, player2_sign)
            checklist = functions.remove_input_from_checklist(
                player_input, checklist)
            table = functions.set_mark_on_table(player_input, table,
                                                player2_sign)
            win_conditions_list = functions.add_sign_to_win_cons(
                win_conditions_list, player_input, player2_sign)
            functions.win_check(win_conditions_list, player2_sign, table)
            os.system('clear')
            time.sleep(1)
def multiplayer_game_cycle():
    table = functions.get_table()
    win_conditions_list = functions.get_win_conditions_list()
    player1_sign = functions.get_player1_sign()
    player2_sign = functions.get_player2_sign(player1_sign)
    checklist = functions.get_checklist(win_conditions_list)
    for i in range(0, 9):
        if i % 2 == 0:
            print(table)
            print("Player 1:")
            player_input = functions.input_check(functions.get_player_input(), checklist)
            checklist = functions.remove_input_from_checklist(player_input, checklist)
            table = functions.set_mark_on_table(player_input, table, player1_sign)
            win_conditions_list = functions.add_sign_to_win_cons(win_conditions_list, player_input, player1_sign)
            functions.win_check(win_conditions_list, player1_sign, table)
            os.system('clear')
            time.sleep(1)
        else:
            print()
            print("Player 2:")
            player_input = functions.input_check(functions.get_player_input(), checklist)
            checklist = functions.remove_input_from_checklist(player_input, checklist)
            table = functions.set_mark_on_table(player_input, table, player2_sign)
            win_conditions_list = functions.add_sign_to_win_cons(win_conditions_list, player_input, player2_sign)
            functions.win_check(win_conditions_list, player2_sign, table)
            os.system('clear')
            time.sleep(1)
    print("No winner this time... C'mon, it's an easy game!")
Exemplo n.º 3
0
        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":
                    marker = "O"
                else:
                    marker = "X"
                continue
            else:
                game.display_board(board)
                print("=" * 20 + " It's a TIE." + "=" * 20)
                break
        #Check if we replay, if yes, loop starts again, else it ends and program stops
Exemplo n.º 4
0
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)

print('Test choose_position()')
functions.choose_position(test_board)

print('Test win_check()')
functions.win_check(test_board, 'X')

print('Test replay()')
functions.replay()

print('Test count_down()')
functions.count_down(10)
Exemplo n.º 5
0
        ### 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)
            functions.display_board(gameboard)

            #Break out of the loop if player 1 wins
            if functions.win_check(gameboard,
                                   d_plyr_marker[first_plyr]) == True:
                print(
                    f'Game Over. {first_plyr} (marker:{d_plyr_marker[first_plyr]}) won!'
                )
                game_on = False
                break

            # Chec
            if functions.full_board_check(gameboard) == True:
                print('Game Over. It is a tie!')
                game_on = False
                break

            # Player2's turn.
            print(f'{second_plyr} (marker {d_plyr_marker[second_plyr]}):')
            new_position = functions.choose_position(gameboard)