phikal / ReGeX

A Regular Expression game for Android
https://f-droid.org/en/packages/com.phikal.regex/
GNU General Public License v3.0
101 stars 10 forks source link

Scoring? #51

Open ameenross opened 2 years ago

ameenross commented 2 years ago

Is it just length? I notice sometimes that I get a score of 200+ for regex's that aren't particularly short, although I liked the solution better than a [xyz].+ type solution. Is there any weight given to the use of certain solutions / meta characters in scoring?

phikal commented 2 years ago

(Sorry for taking so long to respond, my repository notifications were apparently disabled)

This is the section of the code that calculates the score: https://github.com/phikal/ReGeX/blob/b2d3563f6528692d1cd8ab30c9293a0a7c7b6b99/app/src/main/java/com/phikal/regex/Utils/Calc.java#L38

There is nothing to understand, I just experimented with a few constants and functions to get something approximating a sensible score. What actually has to be done, is to parse the regular expression into a tree, then compare the size of the regular expression to the smallest expression (that should also be calculated beforehand), and using the difference to determine how many points you get for each problem.

ameenross commented 2 years ago

the smallest expression (that should also be calculated beforehand)

That seems like a tough job in and of itself.

ameenross commented 2 years ago

So what I understand from the code is this:

(charactersSaved / 2 + 1) * (gameDependentConstant + 3 * regexValue)

Where regexvalue is calculated by counting meta characters, and a \ counts for 2. So using meta characters positively influences the score, is that correct?

phikal commented 2 years ago

That seems like a tough job in and of itself.

The algorithms might be non-trivial, but is would essentially build a random regular expression depending on the difficulty, check if can be minimised, then use this to generate a number of words that are in and outside of the described language (again, the number and length depends on the level).