private CardAmount getColorOfMaxPieces(ArrayList<TrainCard> hand) { CardAmount rainbow = new CardAmount(TrainCardColor.rainbow, 0); CardAmount black = new CardAmount(TrainCardColor.black, 0); CardAmount blue = new CardAmount(TrainCardColor.blue, 0); CardAmount green = new CardAmount(TrainCardColor.green, 0); CardAmount orange = new CardAmount(TrainCardColor.orange, 0); CardAmount purple = new CardAmount(TrainCardColor.purple, 0); CardAmount red = new CardAmount(TrainCardColor.red, 0); CardAmount white = new CardAmount(TrainCardColor.white, 0); CardAmount yellow = new CardAmount(TrainCardColor.yellow, 0); CardAmount best = new CardAmount(TrainCardColor.orange, 0); for (TrainCard card : hand) { if (card.getColor() == TrainCardColor.rainbow) { rainbow.incAmount(); if (rainbow.getAmount() > best.getAmount()) best = rainbow; } if (card.getColor() == TrainCardColor.black) { black.incAmount(); if (black.getAmount() > best.getAmount()) best = black; } if (card.getColor() == TrainCardColor.blue) { blue.incAmount(); if (blue.getAmount() > best.getAmount()) best = blue; } if (card.getColor() == TrainCardColor.green) { green.incAmount(); if (green.getAmount() > best.getAmount()) best = green; } if (card.getColor() == TrainCardColor.orange) { orange.incAmount(); if (orange.getAmount() > best.getAmount()) best = orange; } if (card.getColor() == TrainCardColor.purple) { purple.incAmount(); if (purple.getAmount() > best.getAmount()) best = purple; } if (card.getColor() == TrainCardColor.red) { red.incAmount(); if (red.getAmount() > best.getAmount()) best = red; } if (card.getColor() == TrainCardColor.white) { white.incAmount(); if (white.getAmount() > best.getAmount()) best = white; } if (card.getColor() == TrainCardColor.yellow) { yellow.incAmount(); if (yellow.getAmount() > best.getAmount()) best = yellow; } } return best; }
private boolean canPurchase(Route route, ArrayList<TrainCard> hand, int numPieces) { Routes routes = Routes.getInstance(); TrainCardColor routeColor = route.getColor(); int routeCost = route.getCost(); if (routes.isRouteClaimed(route)) { System.out.println( "This route from " + route.getDest1() + " to " + route.getDest2() + " is owned. You have failed good sir."); return false; } if (routeCost > numPieces) { System.out.println("Not enough pieces"); return false; } // tally up relevant pieces int piecesOfColorAvailible = 0; int piecesOfRainbowAvailible = 0; for (TrainCard card : hand) { if (card.getColor() == routeColor) { piecesOfColorAvailible++; } if (card.getColor() == TrainCardColor.rainbow) { piecesOfRainbowAvailible++; } } // grey routes if (routeColor == TrainCardColor.rainbow) { CardAmount mostCard = getColorOfMaxPieces(hand); if ((mostCard.getAmount() + piecesOfRainbowAvailible) >= routeCost) { return true; } } // normal routes if ((piecesOfColorAvailible + piecesOfRainbowAvailible) >= routeCost) { return true; } return false; }