online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
''' Press the Green "Run" button above. You enter 2 numbers, the distances to the closest group of Marines, distance to second closest group. Then, for each Marine in danger of attach you enter distance to Genestealer and Overwatch status. Press enter for distance to Genestealer on the next turn. To quit press "q" You can "Fork" your own version and change the monster_result table to get different monsters ''' import random # Logic by Johannes Epple # Genestealer movement logic based on a and β def move_genestealer(a, beta): red_start = "\033[91m" red_end = "\033[0m" if beta >= 2 * a: return f"{red_start}Genestealers go for group a.{red_end}" else: roll = random.randint(1, 6) if roll in [1, 2, 3, 4]: return f"{red_start}Genestealers go for group a.{red_end}" else: return f"{red_start}Genestealers go for group b.{red_end}" # Genestealer attack logic based on d and overwatch status def attack_genestealer(d, is_overwatch): roll = random.randint(1, 6) prefix = "If the Space Marine can't avoid close combat Genestealer attacks always, otherwise: " blue_start = "\033[94m" blue_end = "\033[0m" if is_overwatch: if d > 5 and roll == 6: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" elif d in [4, 5] and roll in [5, 6]: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" elif d <= 3: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" else: if d > 10 and roll == 6: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" elif d in [9, 10] and roll in [5, 6]: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" elif d < 9: return f"{blue_start}{prefix}Roll: {roll} - Genestealer attacks!{blue_end}" return f"{blue_start}{prefix}Roll: {roll} - Genestealer does not attack.{blue_end}" # Main game loop def main(): while True: user_input = input("Enter Distance to closest Marine Group, Distance to next closest Marine Group separated by spaces (or 'q' to quit): ") if user_input.lower() == 'q': break try: a, beta = map(int, user_input.split()) except ValueError: print("Invalid input. Please enter two integers separated by spaces.") continue move_result = move_genestealer(a, beta) print(move_result) while True: d_input = input("Distance to target Space Marine (Press Enter to end turn): ") if d_input == '': break try: d = int(d_input) except ValueError: print("Invalid input. Please enter an integer for distance.") continue is_overwatch = input("Is the Space Marine in Overwatch? (y/n): ").lower() == 'y' attack_result = attack_genestealer(d, is_overwatch) # Example Genestealer number "1" print(attack_result) if __name__ == "__main__": main()

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