Don't use the same build twice (untested!)

This commit is contained in:
Shaun Bennett 2016-01-22 01:37:47 -05:00
parent 49e439af55
commit 4bbd956e14
2 changed files with 20 additions and 2 deletions

View File

@ -152,6 +152,21 @@ public class UtilAlg
return list.get(UtilMath.r(list.size()));
}
public static <T> T Random(List<T> list, List<T> exclude)
{
int attempts = 0;
T element;
do
{
element = Random(list);
attempts++;
}
while (element != null && exclude.contains(element) && attempts < 15);
return element;
}
public static boolean inBoundingBox(Location loc, Location cornerA, Location cornerB)
{
if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false;

View File

@ -108,6 +108,7 @@ public class SpeedBuilders extends SoloGame
private Location _buildMiddle;
private ArrayList<BuildData> _buildData = new ArrayList<BuildData>();
private ArrayList<BuildData> _usedBuilds = new ArrayList<>();
private BuildData _currentBuild;
private BlockState[][] _defaultMiddleGround = new BlockState[BuildSize][BuildSize];
@ -458,7 +459,8 @@ public class SpeedBuilders extends SoloGame
return;
}
_currentBuild = UtilAlg.Random(_buildData);
_currentBuild = UtilAlg.Random(_buildData, _usedBuilds);
_usedBuilds.add(_currentBuild);
HashSet<Location> usedBuildLocs = new HashSet<Location>();
@ -833,7 +835,8 @@ public class SpeedBuilders extends SoloGame
clearCenterArea(true);
_currentBuild = UtilAlg.Random(_buildData);
_currentBuild = UtilAlg.Random(_buildData, _usedBuilds);
_usedBuilds.add(_currentBuild);
for (Player player : GetTeamList().get(0).GetPlayers(true))
{