Skip to content

Wishlist #3 - James' Wishlist

  1. Actually - possibly more of a bug this one. I found it necessary when constructing a list of all legal moves to do something like the below. Initially using Action.isLegal() did not work because of the way it checks if a card slot is occupied. I believe this should use Hand.hasCard() rather than its current Hand.getCard() != null
public List<Action> getAllLegalMoves(GameState state, int nextID) {
    // we assume that state has had hand/deck sorted before making a decision

    List<Action> retValue = allRules.stream()
            .map(r -> r.execute(nextID, state))
            .filter(Objects::nonNull)
            .filter(p -> {
                // this section should use Action.isLegal(). But that is broken for Play and Discard
                // as it uses hand.getCard() != null, which will always be true for the acting player
                // when we use the state provided by GameRunner
                if (p instanceof PlayCard) {
                    int slot = ((PlayCard) p).slot;
                    return state.getHand(nextID).hasCard(slot);
                } else if (p instanceof DiscardCard) {
                    int slot = ((DiscardCard) p).slot;
                    return state.getHand(nextID).hasCard(slot) && state.getInfomation() != state.getStartingInfomation();
                } else {
                    return state.getInfomation() != 0;
                }
            })
            .distinct()
            .collect(Collectors.toList());

    return retValue;
}