示例#1
0
def check_for_treasures(room, hero, game_board, monsters_in_room):

    t_sum = 0
    for treasure in room.treasure_list:
        t_sum += treasure[1]
    hero.points_current_game += t_sum

    main.print_board(game_board, hero)

    if len(room.treasure_list) > 0:

        if not monsters_in_room:
            print('\nInga monster i rummet.')
        else:
            print('\nAlla monster besegrade.')
        print('Du hittade skatter i rummet:\n')

        i = 0
        for treasure in room.treasure_list:
            print(treasure[0])
            i += treasure[1]

        print(f'\nTotalt värde: {i}')
        print('Skatten är tillagd i din ryggsäck.')

        room.treasure_list = []
        room.set_room_symbol()
    else:
        if not monsters_in_room:
            print('\nInga monster i rummet.')
        else:
            print('\nAlla monster besegrade.')
        print('Inga skatter hittades i rummet.')
        room.set_room_symbol()
示例#2
0
def hero_flee(hero, game_board, monster_list, room, grid_size, room_list):
    print(f"\n{hero.name} Försöker att fly...")
    escape_try = escape_monster(hero)
    delay_in_fight()
    if escape_try:
        if hero.hero_class == "Trollkarl":
            print("\nLjussken!")
        print('\nDu lyckades fly från monstret')
        game_board[hero.coordinates[0]][hero.coordinates[1]] = '[ ]'
        hero.coordinates = hero.previous_coordinates
        main.place_hero(hero.coordinates, game_board)
        input('\n-- Tryck på enter för att fortsätta --')

        for monster in monster_list:
            if monster.resistance > 0:
                monster.heal_remaining_monster()
            else:
                room.remove_dead_monsters()

        main.print_board(game_board, hero)
        main.walk_on_board(hero, grid_size, game_board, room_list)

    else:
        print(f'\n{hero.name} lyckades inte fly ')
        input('\n-- Tryck på enter för att fortsätta --')
示例#3
0
def check_for_monsters(hero, grid_size, game_board, room_list, room):
    if len(room.monster_list) > 0:

        main.print_board(game_board, hero)

        print(f"\nDu gick in i ett rum med {len(room.monster_list)} monster:")
        i = 1
        for monster in room.monster_list:
            print(f"{i}. {monster.name}")
            i += 1
        start_fight_message(room.monster_list, hero)

        input('\n-- Tryck på enter för att fortsätta --')
        fight(hero, grid_size, game_board, room_list, room)
    else:
        return False
示例#4
0
def check_for_living_monsters(room, game_board, hero, grid_size, room_list):

    monsters_alive = []
    for monster in room.monster_list:

        if monster.resistance > 0:
            monsters_alive.append(monster)

    if len(monsters_alive) == 0:
        room.monster_list = []
        room.set_room_symbol()
        room.sum_of_treasures = 0
        main.print_board(game_board, hero)

        check_for_treasures(room, hero, game_board, True)
        main.walk_on_board(hero, grid_size, game_board, room_list)
示例#5
0
def check_room(coordinates, room_list, hero, game_board, start_coordinates,
               grid_size):

    for room in room_list:
        if room.coordinates == coordinates:
            if room.symbol == "[ ]":
                undiscovered_room(room, hero, room_list, game_board, grid_size)
            elif room.symbol == "[O]":
                main.print_board(game_board, hero)
                exit_to_menu = main.exit_map(
                    game_board, (start_coordinates[0], start_coordinates[1]),
                    hero)
                if exit_to_menu:
                    main.clear_screen()
                    save_collected_treasure(hero)

                    main.main_menu()
            elif room.symbol == "[.]":
                main.print_board(game_board, hero)
                print('\nInga monster i rummet.')
                print('Inga skatter hittades i rummet.')
示例#6
0
文件: test.py 项目: lumenghe/game
                    [(7, 4), (5, 2), (3, 4), (1, 2), (3, 0), (5, 2), (7, 0)],
                    [(7, 4), (5, 2), (3, 4), (1, 6)]]
    moves = ai.allowed_moves(board, 'b')
    return board, ground_truth, check_moves(moves, ground_truth)


###############################################################################

if __name__ == "__main__":

    def check_valid_position(test_name, board):
        for row, line in enumerate(board):
            for col, square in enumerate(line):
                if (row + col) % 2 == 0:
                    if square != '_':
                        raise Exception(
                            "Ground truth for %s at row %d and column %d (starting at 0) is not valid, it should be '_' as it is a white square."
                            % (test_name, row, col))

    for test_name in dir():
        if test_name.startswith("test_"):
            print("Running '%s':" % test_name)
            (board, ground_truth, ok) = eval("%s()" % test_name)
            check_valid_position(test_name, board)
            if not ok:
                main.print_board(board)
                break
    if ok:
        print(
            "You are good to go ! You can try your script against the other side one with 'make'"
        )
示例#7
0
                board[randy][randx] = rand_val
                cnt += 1
                if cnt > 9:
                    return False
            cnt = 0
            while not solver.solve(board):
                rand_val = random.randint(1,9)
                board = copy.deepcopy(initial)
                board[randy][randx] = rand_val
                cnt += 1
                if cnt > 9:
                    return False
            initial[randy][randx] = rand_val
            board = copy.deepcopy(initial)
            cst2 += 1

    return board

def main():
    difficulty = 5-int(input("Select difficulty: Very Easy (0), Easy (1), Medium(2), Hard(3), Insane(4)"))
    assert difficulty > 0 and difficulty <= 5, "Invalid entry"

    return generate(difficulty)

if __name__ == "__main__":
    board = main()
    if type(board) == bool:
        print("Generating failed")
    else:
        solver.print_board(board)
示例#8
0
def function_incorrect(board):
    print("FAIL on ")
    print_board(board)
    exit(1)