← Pixel Dreamer Studio

Count slot line wins with wilds in front

Decide what a line pays by its first symbol that is not wild, then count from the left while each symbol is that one or a wild.

Skip the wilds at the start of the line to find the symbol it pays for, then count from the left while each symbol is that symbol or a wild. Checking against the first symbol on the line fails as soon as that symbol is a wild, because only another wild is equal to a wild. In our Godot 4.7 test W A A B C and W W A A A paid nothing that way, and over 100,000 random lines of 6 symbols plus a wild it found 7,296 wins where there were 12,638: 5,342 missed and 338 paid as fewer wilds instead of a longer run. The script found all of them.

The code

Save it as line_win.gd. line_win() takes the symbols on one line from left to right and returns the symbol and how many in a row, or an empty Dictionary for no win. Symbols here are Strings with W as the wild. With resources, compare ids, or a wild flag on the symbol, the same way.

extends RefCounted
## Count a slot line win from the left, with a wild symbol that stands in for anything.
## Symbols here are Strings and "W" is the wild. Use your own ids or resources the same way.

const WILD := "W"


static func line_win(line: Array, min_match: int = 3) -> Dictionary:
	var base := WILD  # a line of only wilds pays as wilds
	for s in line:
		if s != WILD:
			base = s  # the first real symbol decides what the line pays, even after wilds
			break
	var count := 0
	for s in line:
		if s != base and s != WILD:
			break
		count += 1
	if count < min_match:
		return {}
	return {"symbol": base, "count": count}

What we measured

Lines of 5 symbols, a win from 3 in a row, compared with a check that takes the first symbol on the line as the one to match. Two runs gave the same numbers.

Why it happens

A wild has no symbol of its own. When it is the first on the line, a check that matches everything to the first symbol is matching against the wild, and the only thing equal to a wild is another wild. So a line that starts with a wild only pays while the wilds last, and the real symbol behind them never counts. Looking past the wilds first gives the line the symbol it actually pays for.

What to change

A whole machine built on this: Slot Roguelike Kit for Godot 4 finds wins on rows, V shapes and diagonals, columns and clusters, with a wild flag on any symbol and min_match to set. Its evaluate(grid) checks a grid without spinning, and every win reports its cells, symbol, count and score.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Slot Roguelike Kit for Godot 4 finds wins on rows, V shapes, diagonals, columns and clusters, with wild symbols that count even at the start of a line.

More how-tos: Game systems