return true if hand1 beats hand2 (has a higher score)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hand), | intent(inout) | :: | hand1 | |||
| class(hand), | intent(inout) | :: | hand2 | |||
| logical, | intent(in) | :: | with_jokers |
if considering jokers |
logical function beats(hand1, hand2, with_jokers) !! return true if hand1 beats hand2 (has a higher score) class(hand),intent(inout) :: hand1, hand2 logical,intent(in) :: with_jokers !! if considering jokers integer :: i associate(h1 => hand1%cards, h2 => hand2%cards) ! recompute type if it hasn't already been computed if (hand1%type==0) hand1%type = hand_type(hand1, with_jokers) if (hand2%type==0) hand2%type = hand_type(hand2, with_jokers) if (hand1%type==hand2%type) then ! lower index is stronger do i = 1, 5 if (h1(i)/=h2(i)) then beats = index_in_cards(h1(i),with_jokers) < & index_in_cards(h2(i),with_jokers) ! lower is stronger return end if end do else ! one hand beat the other beats = hand1%type < hand2%type ! lower score is better (1-7) end if end associate end function beats