Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of rules is wrong with multiple same letters #1

Closed
tardypad opened this issue Jan 28, 2022 · 4 comments
Closed

Implementation of rules is wrong with multiple same letters #1

tardypad opened this issue Jan 28, 2022 · 4 comments

Comments

@tardypad
Copy link

Here are a couple examples that show some issues with the coloration of the letters.

game2

(screenshot used in Harbour)
In the 3rd line, only one E should be colored to match the number of E in the end word

game1

(from one of my game)
In the 3rd line, the last L shouldn't be colored at all as it's already colored at the right 1st place (and there's no other L in the end word)

For reference, here's a screenshot from the official game that show the validity of my remarks
official

@tardypad tardypad changed the title Implementation of rules is wrong in some cases Implementation of rules is wrong with multiple same letters Jan 28, 2022
@monich
Copy link
Owner

monich commented Jan 28, 2022

Indeed, you're right! I'll fix the rules. The JavaScript code of the original game is obfuscated or something, and is hard to read, but the row state evaluation function goes roughly like this (I reformatted it a bit to be more readable):

var e = this.boardState[this.rowIndex],  // row to evaluate
    a = this.solution,                   // the answer
    s = Array(a.length).fill("absent"),  // the state
    t = Array(a.length).fill(true),
    o = Array(a.length).fill(true)

for (var n = 0; n < e.length; n++) {
    if (e[n] === a[n]) {
        s[n] = "correct"
        t[n] = false
        o[n] = false
    }
}

for (var i = 0; i < e.length; i++) {
    var L = e[i]
    if (t[i]) {
	for (var j = 0; j < a.length; j++) {
	    var A = a[j]
	    if (o[j] && L === A) {
		s[i] = "present"
                o[j] = false
		break
	    }
	}
    }
}

@monich
Copy link
Owner

monich commented Jan 29, 2022

Should be fixed by c6a1411

My example now looks like this:

whole

your example:

ledge

and the "official" one:

banal

@monich
Copy link
Owner

monich commented Jan 29, 2022

Should be fixed in 1.0.1, please give it a try (rpms are available from either github or openrepos). Thanks for reporting it!

@tardypad
Copy link
Author

Thanks for fixing it so fast :)
It looks fine now from the few examples I had today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants