I will first say, broadly: I understand that you're constrained by the demands of the assignment, but the assignment doesn't make any sense. It isn't your fault, but like - some of the features are pointless. Allowing the user to check whether a username exists in the list is pointless. There are ways to construct a semi-realistic scenario that exercise the ...
There's some odd features to this code, even for a coding practice exercise. Python of course has a couple of list sorting techniques which you should absolutely use in normal circumstances.
So accepting that you are doing this for practice, I wonder what the point of the duplicatelist is? Or indeed temp? Are these development fossils of some earlier process ...
I'm not going to go too heavily into refactoring the whole thing.
Some basic readability things:
return_values = compare(options, options, score)
score = return_values
lost = return_values
It would be much clearer if you did:
lost, score = compare(options, options, score)
You have indented things with two spaces, which is odd, normally ...
The goal is to optimize the program. I won't change the backtracking algorithm.
Your code is good, but you should use structs and impls in this program, instead of passing grid: [[i8; 9]; 9] around. I show this in code below.
You check cell vacancy with many loops that check multiple cells. How about we kill many birds with one ...
This is a fun project.
Here are a few things I noticed:
$AlivePercChance implies that it's a percentage (30%) rather than a fraction (0.3). You might consider renaming it to $AliveChance
Why did you flatten the 2D array to 1D? It adds substantial overhead (2 extra function calls * $Width * $Height per screen write, way more for checking neighbors) and ...
You mostly follow PEP8 styling conventions, making your code quite readable. The only exception I see is an extra blank line at the beginning of the score and play methods.
Also, it is good thinking to wrap your game state into a class for future integration into a more complex project. It is also a good use of a main guard at the end.
Hello and welcome to the Rust community.
Are you sure the code is correct? The regex looks odd, but ok. It seems that Tag::Close does not carry any meaningful info, even though it contains a String.
Be sure to read up on if let statements. They are useful for concise and idiomatic code. Here, catch some reading material: