/** * Get necessary exchange to make a four of a kind dedication to given player. * * @param player {@link Player} * @return A pair of {@link LanternCardWrapper} with the [card to give, card to receive], or null * if there is no dedication one card away. */ public LanternCardWrapper[] getNextFourOfAKind(Player player) { LanternCardWrapper[] giveReceive = null; LanternCardWrapper give = null; LanternCardWrapper receive = null; // check if there is any card to receive for (LanternCardWrapper lantern : player.getCards()) { if (lantern.getQuantity() == 3) { receive = lantern; break; } } // if can receive, check if there is any different card to give if (receive != null) { for (LanternCardWrapper lantern : player.getCards()) { if ((!lantern.equals(receive)) && (lantern.getQuantity() > 0)) { give = lantern; break; } } // if can give and receive, return it if (give != null) { giveReceive = new LanternCardWrapper[] {give, receive}; } } return giveReceive; }
/** * Get necessary exchange to make a three pairs dedication to given player. * * @param player {@link Player} * @return A pair of {@link LanternCardWrapper} with the [card to give, card to receive], or null * if there is no dedication one card away. */ public LanternCardWrapper[] getNextThreePairs(Player player) { LanternCardWrapper[] giveReceive = null; LanternCardWrapper pair1 = null; LanternCardWrapper pair2 = null; LanternCardWrapper give = null; LanternCardWrapper receive = null; // search for first 2 pairs for (LanternCardWrapper lantern : player.getCards()) { if (lantern.getQuantity() >= 2) { // if there is more than 2, this is also the card to give if (lantern.getQuantity() >= 3) { give = lantern; } if (pair1 == null) { pair1 = lantern; } else if (pair2 == null) { pair2 = lantern; break; } } } // if there is at least 2 pairs, check if there are other cards to give and receive if ((pair1 != null) && (pair2 != null)) { for (LanternCardWrapper lantern : player.getCards()) { if ((!lantern.equals(pair1)) && (!lantern.equals(pair2))) { if (lantern.getQuantity() > 0) { if (give == null) { give = lantern; } else if (receive == null) { receive = lantern; break; } } } } } // if can give and receive, return it if ((give != null) && (receive != null)) { giveReceive = new LanternCardWrapper[] {give, receive}; } return giveReceive; }