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 implementation of get_perspective #17

Open
miselico opened this issue Jan 23, 2021 · 0 comments
Open

Improve the implementation of get_perspective #17

miselico opened this issue Jan 23, 2021 · 0 comments

Comments

@miselico
Copy link

In Deck, the method get_perspective fullfills two functions

  1. providing the overall perspective
  2. providing the perspectives of the players

What is returned is decided based on both the signature of the Deck and the specified player. I would change this to two methods, one for each of the functionalities above.
The signature would then only be used as an access control mechanism.

Even without this, the current functionality could be written less concise, but more clear as

	if self.__signature == 1:
		assert player == 1 or player == None, "You are not allowed to access the game of player 1 trough this state"
		return list(self.__p1_perspective)
	elif self.__signature == 2:
		assert player == 2 or player == None,  "You are not allowed to access the game of player 2 trough this state"
		return list(self.__p2_perspective)
	elif self.__signature == None:
		if player is None:
			return self.__card_state
		else:
			if player == 1: return list(self.__p1_perspective)
			else: return list(self.__p2_perspective)
	else:
		raise Exception("Deck.__signature invalid!")
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

1 participant