Type Triangle Duel
Pick a starter, then face the type that beats it. Win from a losing matchup or do not win at all.
Pick a starter. The card tells you who you will be fighting before you commit.
You always start in the losing matchup. Grass beats water, water beats fire, fire beats grass. Whichever starter you pick, the opponent is the type that beats it. Your same-type attack is halved, theirs is doubled, and the fight is still winnable: the off-type move is never resisted, the status move drags their attack down, and the guard turn is how you pay for both.
How it works
The game is the starter-triangle format made famous by monster-battling RPGs, with one rule changed: the opponent is never random. It is always the type that beats the one you picked. That turns the whole thing into a puzzle about finding a route out of a losing matchup, and it puts a fair amount of weight on four small pieces of code.
The type chart is data, not branching
Effectiveness lives in a nested object keyed by attacking type and then defending type. There is exactly one function that reads it, and no part of the game asks if (type === 'fire').
const BTL_CHART = {
grass: {grass:0.5, fire:0.5, water:2, neutral:1},
fire: {grass:2, fire:0.5, water:0.5, neutral:1},
water: {grass:0.5, fire:2, water:0.5, neutral:1},
neutral: {grass:1, fire:1, water:1, neutral:1}
}
function btlEff(moveType, defType){
const r = BTL_CHART[moveType]
return (r && r[defType] != null) ? r[defType] : 1
}The payoff is what happens when a fourth type arrives. With a table you add one row, one column, and nothing else changes: damage, the AI's move scoring, the move tooltips and the chips all keep working because they all go through btlEff. With a chain of conditionals a fourth type means finding every branch that enumerates types and remembering to extend each one, and the branches you miss fail silently as a 1x multiplier rather than as an error. A table also lets you look at the balance as a grid and see, at a glance, that the triangle is symmetric. You cannot eyeball that in an if-chain.
The neutral row is what makes the game winnable. Every creature carries one off-type move that reads 1x against all three types, so a player stuck at 0.5x with their own type still has a weapon that does not get halved.
The turn is an explicit state machine
A turn has more steps than it looks like: your move resolves, the game checks whether that ended the fight, the opponent's move resolves, it checks again, then upkeep ticks the damage-over-time and the stamina regeneration, and only then is input accepted again. Those are named states in a table, and one function moves between them.
const BTL_FLOW = {
select: {pick:'choose'},
choose: {move:'resolveYou'},
resolveYou: {done:'checkYou'},
checkYou: {alive:'resolveFoe', over:'end'},
resolveFoe: {done:'checkFoe'},
checkFoe: {alive:'upkeep', over:'end'},
upkeep: {alive:'choose', over:'end'},
end: {again:'select'}
}
function btlSend(ev, payload){
const next = (BTL_FLOW[BTL.phase] || {})[ev]
if(!next) return false /* wrong phase: the event is dropped, not queued */
BTL.phase = next
BTL_ENTER[next](payload)
return true
}Every move button sends the same event, move, and only the choose state has a transition for it. So the guard against double-resolving a turn is not a boolean flag someone has to remember to set and clear, and it is not the disabled attribute on the buttons either. The buttons are disabled as well, but that is presentation. If a click arrives during the animation pause between the two resolve steps, or from a keyboard repeat, or from a second tap on a touchscreen that fired before the re-render, the lookup returns undefined and the event is dropped.
The bugs this design removes are the ones that turn up late. An implicit state machine, where the turn is a sequence of nested callbacks and timeouts, gives you two players acting twice in one turn because a second click landed inside a setTimeout; it gives you a knockout that is checked only after both sides have moved, so a creature at zero HP still gets its attack in; and it gives you input accepted during an animation, which reads as a dropped click to the player and as an off-by-one turn count to the scoreboard. Each of those is a different fix in the callback version. Here they are the same fix, and it is already made.
The one thing the state machine does own is the timers. Transitions that pace the animation go through a helper that records the timeout id, so stop() can cancel every pending one when the page is left mid-turn.
Damage is a pure function
Damage takes the attacker, the defender, the move, the effectiveness multiplier and the random roll, and returns a number. It reads no global state and writes nothing.
function btlDamage(attacker, defender, move, mult, roll){
if(move.kind !== 'attack') return 0
const atk = attacker.atk * btlStageMult(attacker.atkStage)
const def = defender.def * btlStageMult(defender.defStage)
const guard = defender.guarding ? BTL_K.guardCut : 1
return Math.max(1, Math.round(move.power * (atk / def) * mult * roll * guard))
}Pulling the roll out as a parameter rather than calling Math.random() inside is the part that matters. It means the function can be called with roll = 1 to get the expected damage of a move, which is exactly what the opponent AI needs in order to compare its options, and it means the balance can be tested by running whole matches with a scripted policy and no UI. Tuning the game was a loop of running two hundred matches per starter against a competent policy and against a policy that spams the strongest same-type attack, and checking that the first wins comfortably and the second does not. That is only cheap because the rules do not touch the DOM.
The random band is deliberately narrow, plus or minus six percent. Wide enough that identical turns are not identical, narrow enough that a correct line of play does not lose to variance.
The opponent is a scoring policy
The AI does not pick at random and it does not run a search. It scores its four moves in damage-equivalent points and takes the highest.
function btlAiScore(move, self, foe){
if(move.cost > self.sp) return -Infinity
const left = self.sp - move.cost
if(move.kind === 'attack'){
/* score against an unguarded foe: a guard lapses the moment its owner acts again */
const open = Object.assign({}, foe, {guarding:false})
const est = btlDamage(self, open, move, btlEff(move.mtype, open.type), 1)
return est - (left < BTL_K.aiReserve ? BTL_K.aiStrain : 0)
}
if(move.kind === 'status'){
return (foe.atkStage > -BTL_K.stageCap ? BTL_K.aiWantAtk : 0)
+ (self.defStage < BTL_K.stageCap ? BTL_K.aiWantDef : 0)
+ (foe.wound > 0 ? 0 : BTL_K.aiWantWound)
}
/* guard: recover when starved, bank when the heavy move is one turn out of reach */
const heavy = self.moves.filter(m => m.kind === 'attack')
.reduce((a, b) => a.power >= b.power ? a : b)
if(self.sp <= BTL_K.aiReserve) return BTL_K.aiBrace
return self.sp < heavy.cost ? BTL_K.aiBank : 3
}Because it is deterministic given the board, the opponent's next move can be computed at the end of upkeep and shown to the player before they choose, and it will be honest: nothing the player does between the telegraph and the resolution changes the opponent's stamina, so it always commits to what it announced. The player is reading a rule, not a coin flip.
The behaviour that falls out is a pattern you can learn in three or four attempts. The opponent opens with its doubled same-type attack, which costs most of its stamina bar. It fills the next turns with the cheap off-type move while the bar refills, spends a turn on its status move once neither attack is worth much, and braces when it is nearly empty. Then it saves up and leads with the big attack again. Once you have seen the loop, you know which turn to spend on your guard and which turns are free for the off-type move. Beating it is solving it.
A scoring policy is also the version you can tune. Every number in that function is a lever with a meaning: aiStrain is how much the opponent dislikes stranding itself without stamina, aiBrace is how urgently it recovers when starved, aiBank is how willing it is to spend a turn saving up for the heavy move. Moving one changes behaviour in a direction you can predict and re-measure with the same two hundred match harness. A tree of conditionals encodes the same decisions in a form where you can only change them by rewriting the tree.
What is deliberately simple
There is one status move rather than a menu of them, and it does three things at once: it lowers their attack, raises your defence and sets a wound. Stat stages are linear and capped at plus or minus two rather than the compounding fractions the genre normally uses, because linear stages are easier to read off the chips on the card and easier to reason about when tuning. There is no switching, no items and no accuracy roll. All three would add depth, and none of them would make the central question, which is how to win from behind, any sharper.
Leaderboard
More games
Typing Test
Thirty seconds of real Rust, indentation handled for you. WPM and accuracy, the usual.
PlayCold Case Files
Ten cases: a locked study, a train that arrived one passenger short, a ransom nobody collected. Read the evidence, commit to an answer.
PlayWill It Hold?
A steel beam, a span, a load. Does it pass? Real IWF sections and yield strengths, checked the way a design reviewer checks them.
Play