Finish game algorithm