thomas-koller / jass-kit-py

GNU General Public License v3.0
11 stars 5 forks source link

get_valid_cards thinks that trump 10 > trump J #10

Open Joelius300 opened 1 year ago

Joelius300 commented 1 year ago

I believe to have found a bug in RuleSchieber.get_valid_cards.

Example:

Trump declared as ♦ \ The following trick is already in play (in that order): ♣6, ♦J , ♦10 \ The last player has the hand : ♦A, ♦9, ♦6 , ♠10

From my limited knowledge about Jass, I think the player should only be able to play ♠10 but the function returns ♦A, ♦9, ♠10.

Reproduction:

from jass.game.rule_schieber import RuleSchieber
from jass.game.game_util import *
from jass.game.const import *

if __name__ == "__main__":
    schieber, trump, move_nr = RuleSchieber(), D, 3
    trick = np.array([C6, DJ, D10])
    # highest trump in this trick is DJ
    # lowest trump in this trick is D10
    # trumps lower than D10 = D8, D7, D6
    # trumps higher than DJ = None
    # indices are in order of DA, DK, DQ, DJ, D10, D9, D8, D7, D6
    print([DA, DK, DQ, DJ, D10, D9, D8, D7, D6])
    # therefore D10 > DJ meaning that in get_valid_cards the check lowest_trump_played < current_trick[2]
    # will think that D10 is higher than DJ and update lowest_trump_played leading to the invalid response
    # that only trumps below D10 are invalid even though all trumps should be invalid because DJ is the max.
    hand = get_cards_encoded([DA, D9, D6, S10])
    # player has something else than trump in hand and is therefore not allowed to play any lower trumps
    valid_cards = schieber.get_valid_cards(hand, trick, move_nr, trump)
    print(valid_cards)
    print(convert_one_hot_encoded_cards_to_str_encoded_list(valid_cards))
    assert valid_cards[DA] == 0  # lower than DJ, cannot play
    assert valid_cards[D9] == 0  # lower than DJ, cannot play
    assert valid_cards[D7] == 0  # lower than DJ, cannot play
    assert valid_cards[S10] == 1 # not trump, can play

Output:

[0, 1, 2, 3, 4, 5, 6, 7, 8]
[1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
['DA', 'D9', 'S10']
Traceback (most recent call last):
  File ".../jass_bot/main.py", line 48, in <module>
    assert valid_cards[DA] == 0  # lower than DJ
           ^^^^^^^^^^^^^^^^^^^^
AssertionError

Could you confirm if this is a bug?

timoloc commented 4 days ago

It seems like there is confusion regarding the rules of Jass, particularly the Schieber variant, and how the get_valid_cards function works.

In Schieber, if a player doesn't have a card of the suit that was led (in this case, ♣ since the first card played was ♣6), they are free to play any card. This rule applies regardless of whether they hold trump cards or other cards.

So in your example:

The trick is: ♣6, ♦J, ♦10
The player's hand is: ♦A, ♦9, ♦6, ♠10
The player has no ♣ (the suit that was led), so the player is allowed to play any card.
thomas-koller commented 4 days ago

No, that is not correct. According to the rules of Schieber, it is not allowed to play a lower trump card, if a higher one has been played, except if you have only trump cards.