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

Improve the method name_to_position #11

Open
guilhermesilveira opened this issue Mar 29, 2021 · 4 comments
Open

Improve the method name_to_position #11

guilhermesilveira opened this issue Mar 29, 2021 · 4 comments
Labels
good first issue Good for newcomers

Comments

@guilhermesilveira
Copy link
Owner

It could use a simple cached hash map (dictionary) for quick lookup, no comparisons done.

@guilhermesilveira guilhermesilveira added the good first issue Good for newcomers label Mar 29, 2021
@NovusEdge
Copy link

I would like to take this issue up if no one's assigned

@guilhermesilveira
Copy link
Owner Author

Sure, go ahead! Let me know if you need something

@NovusEdge
Copy link

@guilhermesilveira
Could you please tell me where the method is (which file) and how would you like it to be improved?

@guilhermesilveira
Copy link
Owner Author

@NovusEdge sure. Here is the current code:
https://github.com/guilhermesilveira/generativemagic/blob/main/generativemagic/spelling.py#L20

There is a private method responsible for taking the list of values [0,...,10,JACK,QUEEN, KING] and list of suits, and the name of a card [1 of clubs etc]. So it does the math to return the position of the card in a simple deck.

I believe the easiest way is to remove all the private methods here and then on the english (and portuguese) initiation method you can iterate over the numbers 1 to 52, invoke self.card_name(k). The result of that call can be cached in a self._cached_names. So the method name_to_position becomes a simple look up in the self._cached_names dictionary

Let me knoiw if you need something else

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

No branches or pull requests

2 participants