online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
''' Press the Green "Run" button above. When you enter a board's corridor press "c" When you enter a room Press "r" To quit press "q" You can "Fork" your own version and change the monster_result table to get different monsters ''' import random dreadnought_encountered = False def roll_dice(num_dice=1, sides=6): return sum(random.randint(1, sides) for _ in range(num_dice)) def difficulty_adjustment(result, difficulty): if difficulty == '1' and result != 'Empty': if roll_dice() == 1: return 'Empty' elif difficulty == '3' and result == 'Empty': if roll_dice() == 1: return room_result(difficulty) if random.choice(['room', 'corridor']) == 'room' else corridor_result(difficulty) return result def room_result(difficulty): result = roll_dice() if result == 1: return 'Empty' elif 2 <= result <= 5: return f'Monster: {monster_result(difficulty)}' elif result == 6: special_result = roll_dice() if special_result == 1: return 'Alien Event (draw Event card)' elif special_result == 2: return 'Equipment (choose an Equipment card)' elif special_result == 3: return 'Order (choose an Order card)' elif special_result == 4: return f'Monsters: {monster_result(difficulty)}, {monster_result(difficulty)}' elif special_result == 5: return f'Monsters: {monster_result(difficulty)}, {monster_result(difficulty)}, {monster_result(difficulty)}' elif special_result == 6: return f'Stranger: {stranger_result()}' def corridor_result(difficulty): result = roll_dice() if result == 1: special_result = roll_dice() if special_result == 1: return 'Alien Event (draw Event card)' elif special_result == 2: return 'Equipment (choose an Equipment card)' elif special_result == 3: return 'Order (choose an Order card)' elif special_result == 4: return f'Monsters: {monster_result(difficulty)}, {monster_result(difficulty)}' elif special_result == 5: return f'Monsters: {monster_result(difficulty)}, {monster_result(difficulty)}, {monster_result(difficulty)}' elif special_result == 6: return f'Stranger: {stranger_result()}' elif 2 <= result <= 4: return 'Empty' else: # result >= 5 return f'Monsters: {monster_result(difficulty)}' def monster_result(difficulty): global dreadnought_encountered points = 0 result = roll_dice(2) monster_str = '' if result == 2 or result == 12: if difficulty == '1' and dreadnought_encountered: monster_count = random.randint(1, 3) monster_str = f'{monster_count} Orks (3 points) + {random.randint(1, 3)} Gretchins (2 points)' points += monster_count * 3 + monster_count * 2 else: dreadnought_encountered = True monster_str = 'Dreadnought (25 points)' points = 25 elif result == 3 or result == 11: marines_count = random.randint(1, 3) monster_str = f'Chaos Space Marines: 1 Commander, 1 heavy weapon and {marines_count} Marines (5 or 10 points)' points = 20 + marines_count * 5 elif result == 4 or result == 10: android_count = random.randint(1, 3) monster_str = f'{android_count} Androids (10 points)' points = android_count * 10 elif result == 5 or result == 9: genestealer_count = random.randint(1, 2) monster_str = f'{genestealer_count} Genestealers (0 points - no blips)' points = 0 elif result == 6: ork_count = random.randint(1, 3) gretchin_count = random.randint(1, 3) monster_str = f'{ork_count} Orks (3 points) + {gretchin_count} Gretchins (2 points)' points = ork_count * 3 + gretchin_count * 2 elif result == 7: gretchin_count = random.randint(1, 3) monster_str = f'{gretchin_count} Gretchins (2 points)' points = gretchin_count * 2 elif result == 8: ork_count = random.randint(2, 4) gretchin_count = random.randint(1, 3) monster_str = f'{ork_count} Orks (3 points) + {gretchin_count} Gretchins (2 points)' points = ork_count * 3 + gretchin_count * 2 else: monster_str = 'Unknown result' return monster_str, points def stranger_result(): result = roll_dice() if result <= 2: return 'Space Marine with heavy weapon' elif result <= 4: return 'Space Marine with Bolter' else: return 'Renegade Ork' total_points = 0 # Initialize the total points special_objective_reached = False secondary_objective_reached = False turn = 0 cumulative_chance_secondary = 0 cumulative_chance_primary = 0 difficulty = input("Easy: Press 1, Normal: Press 2, Hard: Press 3: ") if difficulty not in ['1', '2', '3']: print("Invalid choice, defaulting to Normal.") difficulty = '2' print("Type 'q' and press Enter to quit.") while True: turn += 1 # Display the prompt to get user's choice user_input = input(f"\033[93mTurn {turn} (Points: {total_points}): Press R for Room, C for Corridor...\033[0m").lower() if user_input == 'q': break elif user_input == 'r': room_res, room_points = monster_result(difficulty) print(f"\033[94mRoom result: Monster: {room_res}\033[0m") # Blue total_points += room_points elif user_input == 'c': corridor_res, corridor_points = monster_result(difficulty) print(f"\033[92mCorridor result: Monster: {corridor_res}\033[0m") # Green total_points += corridor_points else: print("Invalid input. Please enter R for Room or C for Corridor.") print("Thanks for playing!")

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue