Open JohnTMurphy-NIU opened 2 years ago
This is more correct, but there's a different problem that may occur (and I should have mentioned it- sorry!): The issue is that if the highest degree is 'N' , there may be more than one player with degree 'N'. In that case you need to worry about a few things. First, it should be theoretically possible for any of the players with the highest degree to be chosen as the favorite player, and this should be truly random. Right now, it is assigned to the first one found, which means it is based on the order in which the nodes are returned by the getNodes method, which may be arbitrary (that is, not reliably consistent from call to call, but also not truly random). The better approach is to make a list of all the nodes with the highest value and then choose randomly from that list. However, you may also want to keep the same 'favorite' player from turn to turn, unless they lose a network connection or someone gains one. That is, it should stay 'favorite' so long as it is a member of the set of nodes with the highest degree. Exactly how you handle this is up to you. Suppose that the highest degree is 6, and you have 3 players with degree 6. If the network never changes, do you want to choose one player as the favorite and never change? Or choose one of these three every turn? If the network changes, and some other player ends up with degree 7, do you want to switch? All of this is a little bit more obscure; I think the current implementation will always choose from among the players with the highest degree, and will choose the first one, which is likely to be consistent every time the routine is run, so it will appear as if the same agent is being chosen, but from time to time this may not happen in exactly the same way.
It seems like the intent of the 'Player.findFavorite' method is to find the agent with the highest degree. As written, however, the method will find an arbitrary agent with degree higher than 'self'. (Strictly, it will find the last agent in the arbitrarily ordered list of nodes whose degree is higher than the 'self' agent. Also, if 'self' is the agent with the highest degree, 'favorite' will be left null.) Line 641 should set 'fav = obj;' instead of 'favorite = (Player) obj;'. The closing statement, after the loop through the agents, should be 'favorite = (Player)fav;'.
(You might also consider recording the in-degree of fav in a temporary integer variable; calling net.inDegree(fav) for every iteration may be an expensive network operation, though it's probably not too bad if the number of nodes is small.)