Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelativeValue calculated improperly when vira is 3 #34

Open
Keilo104 opened this issue May 8, 2024 · 0 comments
Open

RelativeValue calculated improperly when vira is 3 #34

Keilo104 opened this issue May 8, 2024 · 0 comments

Comments

@Keilo104
Copy link
Contributor

Keilo104 commented May 8, 2024

when vira is 3 and manilha is 4, relative values are not shifted properly, making so cards 5~3 are valued at 2~10 instead of 1~9, and a 3 has the same value as a diamonds 4 (manilha)

related code @com/bueno/spi/model/TrucoCard.java:

    public int relativeValue(TrucoCard vira) {
        Objects.requireNonNull(vira, "Vira card must not be null.");
        if (isManilha(vira))
            return switch (suit) {
                case DIAMONDS -> 10;
                case SPADES -> 11;
                case HEARTS -> 12;
                case CLUBS -> 13;
                case HIDDEN -> throw new IllegalStateException("Closed card can not be manilha!");
            };
        if(rank.value() > vira.rank.value()) return rank.value() - 1;
        return rank.value();
    }

test that i made that fails:

    @Test
    @DisplayName("Should 3 have a relative value of 9 when 3 is vira and 4 is manilha")
    void shouldThreeHaveRelativeValueOfNineWhenThreeIsVira(){
        TrucoCard vira = TrucoCard.of(THREE, SPADES);
        TrucoCard three = TrucoCard.of(THREE, DIAMONDS);

        assertEquals(9, three.relativeValue(vira));
    }
org.opentest4j.AssertionFailedError: 
Expected :9
Actual   :10

potential fix:

    public int relativeValue(TrucoCard vira) {
        Objects.requireNonNull(vira, "Vira card must not be null.");
        if (isManilha(vira))
            return switch (suit) {
                case DIAMONDS -> 10;
                case SPADES -> 11;
                case HEARTS -> 12;
                case CLUBS -> 13;
                case HIDDEN -> throw new IllegalStateException("Closed card can not be manilha!");
            };
        if(rank.value() > vira.rank.value()) return rank.value() - 1;
        if(vira.rank.value() == 10) return rank.value() - 1;
        return rank.value();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant