Monster Fight
Implement a system to simulate combat between monsters with different attributes and abilities. Design the logic to handle turn-based fighting mechanics and determine the winner.
Asked at:
OpenAI
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid April, 2026
OpenAI
Staff
Simulate Turn-Based Monster Team Battle Problem Statement Implement the core battle engine for a turn-based monster team fight between Team A and Team B. Each team has an ordered list of monsters. The battle proceeds in rounds until one side has no living monsters left, and you must produce a detailed, time-ordered battle log. Each monster has: - name (string) - health (HP, integer) - attack (ATK, integer) Active Monster: - For each team, the Active Monster is the first monster in its list with HP > 0. - If a team has no living monsters, it loses immediately. Round flow (fixed): 1) Team A's Active Monster attacks Team B's Active Monster. 2) Team B's Active Monster counterattacks Team A's Active Monster. 3) Next round starts. Damage: - When X attacks Y: Y.HP -= X.ATK Important rule (to match the interview version and allow draws): - The counterattack always happens if Team B had a living Active Monster at the start of the round, even if Team A's attack reduces it to HP <= 0. This is a "dying strike". - A monster that reaches HP <= 0 during the round is removed after the counterattack step finishes. Replacement: - When an Active Monster dies, it is removed and the next living monster (if any) becomes Active for the next round. End conditions: - "Team A wins" if Team B has no living monsters. - "Team B wins" if Team A has no living monsters. - "Draw" if both teams have no living monsters after the same round. Logging requirements (in order): - Each attack: who attacked whom, damage, and defender HP change (before -> after). - Counterattacks that are dying strikes must be marked with "[dying strike]". - Each death event. - Each replacement event ("Team X sends out ...") when applicable. - Final result as the last log line: "Result: Team A wins" / "Result: Team B wins" / "Result: Draw". Implementation requirement: - Your code should be reasonably OOD: define Monster, Team, and BattleEngine (they can be nested inside the solution function). Return a BattleResult-like object (you may use a dict) containing the winner and the full log.
Mid March, 2026
OpenAI
Senior
Late February, 2026
OpenAI
Senior
Hello Interview Premium
Your account is free and you can post anonymously if you choose.