aimacode / aima-java

Java implementation of algorithms from Russell And Norvig's "Artificial Intelligence - A Modern Approach"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation and Specification difference in getPlayer(int x) method of ConnectFourGame.

ashishrana160796 opened this issue · comments

Documentation differs from implementation as nowhere it is specified that this method returns null if playerNum doesn't match the case value. Which will also lead to the following method being affected also :

@Override
	public String getPlayer(ConnectFourState state) {
		return getPlayer(state.getPlayerToMove());
	}

Referred snippet of code in this issue:

/**
	 * Returns the player corresponding to the specified player number. For
	 * efficiency reasons, <code>ConnectFourState</code>s use numbers
	 * instead of strings to identify players.
	 */
	public String getPlayer(int playerNum) {
		switch (playerNum) {
		case 1:
			return players[0];
		case 2:
			return players[1];
		}
		return null;
	}

Adding a @nullable annotation can solve this issue.

@roychowdhuryrohit-dev considering your point of @Nullable annotation addition makes the method String getPlayer(ConnectFourState state) {...} of same return type. Which is quite wrong as the method it is overriding from is of @nonnull return type method in aima.core.search.adversarial.Game. Here is the following error message :

error: [override.return.invalid] Incompatible return type.
	public @Nullable String getPlayer(ConnectFourState state) {

The issue of ambiguity in specification is substantiated with is illustration. Sure, specification doesn't forbid null value type in return. But it is expected to return some value when called, which is inferred from it's usage in code.

I am going to try to fix this issue. - GSoC

Would adding @nullable annotation before the getPlayer(STATE state) method in the game interface resolve such an ambiguity? @norvig @ctjoreilly @ashishrana160796?