Example #1
0
def computers_vs_computer_one():

    ships = {
        'P': 2,  # Patrol Boat
        'D': 3,  # Destroyer
        'S': 3,  # Submarine
        'B': 4,  # Battleship
        'A': 5  # Aircraft Carrier
    }
    # create tron
    tron = AI_Easy()
    tron_board = Board(10, 10)
    tron.place_ships(tron_board, ships)
    original_tron = Board(10, 10)
    original_tron.spaces = deepcopy(tron_board.spaces)

    # create clu
    clu = AI_Easy()
    clu_board = Board(10, 10)
    clu.place_ships(clu_board, ships)
    original_clu = Board(10, 10)
    original_clu.spaces = deepcopy(clu_board.spaces)

    no_winner = True
    # Let the Games BEGIN!
    while no_winner:

        bool_ships = {
            'P': True,  # Patrol Boat
            'D': True,  # Destroyer
            'S': True,  # Submarine
            'B': True,  # Battleship
            'A': True  # Aircraft Carrier
        }
        # Tron's Turn
        print "tron's turn..."
        #time.sleep( 2 )
        tron.take_turn(clu_board, original_clu)
        #clu_board.display()
        tron.which_ships_are_sunk(bool_ships, clu_board)
        if is_win(bool_ships):
            print "game over tron wins"
            break

        bool_ships = {
            'P': True,  # Patrol Boat
            'D': True,  # Destroyer
            'S': True,  # Submarine
            'B': True,  # Battleship
            'A': True  # Aircraft Carrier
        }
        # Clu's turn
        print "Clu's turn..."
        #time.sleep( 2 )
        clu.take_turn(tron_board, original_tron)
        #tron_board.display()
        clu.which_ships_are_sunk(bool_ships, tron_board)
        if is_win(bool_ships):
            print "game over clu wins"
            break
Example #2
0
def player_vs_computer():
    still_playing = True
    while still_playing:
        not_valid_input = True
        while not_valid_input:
            level = 'hard'
            # create AI
            if level.lower() == 'easy':
                clu = AI_Easy()
                not_valid_input = False
            elif level.lower() == 'medium':
                clu = AI_Intermediate()
                not_valid_input = False
            elif level.lower() == 'hard':
                clu = AI_Expert()
                not_valid_input = False

        ships = {
            'P': 2,  # Patrol Boat
            'D': 3,  # Destroyer
            'S': 3,  # Submarine
            'B': 4,  # Battleship
            'A': 5  # Aircraft Carrier
        }

        # create the user_board
        user_board = Board(10, 10)
        user_hit_board = Board(10, 10)
        original_user_board = Board(10, 10)

        # create user
        start = Start_Player()
        start.place_ships(user_board, ships)
        original_user_board.spaces = deepcopy(user_board.spaces)
        user = Player()

        # create the AI
        clu_board = Board(10, 10)
        clu.place_ships(clu_board, ships)
        original_clu_board = Board(10, 10)
        original_clu_board.spaces = deepcopy(clu_board.spaces)

        print " "

        user_hit_board.display()
        no_winner = True
        # Let the Games BEGIN!
        round_count = 0
        while no_winner:

            round_count += 1
            ''' USER MOVE'''
            user.take_turn(user_hit_board, clu_board, original_clu_board)
            user_hit_board.display()
            bool_ships = {
                'P': True,  # Patrol Boat
                'D': True,  # Destroyer
                'S': True,  # Submarine
                'B': True,  # Battleship
                'A': True  # Aircraft Carrier
            }
            user.which_ships_are_sunk(bool_ships, clu_board)
            if is_win(bool_ships):
                user.save_shot_map()
                Game_Stats.write_game_stats(1, round_count, 0, 1)
                print "Game over you win!"
                break
            ''' CLU's TURN '''
            print "Clu's turn..."

            bool_ships = {
                'P': True,  # Patrol Boat
                'D': True,  # Destroyer
                'S': True,  # Submarine
                'B': True,  # Battleship
                'A': True  # Aircraft Carrier
            }
            clu.take_turn(user_board, original_user_board)
            user_board.display()
            print '\n-------------------------'
            user_hit_board.display()
            clu.which_ships_are_sunk(bool_ships, user_board)
            if is_win(bool_ships):
                user.save_shot_map()
                Game_Stats.write_game_stats(1, round_count, 1, 0)
                print "Game over clu wins!"
                break
        response = raw_input("Play Again? (y/n) ")
        if response.lower() == 'n':
            still_playing = False