Please explain where in the code this test is being made.
What are the rules for determining who wins?

You should learn how to comment your code. There are no comments in it describing the logic...