added a check for whether the player won or lost the match. Reorganized the code