mardi 5 décembre 2017

Designing a generic library for calculating player turns in games

I was asked this question in an interview.
Basically, I have to create a generic library which games can to use to calculate player turns.
I came up with this soln.

The library will define a Player class that needs to used by our game. Create an abstract class named say BaseStrategy which has a findNextTurn(List<Player>, currentPlayer) method that can be implemented by child class strategies like RoundRobinStrategy, PriorityBasedStrategy etc.

Our GameController will get an instance of the appropriate strategy by calling a TurnStrategyFactory and will call strategy.findNextTurn(List<Player>, currentPlayer) every time to get player whose turn is next.

The interviewer wasn't happy with passing the List & the current Player state everytime.

How can I solve this better?

Aucun commentaire:

Enregistrer un commentaire