package net.zomis.monopoly.model.actions;

import net.zomis.monopoly.model.GameAction;
import net.zomis.monopoly.model.GameActionResult;
import net.zomis.monopoly.model.Player;
import net.zomis.monopoly.model.Property;

public class BuildAction implements GameAction {

    public BuildAction(int houseCount, Property... properties) {

    }

    @Override
    public boolean isAllowed(Player player) {
        return false;
    }

    @Override
    public GameActionResult perform(Player player) {
        return null;
    }

}

@@ -72,451 +72,2295 @@
 del.
-GameAction;%0Aimport net.zomis.monopoly.model.GameActionResult;%0Aimport net.zomis.monopoly.model.Player;%0Aimport net.zomis.monopoly.model.Property;%0A%0Apublic class BuildAction implements GameAction %7B%0A%0A    public BuildAction(int houseCount, Property... properties) %7B%0A%0A    %7D%0A%0A    @Override%0A    public boolean isAllowed(Player player) %7B%0A        return false;%0A    %7D%0A%0A    @Override%0A    public GameActionResult perform(Player player) %7B%0A        return null
+*;%0A%0Aimport java.util.Arrays;%0Aimport java.util.IntSummaryStatistics;%0Aimport java.util.stream.Collectors;%0A%0Apublic class BuildAction implements GameAction %7B%0A%0A    private final int amount;%0A    private final Property%5B%5D properties;%0A%0A    public BuildAction(int houseCount, Property... properties) %7B%0A        this.amount = houseCount;%0A        this.properties = Arrays.copyOf(properties, properties.length);%0A    %7D%0A%0A    @Override%0A    public boolean isAllowed(Player player) %7B%0A        if (Arrays.stream(properties).map(Property::getGroup).distinct().count() != 1) %7B%0A            // Can only buy on one group at a time%0A            return false;%0A        %7D%0A        if (properties%5B0%5D.getGroup().getHouseCost() %3C= 0) %7B%0A            // Not possible to buy on all groups%0A            return false;%0A        %7D%0A        if (!properties%5B0%5D.getGroup().getProperties().stream().allMatch(p -%3E p.isOwnedBy(player))) %7B%0A            // Can only buy if you own the whole group%0A            return false;%0A        %7D%0A        PropertyGroup group = properties%5B0%5D.getGroup();%0A        int%5B%5D resultingHouseCount = group.getProperties().stream().mapToInt(Property::getHouseCount).toArray();%0A%0A        for (int i = 0; i %3C amount; i++) %7B%0A            int index = i %25 properties.length;%0A            Property property = properties%5Bindex%5D;%0A            int groupIndex = group.getProperties().indexOf(property);%0A            resultingHouseCount%5BgroupIndex%5D++;%0A        %7D%0A%0A        IntSummaryStatistics stats = Arrays.stream(resultingHouseCount).summaryStatistics();%0A        boolean balanced = stats.getMax() - stats.getMin() %3C= 1;%0A        return balanced && player.getGame().isEmptyStack() && player.getGame().getCurrentPlayer() == player && player.getMoney() %3E= getCost();%0A    %7D%0A%0A    private int getCost() %7B%0A        return amount * properties%5B0%5D.getGroup().getHouseCost();%0A    %7D%0A%0A    @Override%0A    public GameActionResult perform(Player player) %7B%0A        player.pay(null, getCost());%0A        for (int i = 0; i %3C amount; i++) %7B%0A            int propertyIndex = i %25 properties.length;%0A            Property property = properties%5BpropertyIndex%5D;%0A            property.setHouseCount(property.getHouseCount() + 1);%0A        %7D%0A        return new GameActionResult(true, player + %22 built %22 + amount + %22 buildings on %22 + properties%5B0%5D.getGroup().getName())
 ;%0A  

Implement BuildAction