Logic and tests updated

Fixed some bugs, changed the end game test and corresponding logic
codes.