queler / holokenmod

Fork of holoken
GNU General Public License v3.0
17 stars 3 forks source link

Always '2' and '9' as only solution in a '7-' group #33

Open Hajuskin opened 1 year ago

Hajuskin commented 1 year ago

Playing 1000+ 9x9 games of the original Holoken, there has been always only one solution to a 7- group. It is always 2 and 9 when there should also cases with 1 and 8. I just discovered this mod and quickly tested it, but this bug seems to be still there.

Kiwaiti commented 4 months ago

This is true, and is a result (though not unavoidable) of how grids are generated: First a grid is filled with numbers and then overlayed with random cages (that's what your groups are called in the program), and last the numbers present in each cage (e.g. 1 and 8) are assigned an operator (-), with which the result or hint number (7) is calculated. Thus we start with a cage of two numbers already assigned and determine which operator to use. After randomly deciding to use addition or multiplication each with a likelyhood of 0.25, the other half of 2-number cages are inspected to see whether division will work, since it is the only operator that can't be applied to all number pairs. If division is possible, it is used, otherwise subtraction is used. So, if a pair of 1 and 8 is randomly selected not to use either addition (9+) or multiplication (8x), it will be determined that 8 is divisible by 1 and therefore division (8/) will always be used, never subtraction (7-). This utterly prevents the following subtractions from ever being used: 2-1, 3-1, 4-2, 4-1, 6-3, 5-1, 6-2, 8-4, 6-1, 7-1, 8-2, 9-3, 8-1, 9-1 (these 14 out of 36 pairs of numbers from 1 to 9 are the ones viable for division) In order to change this behaviour, we could change line 248 in GridCage.java from

    if (canDivide) {

to

    if (canDivide && rand <= 0.9) { // leave a chance to use subtraction even if divisible

since we already knew rand to be > 0.5, this should result in subtraction being used about 20% of the time even though division has been determined to be possible (and random selection against addition and multiplication has occurred). That still means 8-1 would occur much less often than 9-2, but at least you couldn't be sure which it is in any specific case. It would also make division be used even less often in favour of subtraction (currently 70 division to 110 subtraction, then 56 division to 124 subtraction, with addition and multiplication still at an even 90 each for cages containing two values), that could be improved by selecting for division before addition and multiplication (at a cost of more complicated and slightly slower code) and adjusting proportions to counteract the limited applicability of division (expect that to be even more complicated if you're trying to make it come out evenly for smaller grids as well).

Hajuskin commented 4 months ago

Thank you very much for this detailed explanation. I think that the game could profit by having more possible pairs, so maybe it is worth a try :)