refactored game algorithm