From adceaf727945fb1175c0b95eea1fe7ca69faa7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Hor=C3=A1=C4=8Dek?= <horaceklubos@gmail.com> Date: Tue, 23 Jun 2015 15:07:26 +0200 Subject: [PATCH] Random access refactor --- .../tablexia/game/AbstractTablexiaGame.java | 39 +-- .../tablexia/game/common/RandomAccess.java | 45 --- .../tablexia/game/common/TablexiaRandom.java | 28 ++ .../game/games/kidnapping/KidnappingGame.java | 6 +- .../games/night_watch/NightWatchGame.java | 2 +- .../game/games/robbery/RobberyGame.java | 4 +- .../robbery/creature/CreatureFactory.java | 36 +-- .../robbery/creature/attribute/Attribute.java | 9 +- .../game/games/robbery/rules/GameRule.java | 294 +++++++++--------- .../games/robbery/rules/GameRuleUtility.java | 10 +- .../robbery/rules/GameRulesDefinition.java | 9 +- .../games/robbery/rules/easy/BC_1_BCRule.java | 28 +- .../games/robbery/rules/easy/Bb_0_BbRule.java | 8 +- .../games/robbery/rules/easy/Bt_0_BtRule.java | 20 +- .../games/robbery/rules/easy/CACARule.java | 10 +- .../games/robbery/rules/easy/CACCRule.java | 13 +- .../robbery/rules/easy/CA_0_CC_0_TRule.java | 24 +- .../games/robbery/rules/easy/CCCCRule.java | 14 +- .../robbery/rules/easy/CC_0_CC_0_TRule.java | 11 +- .../robbery/rules/easy/CC_0_notCCRule.java | 22 +- .../games/robbery/rules/hard/Bb_1_BbRule.java | 8 +- .../games/robbery/rules/hard/Bt_1_BtRule.java | 7 +- .../robbery/rules/hard/CCCCnotCCRule.java | 22 +- .../robbery/rules/hard/CC_0_CC_0_CCRule.java | 32 +- .../rules/hard/CC_0_notCA_0_TRule.java | 12 +- .../rules/hard/CC_0_notCC_0_TRule.java | 16 +- .../games/robbery/rules/hard/CC_2_CCRule.java | 8 +- .../robbery/rules/medium/BC_2_BCRule.java | 7 +- .../robbery/rules/medium/CA_1_CCRule.java | 10 +- .../robbery/rules/medium/CCCCCCRule.java | 14 +- .../robbery/rules/medium/CC_1_CCRule.java | 24 +- .../robbery/rules/medium/CC_1_notCARule.java | 12 +- .../robbery/rules/medium/CC_1_notCCRule.java | 7 +- 33 files changed, 403 insertions(+), 408 deletions(-) delete mode 100644 core/src/cz/nic/tablexia/game/common/RandomAccess.java create mode 100644 core/src/cz/nic/tablexia/game/common/TablexiaRandom.java diff --git a/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java b/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java index 8cb81201c..54d4cca86 100644 --- a/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java +++ b/core/src/cz/nic/tablexia/game/AbstractTablexiaGame.java @@ -2,7 +2,6 @@ package cz.nic.tablexia.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Interpolation; @@ -19,7 +18,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import cz.nic.tablexia.TablexiaSettings; -import cz.nic.tablexia.game.common.RandomAccess; +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; @@ -39,27 +38,29 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> private static final String GLOBAL_ATLAS_NAME = "game/_global/_global.atlas"; - public static final String RANDOM_SEED_SCREEN_INFO_LABEL = "Random Seed"; - public static final String GAME_DIFFICULTY_SCREEN_INFO_LABEL = "Game Difficulty"; - private static final int SCREEN_TRANSACTION_FADE_DELAY = 1; + public static final String RANDOM_SEED_SCREEN_INFO_LABEL = "Random Seed"; + public static final String GAME_DIFFICULTY_SCREEN_INFO_LABEL = "Game Difficulty"; + private static final int SCREEN_TRANSACTION_FADE_DELAY = 1; - public static final String VICTORYSCREEN_RESULTSBANNER = "resultsbanner"; - public static final String VICTORYSCREEN_RATINGSTAR_DISABLED = "ratingstar_disabled"; - public static final String VICTORYSCREEN_RATINGSTAR_ENABLED = "ratingstar_enabled"; + public static final String VICTORYSCREEN_RESULTSBANNER = "resultsbanner"; + public static final String VICTORYSCREEN_RATINGSTAR_DISABLED = "ratingstar_disabled"; + public static final String VICTORYSCREEN_RATINGSTAR_ENABLED = "ratingstar_enabled"; - private RandomAccess randomAccess; - private GameDifficulty gameDifficulty; - private Actor screenDimmer; + private TablexiaRandom random; + private GameDifficulty gameDifficulty; + private Actor screenDimmer; public AbstractTablexiaGame() { final TextureRegion texture = getColorTextureRegion(Color.BLACK, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - screenDimmer = new Actor(){ + screenDimmer = new Actor() { public void draw(Batch batch, float parentAlpha) { batch.setColor(getColor()); batch.draw(texture, 0, 0); batch.setColor(Color.WHITE); - }; + } + + ; }; screenDimmer.addAction(alpha(0)); getStage().addActor(screenDimmer); @@ -94,13 +95,13 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> @Override protected final T prepareScreenData() { - randomAccess = new RandomAccess(); - printScreenInfo(RANDOM_SEED_SCREEN_INFO_LABEL, "" + getRandomAccess().getRandomSeed()); + random = new TablexiaRandom(); + printScreenInfo(RANDOM_SEED_SCREEN_INFO_LABEL, "" + getRandom().getSeed()); - gameDifficulty = TablexiaSettings.getInstance().getGameDifficulty(GameDefinition.getGameDefinitionForClass((Class<? extends AbstractTablexiaGame<?>>)getClass())); + gameDifficulty = TablexiaSettings.getInstance().getGameDifficulty(GameDefinition.getGameDefinitionForClass((Class<? extends AbstractTablexiaGame<?>>) getClass())); printScreenInfo(GAME_DIFFICULTY_SCREEN_INFO_LABEL, "" + gameDifficulty.name()); - Log.info(getClass(), "Start game data loading with random seed: " + getRandomAccess().getRandomSeed() + " and difficulty: " + getGameDifficulty()); + Log.info(getClass(), "Start game data loading with: " + getRandom().toString() + " and difficulty: " + getGameDifficulty()); return prepareGameData(); } @@ -237,8 +238,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> } } - protected RandomAccess getRandomAccess() { - return randomAccess; + protected TablexiaRandom getRandom() { + return random; } protected GameDifficulty getGameDifficulty() { diff --git a/core/src/cz/nic/tablexia/game/common/RandomAccess.java b/core/src/cz/nic/tablexia/game/common/RandomAccess.java deleted file mode 100644 index df6d4b280..000000000 --- a/core/src/cz/nic/tablexia/game/common/RandomAccess.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Tablexia - * - * Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - ******************************************************************************/ -package cz.nic.tablexia.game.common; - -import java.util.Random; - -/** - * - * @author Matyáš Latner - */ -public class RandomAccess { - - private long randomSeed; - private Random random; - - public RandomAccess() { - randomSeed = System.currentTimeMillis(); - random = new Random(randomSeed); - } - - public Random getRandom() { - return random; - } - - public long getRandomSeed() { - return randomSeed; - } - -} diff --git a/core/src/cz/nic/tablexia/game/common/TablexiaRandom.java b/core/src/cz/nic/tablexia/game/common/TablexiaRandom.java new file mode 100644 index 000000000..78e5fc2e5 --- /dev/null +++ b/core/src/cz/nic/tablexia/game/common/TablexiaRandom.java @@ -0,0 +1,28 @@ +package cz.nic.tablexia.game.common; + +import java.util.Random; + +/** + * Created by lhoracek on 6/23/15. + */ +public class TablexiaRandom extends Random { + private final long seed; + + public TablexiaRandom(long seed) { + super(seed); + this.seed = seed; + } + + public TablexiaRandom() { + this(System.currentTimeMillis()); + } + + public long getSeed() { + return seed; + } + + @Override + public String toString() { + return "Random[seed:" + seed + "]"; + } +} diff --git a/core/src/cz/nic/tablexia/game/games/kidnapping/KidnappingGame.java b/core/src/cz/nic/tablexia/game/games/kidnapping/KidnappingGame.java index aaa8a9406..556c97ab4 100644 --- a/core/src/cz/nic/tablexia/game/games/kidnapping/KidnappingGame.java +++ b/core/src/cz/nic/tablexia/game/games/kidnapping/KidnappingGame.java @@ -49,7 +49,7 @@ public class KidnappingGame extends AbstractTablexiaGame<GameState> { @Override protected GameState prepareGameData() { - GameState gs = GameState.GameStateFactory.createInstance(getRandomAccess().getRandom(), getGameDifficulty(), Properties.MAP_WIDTH, Properties.MAP_HEIGHT, Properties.GAME_STOPS, Properties.MAP_WIDTH / 2, Properties.MAP_HEIGHT / 2); + GameState gs = GameState.GameStateFactory.createInstance(getRandom(), getGameDifficulty(), Properties.MAP_WIDTH, Properties.MAP_HEIGHT, Properties.GAME_STOPS, Properties.MAP_WIDTH / 2, Properties.MAP_HEIGHT / 2); Log.info(getClass(), "Game State: " + gs.toString()); return gs; } @@ -93,7 +93,7 @@ public class KidnappingGame extends AbstractTablexiaGame<GameState> { if (getData().getLastDirection() == null) { Direction[] dirs = null; do { - dirs = DirectionsHelper.getNextDirections(Direction.values()[getRandomAccess().getRandom().nextInt(Direction.values().length)]); + dirs = DirectionsHelper.getNextDirections(Direction.values()[getRandom().nextInt(Direction.values().length)]); } while (!Arrays.asList(dirs).contains(getData().getNextDirection())); return dirs; } @@ -117,7 +117,7 @@ public class KidnappingGame extends AbstractTablexiaGame<GameState> { final Arrow[] arrows = map.getDirectionArrow(position, directions); map.addAction(Actions.sequence(ShowArrowAction.arrowsFadeIn(arrows), Actions.delay(0.5f), ArrowMusicAction.arrowSequence(sounds, arrows), ReplayAlphaAction.fadeIn(), Actions.run(new Runnable() { public void run() { - final Arrow correct = arrows[(getData().getStep() == getData().getPath().size() - 1) ? getRandomAccess().getRandom().nextInt(arrows.length) : DirectionsHelper.getNextDirectionIndex(directions, getData().getNextDirection())]; + final Arrow correct = arrows[(getData().getStep() == getData().getPath().size() - 1) ? getRandom().nextInt(arrows.length) : DirectionsHelper.getNextDirectionIndex(directions, getData().getNextDirection())]; for (Arrow a : arrows) { for (EventListener el : a.getListeners()) { a.removeListener(el); diff --git a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java index d5567e028..064026edc 100644 --- a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java +++ b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java @@ -63,7 +63,7 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { // difficulty = getGameDifficulty().ordinal(); - gameSolutions = GameSolutionGenerator.generateSolutions(difficulty,getRandomAccess().getRandom()); + gameSolutions = GameSolutionGenerator.generateSolutions(difficulty, getRandom()); selectedWindows = new HashSet<Integer>(); prepareBackground(); diff --git a/core/src/cz/nic/tablexia/game/games/robbery/RobberyGame.java b/core/src/cz/nic/tablexia/game/games/robbery/RobberyGame.java index bb1ac3b7c..7c807a49c 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/RobberyGame.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/RobberyGame.java @@ -41,8 +41,8 @@ public class RobberyGame extends AbstractTablexiaGame<GameRule> { @Override protected GameRule prepareGameData() { - GameRulesDefinition rule = GameRulesDefinition.getRandomGameRuleForDifficulty(getGameDifficulty(), getRandomAccess().getRandom()); - GameRule gameRule = rule.getGameRuleInstance(getRandomAccess(), CREATURES_COUNT, THIEVES_COUNT); + GameRulesDefinition rule = GameRulesDefinition.getRandomGameRuleForDifficulty(getGameDifficulty(), getRandom()); + GameRule gameRule = rule.getGameRuleInstance(getRandom(), CREATURES_COUNT, THIEVES_COUNT); gameRule.generateCreatures(); printScreenInfo("Game Rule", gameRule.getGameRuleDefinition().name()); diff --git a/core/src/cz/nic/tablexia/game/games/robbery/creature/CreatureFactory.java b/core/src/cz/nic/tablexia/game/games/robbery/creature/CreatureFactory.java index 879c80ec5..de24c7d3d 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/creature/CreatureFactory.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/creature/CreatureFactory.java @@ -20,7 +20,8 @@ package cz.nic.tablexia.game.games.robbery.creature; import com.badlogic.gdx.utils.Disposable; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot.AttributeGender; import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; @@ -51,11 +52,10 @@ public class CreatureFactory implements Disposable { * If description is <code>null</code> or field gender on description is <code>null</code>, then is generated creature with random gender. * All creature attributes which are not defined in description are generated. * - * @param vertexBufferObject andengine vertex buffer * @return randomly generated creature */ - public CreatureRoot generateCreature(RandomAccess randomAccess) { - return generateCreature(null, null, randomAccess); + public CreatureRoot generateCreature(Random random) { + return generateCreature(null, null, random); } /** @@ -65,11 +65,10 @@ public class CreatureFactory implements Disposable { * * @param descriptionsToForce list of forced attributes, for <code>null</code> value is no attribute forced * @param descriptionToBan list of banned attributes, for <code>null</code> value is no attribute banned - * @param vertexBufferObject andengine vertex buffer * @return randomly generated creature */ - public CreatureRoot generateCreature(CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, RandomAccess randomAccess) { - return generateCreature(0, 0, descriptionsToForce, descriptionToBan, randomAccess); + public CreatureRoot generateCreature(CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, Random random) { + return generateCreature(0, 0, descriptionsToForce, descriptionToBan, random); } /** @@ -81,13 +80,12 @@ public class CreatureFactory implements Disposable { * @param pY creature position y * @param descriptionsToForce list of forced attributes, for <code>null</code> value is no attribute forced * @param descriptionToBan list of banned attributes, for <code>null</code> value is no attribute banned - * @param vertexBufferObject andengine vertex buffer * @return randomly generated creature */ - public CreatureRoot generateCreature(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, RandomAccess randomAccess) { + public CreatureRoot generateCreature(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, Random random) { - CreatureRoot creatureRoot = createCreatureAndAttributes(pX, pY, descriptionsToForce, descriptionToBan, randomAccess); - creatureRoot.generateCreature(descriptionToBan, randomAccess.getRandom()); + CreatureRoot creatureRoot = createCreatureAndAttributes(pX, pY, descriptionsToForce, descriptionToBan, random); + creatureRoot.generateCreature(descriptionToBan, random); creatureRoot.setAsThief(descriptionsToForce != null ? descriptionsToForce.isThief() : false); creatureRoot.setGroupNumber(descriptionsToForce != null ? descriptionsToForce.getGroupNumber() : CreatureRoot.CREATURE_GROUP_NUMBER_NOGROUP); return creatureRoot; @@ -99,12 +97,11 @@ public class CreatureFactory implements Disposable { * @param descriptionsToForce list of forced attributes, for <code>null</code> value is no attribute forced * @param descriptionToBan list of banned attributes, for <code>null</code> value is no attribute banned * @param copyThiefAttribute <code>true</code> copy thief flag from descriptionToForce - * @param vertexBufferObject andengine vertex buffer * @return randomly generated creature */ - public CreatureRoot getCreatureWithAttributes(CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, boolean copyThiefAttribute, RandomAccess randomAccess) { + public CreatureRoot getCreatureWithAttributes(CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, boolean copyThiefAttribute, Random random) { - return getCreatureWithAttributes(0, 0, descriptionsToForce, descriptionToBan, copyThiefAttribute, randomAccess); + return getCreatureWithAttributes(0, 0, descriptionsToForce, descriptionToBan, copyThiefAttribute, random); } /** @@ -115,13 +112,12 @@ public class CreatureFactory implements Disposable { * @param descriptionsToForce list of forced attributes, for <code>null</code> value is no attribute forced * @param descriptionToBan list of banned attributes, for <code>null</code> value is no attribute banned * @param copyThiefAttribute <code>true</code> copy thief flag from descriptionToForce - * @param vertexBufferObject andengine vertex buffer * @return randomly generated creature */ - public CreatureRoot getCreatureWithAttributes(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, boolean copyThiefAttribute, RandomAccess randomAccess) { + public CreatureRoot getCreatureWithAttributes(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, boolean copyThiefAttribute, Random random) { if ((descriptionsToForce != null) && descriptionsToForce.hasValidDescription()) { - CreatureRoot creatureRoot = createCreatureAndAttributes(pX, pY, descriptionsToForce, descriptionToBan, randomAccess); + CreatureRoot creatureRoot = createCreatureAndAttributes(pX, pY, descriptionsToForce, descriptionToBan, random); if (copyThiefAttribute && descriptionsToForce.isThief()) { creatureRoot.setAsThief(true); } @@ -133,13 +129,13 @@ public class CreatureFactory implements Disposable { /** * Creates creature with attributes in description parameter */ - private CreatureRoot createCreatureAndAttributes(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, RandomAccess randomAccess) { - AttributeGender genre = (descriptionsToForce != null) && (descriptionsToForce.getGender() != null) ? descriptionsToForce.getGender() : AttributeGender.getRandomGender(randomAccess.getRandom()); + private CreatureRoot createCreatureAndAttributes(float pX, float pY, CreatureDescriptor descriptionsToForce, CreatureDescriptor descriptionToBan, Random random) { + AttributeGender genre = (descriptionsToForce != null) && (descriptionsToForce.getGender() != null) ? descriptionsToForce.getGender() : AttributeGender.getRandomGender(random); CreatureRoot creatureRoot = new CreatureRoot(genre, pX, pY); if (descriptionsToForce != null) { for (AttributeDescription attributeDescriptionForce : descriptionsToForce.getDescriptions()) { for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { - if (creatureRoot.generateAttribute(attributeDescriptionForce, descriptionToBan, false, randomAccess.getRandom())) { + if (creatureRoot.generateAttribute(attributeDescriptionForce, descriptionToBan, false, random)) { break; } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/creature/attribute/Attribute.java b/core/src/cz/nic/tablexia/game/games/robbery/creature/attribute/Attribute.java index 17dc6c6fb..133cd950d 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/creature/attribute/Attribute.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/creature/attribute/Attribute.java @@ -18,6 +18,8 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.creature.attribute; +import com.badlogic.gdx.utils.reflect.ClassReflection; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -27,9 +29,6 @@ import java.util.List; import java.util.MissingResourceException; import java.util.Random; -import com.badlogic.gdx.utils.reflect.ClassReflection; - -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.RobberyGame; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot.AttributeGender; @@ -410,9 +409,9 @@ public abstract class Attribute { * @param attributeClass attribute class for obtain color * @return random available color */ - public static AttributeColor getRandomAvalibleColorFromAttributeClass(Class<? extends Attribute> attributeClass, RandomAccess randomAccess) { + public static AttributeColor getRandomAvalibleColorFromAttributeClass(Class<? extends Attribute> attributeClass, Random random) { List<AttributeColor> colorsFromAttributeClass = getAvalibleColorsFromAttributeClass(attributeClass); - return colorsFromAttributeClass.get(randomAccess.getRandom().nextInt(colorsFromAttributeClass.size())); + return colorsFromAttributeClass.get(random.nextInt(colorsFromAttributeClass.size())); } /** diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRule.java index dd03d2959..dbe34ae57 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRule.java @@ -1,28 +1,30 @@ -/******************************************************************************* - * Tablexia - * - * Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - ******************************************************************************/ +/** + * **************************************************************************** + * Tablexia + * <p/> + * Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz> + * <p/> + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * <p/> + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * <p/> + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * **************************************************************************** + */ package cz.nic.tablexia.game.games.robbery.rules; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.RobberyGame; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; @@ -36,7 +38,7 @@ import cz.nic.tablexia.util.Log; /** * Abstract game rule class. Contains common functions for all game rules. - * + * * @author Matyáš Latner */ public abstract class GameRule { @@ -52,143 +54,141 @@ public abstract class GameRule { } }; - - - private RandomAccess randomAccess; - protected int numberOfCreatures; - protected int numberOfThieves; - - private int groupNumber = 1; - - private List<CreatureRoot> creatures; + + + private Random random; + protected int numberOfCreatures; + protected int numberOfThieves; + + private int groupNumber = 1; + + private List<CreatureRoot> creatures; /* * Map for special creatures contains thieves and creatures which is important for thieves to be founded. */ - protected Map<Integer, CreatureDescriptor> specialCreatures; + protected Map<Integer, CreatureDescriptor> specialCreatures; - public GameRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - this.randomAccess = randomAccess; + public GameRule(Random random, int numberOfCreatures, int numberOfThieves) { + this.random = random; this.numberOfCreatures = numberOfCreatures; this.numberOfThieves = numberOfThieves; specialCreatures = new HashMap<Integer, CreatureDescriptor>(); - - Log.debug(getClass(), " ------- " + RULE_LOG_PREFIX + " " + getClass().getSimpleName() + " starts generating creatures with seed: [" + getRandomAccess().getRandomSeed() + "] -------"); + + Log.debug(getClass(), " ------- " + RULE_LOG_PREFIX + " " + getClass().getSimpleName() + " starts generating creatures with: [" + random.toString() + "] -------"); } - + public abstract GameRulesDefinition getGameRuleDefinition(); - - public RandomAccess getRandomAccess() { - return randomAccess; - } - + + public Random getRandom() { + return random; + } + protected void incrementGroupNumber() { - groupNumber++; - Log.debug(getClass(), RULE_LOG_PREFIX + "GROUP COMPLETE"); - } - - + groupNumber++; + Log.debug(getClass(), RULE_LOG_PREFIX + "GROUP COMPLETE"); + } + + /** * Add creature to the map of specials creatures at specific position - * + * * @param position key to special creatures map * @param specialCreature creature to add in */ protected void addSpecialCreature(Integer position, CreatureDescriptor specialCreature) { if (specialCreature != null) { - CreatureDescriptor existingCreature = specialCreatures.get(position); - if (existingCreature != null) { - for (AttributeDescription attributeDescription : specialCreature.getDescriptions()) { - existingCreature.addDescription(attributeDescription); - } - Log.debug(getClass(), RULE_LOG_PREFIX + " P[" + position + "] SPECIAL added: " + specialCreature); - } else { - existingCreature = new CreatureDescriptor(specialCreature.getDescriptions()); - specialCreatures.put(position, existingCreature); - Log.debug(getClass(), RULE_LOG_PREFIX + " P[" + position + "] SPECIAL generated: " + specialCreature); - } - existingCreature.setGroupNumber(groupNumber); - existingCreature.addCreatureOffsets(specialCreature.getCreatureOffsets()); - existingCreature.setThief(existingCreature.isThief() || specialCreature.isThief()); + CreatureDescriptor existingCreature = specialCreatures.get(position); + if (existingCreature != null) { + for (AttributeDescription attributeDescription : specialCreature.getDescriptions()) { + existingCreature.addDescription(attributeDescription); + } + Log.debug(getClass(), RULE_LOG_PREFIX + " P[" + position + "] SPECIAL added: " + specialCreature); + } else { + existingCreature = new CreatureDescriptor(specialCreature.getDescriptions()); + specialCreatures.put(position, existingCreature); + Log.debug(getClass(), RULE_LOG_PREFIX + " P[" + position + "] SPECIAL generated: " + specialCreature); + } + existingCreature.setGroupNumber(groupNumber); + existingCreature.addCreatureOffsets(specialCreature.getCreatureOffsets()); + existingCreature.setThief(existingCreature.isThief() || specialCreature.isThief()); } } /** * Return random number from interval for thief position. - * + * * @param intervalStart start of interval * @param intervalSize size of interval * @return */ protected int getThiefRandomPositionInInterval(int intervalStart, int intervalSize, int minValue) { - int position = getRandomAccess().getRandom().nextInt(intervalSize); + int position = getRandom().nextInt(intervalSize); if (position < minValue) { position = minValue; } return intervalStart + position; } - + /** * Return random number from interval for thief position. - * - * @param intervalStart start of interval - * @param intervalSize size of interval + * TODO fix comments * @return */ protected int getThiefRandomPositionInInterval(int minValue, List<Integer> bannedPositions) { - int result = -1; - for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { - int position = getRandomAccess().getRandom().nextInt(numberOfCreatures); - if (position < minValue) { - position = minValue; - } - if (bannedPositions == null || !bannedPositions.contains(position)) { - result = position; - break; - } - } + int result = -1; + for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { + int position = getRandom().nextInt(numberOfCreatures); + if (position < minValue) { + position = minValue; + } + if (bannedPositions == null || !bannedPositions.contains(position)) { + result = position; + break; + } + } return result; } - + /** * Returns creature description with two random attributes. - * + * * @param descriptor random creature description from is choose random attributes * @return creature description with one random attribute */ protected CreatureDescriptor getRandomCreatureDescriptionWithTwoAttributes(CreatureDescriptor descriptor) { CreatureDescriptor creatureDescriptor = new CreatureDescriptor(); - - int randomDescriptionPosition1 = getRandomAccess().getRandom().nextInt(descriptor.getDescriptions().size()); + + int randomDescriptionPosition1 = getRandom().nextInt(descriptor.getDescriptions().size()); int randomDescriptionPosition2; for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { - randomDescriptionPosition2 = getRandomAccess().getRandom().nextInt(descriptor.getDescriptions().size()); - if (randomDescriptionPosition1 != randomDescriptionPosition2) { - creatureDescriptor.addDescription(descriptor.getDescriptions().get(randomDescriptionPosition1)); - creatureDescriptor.addDescription(descriptor.getDescriptions().get(randomDescriptionPosition2)); - return creatureDescriptor; - } - } + randomDescriptionPosition2 = getRandom().nextInt(descriptor.getDescriptions().size()); + if (randomDescriptionPosition1 != randomDescriptionPosition2) { + creatureDescriptor.addDescription(descriptor.getDescriptions().get(randomDescriptionPosition1)); + creatureDescriptor.addDescription(descriptor.getDescriptions().get(randomDescriptionPosition2)); + return creatureDescriptor; + } + } throw new IllegalStateException("Cannot select two different descriptions from creature description!"); } - + /** * Returns creature description with N random attributes. - * + * * @param sourceCreatureDescriptor creature description for generating from * @param descriptionsNumber number of used attribute descriptions from creature description * @return creature description with N random attributes. */ protected CreatureDescriptor getRandomCreatureDescriptionWithNAttributes(CreatureDescriptor sourceCreatureDescriptor, int descriptionsNumber) { - CreatureDescriptor creatureDescriptor = new CreatureDescriptor(); - - for (int i = 0; i < descriptionsNumber; i++) { - creatureDescriptor.addDescription(getRandomAttributeDescriptionFromCreatureDescription(sourceCreatureDescriptor, creatureDescriptor.getDescriptions())); - } - - return creatureDescriptor; + CreatureDescriptor creatureDescriptor = new CreatureDescriptor(); + + for (int i = 0; i < descriptionsNumber; i++) { + creatureDescriptor.addDescription(getRandomAttributeDescriptionFromCreatureDescription(sourceCreatureDescriptor, creatureDescriptor.getDescriptions())); + } + + return creatureDescriptor; } - + /** * Returns attribute description from source creature description which is not in bannedAttributeDescriptions list parameter * @@ -196,18 +196,18 @@ public abstract class GameRule { * @return randomly selected attribute description from creature description in parameter */ public AttributeDescription getRandomAttributeDescriptionFromCreatureDescription(CreatureDescriptor creatureDescriptor, List<AttributeDescription> bannedAttributeDescriptions) { - for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { - AttributeDescription attributeDescription = creatureDescriptor.getDescriptions().get(getRandomAccess().getRandom().nextInt(creatureDescriptor.getDescriptions().size())); - if (!bannedAttributeDescriptions.contains(attributeDescription)) { - return attributeDescription; - } - } - throw new IllegalStateException("Cannot select attribute description from creature description!"); - } + for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { + AttributeDescription attributeDescription = creatureDescriptor.getDescriptions().get(getRandom().nextInt(creatureDescriptor.getDescriptions().size())); + if (!bannedAttributeDescriptions.contains(attributeDescription)) { + return attributeDescription; + } + } + throw new IllegalStateException("Cannot select attribute description from creature description!"); + } /** * Returns creature description with one random attribute. - * + * * @param descriptor random creature description from is choose random attribute * @return creature description with one random attribute */ @@ -220,28 +220,28 @@ public abstract class GameRule { /** * Returns random attribute description from creature description - * + * * @param descriptor random creature description from is choose random attribute * @return random attribute description */ protected AttributeDescription getRandomAttributeDescription(CreatureDescriptor descriptor) { List<AttributeDescription> descriptions = descriptor.getDescriptions(); - return descriptions.get(getRandomAccess().getRandom().nextInt(descriptions.size())); + return descriptions.get(getRandom().nextInt(descriptions.size())); } /** * Returns attribute description. - * + * * @param attributeDescription attribute description class * @return attribute description */ protected String getAttributeName(AttributeDescription attributeDescription, boolean useForcedVersion) { - return getAttributeName(attributeDescription.getAttributeClass(), useForcedVersion); + return getAttributeName(attributeDescription.getAttributeClass(), useForcedVersion); } - + /** * Returns attribute description. - * + * * @param attributeClass attribute class * @return attribute description */ @@ -251,7 +251,7 @@ public abstract class GameRule { /** * Returns color description. If there is no color returns empty string. - * + * * @param attributeDescription attribute description for obtain color from * @return color description */ @@ -259,14 +259,14 @@ public abstract class GameRule { AttributeColor attributeColor = attributeDescription.getAttributeColor(); return attributeColor != null ? RobberyGame.getRobberyText(attributeColor.getDescriptionResourceName()) : ""; } - + public String getRuleMessageText() { - return RobberyGame.getRobberyFormatedText(getGameRuleDefinition().getGameRuleStringName(), (Object[]) getRuleMessageParameters()); + return RobberyGame.getRobberyFormatedText(getGameRuleDefinition().getGameRuleStringName(), (Object[]) getRuleMessageParameters()); } /** * Returns random color from randomly generated creature without any banned attributes from parameter - * + * * @param banAttributes banned attributes * @return randomly generated color */ @@ -274,22 +274,22 @@ public abstract class GameRule { AttributeColor randomColor = null; int tryCount = 0; while (randomColor == null) { - CreatureDescriptor randomCreature = CreatureFactory.getInstance().generateCreature(null, banAttributes, getRandomAccess()).getCreatureDescrition(); + CreatureDescriptor randomCreature = CreatureFactory.getInstance().generateCreature(null, banAttributes, getRandom()).getCreatureDescrition(); List<AttributeDescription> randomDescriptions = randomCreature.getDescriptions(); - AttributeDescription randomDescription = randomDescriptions.get(getRandomAccess().getRandom().nextInt(randomDescriptions.size())); - randomColor = randomDescription.getAttributeColor(); - if (tryCount >= GENERATOR_TRY_COUNT) { - throw new IllegalStateException("Cannot generate random color!"); - } - tryCount++; - } - + AttributeDescription randomDescription = randomDescriptions.get(getRandom().nextInt(randomDescriptions.size())); + randomColor = randomDescription.getAttributeColor(); + if (tryCount >= GENERATOR_TRY_COUNT) { + throw new IllegalStateException("Cannot generate random color!"); + } + tryCount++; + } + return randomColor; } /** * Adds random creature which has not thieve attribute when there is creature before with "before thief attribute" - * + * * @param creatures list of creatures * @param lastCreature last generated creature * @param t1CreatureDescription description of creature before thief @@ -297,22 +297,22 @@ public abstract class GameRule { */ protected void addRandomCreatureAndCheckCreatureOneBefore(List<CreatureRoot> creatures, CreatureRoot lastCreature, CreatureDescriptor t1CreatureDescription, CreatureDescriptor t0CreatureDescription) { if ((lastCreature != null) && lastCreature.hasAttributes(t1CreatureDescription)) { - creatures.add(CreatureFactory.getInstance().generateCreature(null, t0CreatureDescription, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(null, t0CreatureDescription, getRandom())); } else { - creatures.add(CreatureFactory.getInstance().generateCreature(getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(getRandom())); } } /** * Returns array of strings with parameters to the rule message - * + * * @return array of strings with parameters to the rule message */ public String[] getRuleMessageParameters() { String[] messageParameters = prepareRuleMessageParameters(); if (messageParameters != null) { for (String parameter : messageParameters) { - Log.debug(getClass(), RULE_LOG_PREFIX + "parameter: " + parameter); + Log.debug(getClass(), RULE_LOG_PREFIX + "parameter: " + parameter); } } return messageParameters; @@ -322,7 +322,7 @@ public abstract class GameRule { * Generate new creature on n - 1 position without before thief creature attribute for special creature on position n * which is not thief and has thief attribute. When creature on n - 1 position has beforeThiefAttribute. * n = lastPosition parameter - * + * * @param creatures list of creatures to add in * @param lastPosition position n * @param lastCreature last generated creature @@ -334,11 +334,11 @@ public abstract class GameRule { if (!specialCreature.isThief() && specialCreature.hasAttributes(thiefCreatureDescription)) { if ((lastCreature != null) && lastCreature.hasAttributes(beforeThiefCreatureDescription)) { creatures.remove(lastPosition); - creatures.add(CreatureFactory.getInstance().generateCreature(null, beforeThiefCreatureDescription, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(null, beforeThiefCreatureDescription, getRandom())); } } } - + /** * Check compatibility for creature at specified position and creature from parameter * @param creatureDescriptor creature to check @@ -347,39 +347,39 @@ public abstract class GameRule { * @return <code>true</code> if creature description from parameter is compatible with creature in position */ protected boolean checkCreatureCompactibilityForPosition(CreatureDescriptor creatureDescriptor, int creaturePosition, boolean isThief) { - CreatureDescriptor specialCreature = specialCreatures.get(creaturePosition); - return specialCreature != null ? !(specialCreature.isThief() && isThief) && (specialCreature.checkDescriptionCompactibility(creatureDescriptor)) : true; - } + CreatureDescriptor specialCreature = specialCreatures.get(creaturePosition); + return specialCreature != null ? !(specialCreature.isThief() && isThief) && (specialCreature.checkDescriptionCompactibility(creatureDescriptor)) : true; + } /** * Returns array of strings with parameters to the rule message. Specific rule class implementation - * + * * @return array of strings with parameters to the rule message */ public abstract String[] prepareRuleMessageParameters(); /** * Returns list of creatures for displaying in game. List contains random creatures and thieves. - * + * * @return list of random creatures and thieves */ public void generateCreatures() { - prepareCreatureDescriptionsC(); + prepareCreatureDescriptionsC(); creatures = prepareCreatures(); - for (int i = 0; i < creatures.size(); i++) { - Log.debug(getClass(), RULE_LOG_PREFIX + " ---> [" + i + "] generated creature: " + creatures.get(i)); + for (int i = 0; i < creatures.size(); i++) { + Log.debug(getClass(), RULE_LOG_PREFIX + " ---> [" + i + "] generated creature: " + creatures.get(i)); } } - + public List<CreatureRoot> getCreatures() { - return creatures; - } - + return creatures; + } + protected abstract void prepareCreatureDescriptionsC(); /** * Returns list of creatures for displaying in game. List contains random creatures and thieves. Specific rule class implementation. - * + * * @return list of random creatures and thieves */ protected abstract List<CreatureRoot> prepareCreatures(); diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRuleUtility.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRuleUtility.java index 2d953406c..c3c4f95d9 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRuleUtility.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRuleUtility.java @@ -22,8 +22,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; @@ -45,8 +45,8 @@ public abstract class GameRuleUtility extends GameRule { private Map<Integer, CreatureDescriptor> globalCreatureDescriptors; private CreatureDescriptor baitCreatureDescriptor = new CreatureDescriptor(); - public GameRuleUtility(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves, int thiefGroupSize) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public GameRuleUtility(Random random, int numberOfCreatures, int numberOfThieves, int thiefGroupSize) { + super(random, numberOfCreatures, numberOfThieves); this.thiefGroupSize = thiefGroupSize; globalCreatureDescriptors = new HashMap<Integer, CreatureDescriptor>(); } @@ -112,7 +112,7 @@ public abstract class GameRuleUtility extends GameRule { * @return attribute description from bait creature description or <code>null</code> */ protected AttributeDescription getBaitCreatureDescriptionAttributeAtPosition(int position) { - if (getRandomAccess().getRandom().nextDouble() <= BAIT_PROBABILITY) { + if (getRandom().nextDouble() <= BAIT_PROBABILITY) { if (baitCreatureDescriptor != null) { return baitCreatureDescriptor.getDescriptions().get(position); } @@ -125,7 +125,7 @@ public abstract class GameRuleUtility extends GameRule { * @return bait creature description or <code>null</code> */ protected CreatureDescriptor getBaitCreatureDescriptionRandomly() { - if (getRandomAccess().getRandom().nextDouble() > BAIT_PROBABILITY) { + if (getRandom().nextDouble() > BAIT_PROBABILITY) { return null; } return baitCreatureDescriptor; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRulesDefinition.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRulesDefinition.java index a33665fae..47a7cd2f6 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRulesDefinition.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/GameRulesDefinition.java @@ -18,13 +18,12 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules; +import com.badlogic.gdx.utils.reflect.ClassReflection; + import java.util.ArrayList; import java.util.List; import java.util.Random; -import com.badlogic.gdx.utils.reflect.ClassReflection; - -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.games.robbery.rules.easy.BC_1_BCRule; import cz.nic.tablexia.game.games.robbery.rules.easy.Bb_0_BbRule; @@ -173,9 +172,9 @@ public enum GameRulesDefinition { * * @return new instance of game rule class */ - public GameRule getGameRuleInstance(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { + public GameRule getGameRuleInstance(Random random, int numberOfCreatures, int numberOfThieves) { try { - return (GameRule)ClassReflection.getConstructor(getGameRuleClass(), RandomAccess.class, int.class, int.class).newInstance(randomAccess, numberOfCreatures, numberOfThieves); + return (GameRule)ClassReflection.getConstructor(getGameRuleClass(), Random.class, int.class, int.class).newInstance(random, numberOfCreatures, numberOfThieves); } catch (Exception e) { Log.err(getClass(), "Cannot create instance of game rule: " + getGameRuleClass(), e); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/BC_1_BCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/BC_1_BCRule.java index a21dd5732..00f7a7bfb 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/BC_1_BCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/BC_1_BCRule.java @@ -20,14 +20,14 @@ package cz.nic.tablexia.game.games.robbery.rules.easy; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.rules.GameRuleUtility; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -42,12 +42,12 @@ public class BC_1_BCRule extends GameRuleUtility { protected Integer T1_OFFSET = Integer.valueOf(2); private AttributeDescription commonAttribute; - public BC_1_BCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public BC_1_BCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } - public BC_1_BCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves, int groupSize) { - super(randomAccess, numberOfCreatures, numberOfThieves, groupSize); + public BC_1_BCRule(Random random, int numberOfCreatures, int numberOfThieves, int groupSize) { + super(random, numberOfCreatures, numberOfThieves, groupSize); } @Override @@ -83,7 +83,7 @@ public class BC_1_BCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - commonAttribute = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + commonAttribute = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); addGlobalCreatureDescriptor(T1_OFFSET, new CreatureDescriptor()); addGlobalCreatureDescriptor(T0_OFFSET, new CreatureDescriptor()); @@ -91,9 +91,9 @@ public class BC_1_BCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsB() { - AttributeColor commonColor = Attribute.getRandomAvalibleColorFromAttributeClass(commonAttribute.getAttributeClass(), getRandomAccess()); - - getGlobalCreatureDescriptor(T0_OFFSET).clearDescriptions().addDescription(new AttributeDescription(commonColor, null, commonAttribute.getAttributeClass())); + AttributeColor commonColor = Attribute.getRandomAvalibleColorFromAttributeClass(commonAttribute.getAttributeClass(), getRandom()); + + getGlobalCreatureDescriptor(T0_OFFSET).clearDescriptions().addDescription(new AttributeDescription(commonColor, null, commonAttribute.getAttributeClass())); getGlobalCreatureDescriptor(T1_OFFSET).clearDescriptions().addDescription(new AttributeDescription(commonColor, null, commonAttribute.getAttributeClass())); } @@ -104,8 +104,8 @@ public class BC_1_BCRule extends GameRuleUtility { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { // add special creature - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); + } else { CreatureDescriptor creatureDescriptorToBan = new CreatureDescriptor(); creatureDescriptorToBan.disableGenderCompatibilityCheck(); @@ -125,8 +125,8 @@ public class BC_1_BCRule extends GameRuleUtility { } } - creatures.add(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandom())); + } } return creatures; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bb_0_BbRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bb_0_BbRule.java index 4184d9507..26db0df5d 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bb_0_BbRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bb_0_BbRule.java @@ -18,7 +18,9 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.easy; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.bottom.BottomAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -28,8 +30,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class Bb_0_BbRule extends Bt_0_BtRule { - public Bb_0_BbRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public Bb_0_BbRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bt_0_BtRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bt_0_BtRule.java index 17ee1bb3d..da545b3da 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bt_0_BtRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/Bt_0_BtRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.easy; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -43,12 +43,12 @@ public class Bt_0_BtRule extends GameRuleUtility { protected Class<? extends Attribute> attributeClass; - public Bt_0_BtRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public Bt_0_BtRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } - public Bt_0_BtRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves, int groupSize) { - super(randomAccess, numberOfCreatures, numberOfThieves, groupSize); + public Bt_0_BtRule(Random random, int numberOfCreatures, int numberOfThieves, int groupSize) { + super(random, numberOfCreatures, numberOfThieves, groupSize); } @Override @@ -91,7 +91,7 @@ public class Bt_0_BtRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsB() { - AttributeDescription commonAttributeDescription = CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getAttributeForType(attributeClass).getAttributeDescription(); + AttributeDescription commonAttributeDescription = CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getAttributeForType(attributeClass).getAttributeDescription(); getGlobalCreatureDescriptor(T1_OFFSET).clearDescriptions().addDescription(commonAttributeDescription); getGlobalCreatureDescriptor(T0_OFFSET).clearDescriptions().addDescription(commonAttributeDescription); @@ -104,8 +104,8 @@ public class Bt_0_BtRule extends GameRuleUtility { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { // add special creature - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); + } else { CreatureDescriptor creatureDescriptorToBan = new CreatureDescriptor(); creatureDescriptorToBan.disableGenderCompatibilityCheck(); @@ -125,8 +125,8 @@ public class Bt_0_BtRule extends GameRuleUtility { } } - creatures.add(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandom())); + } } return creatures; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACARule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACARule.java index 842e1b331..459765d58 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACARule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACARule.java @@ -18,10 +18,12 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.easy; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -31,8 +33,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class CACARule extends CCCCRule { - public CACARule(RandomAccess randomAcces, int numberOfCreatures, int numberOfThieves) { - super(randomAcces, numberOfCreatures, numberOfThieves); + public CACARule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACCRule.java index 809d7bc4e..206133310 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CACCRule.java @@ -18,11 +18,12 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.easy; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -32,8 +33,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class CACCRule extends CCCCRule { - public CACCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public CACCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override @@ -55,9 +56,9 @@ public class CACCRule extends CCCCRule { @Override protected void prepareCreatureDescriptionsC() { CreatureDescriptor creatureDescriptor = new CreatureDescriptor(); - CreatureDescriptor randomCreatureDescrition = CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(); + CreatureDescriptor randomCreatureDescrition = CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(); - int randomDescriptionPosition1 = getRandomAccess().getRandom().nextInt(randomCreatureDescrition.getDescriptions().size()); + int randomDescriptionPosition1 = getRandom().nextInt(randomCreatureDescrition.getDescriptions().size()); AttributeColor attributeColor = randomCreatureDescrition.getDescriptions().get(randomDescriptionPosition1).getAttributeColor(); for (int i = 0; i < GENERATOR_TRY_COUNT; i++) { diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CA_0_CC_0_TRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CA_0_CC_0_TRule.java index b47a50b9f..5a3dc7400 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CA_0_CC_0_TRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CA_0_CC_0_TRule.java @@ -20,13 +20,13 @@ package cz.nic.tablexia.game.games.robbery.rules.easy; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRuleUtility; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -43,8 +43,8 @@ public class CA_0_CC_0_TRule extends GameRuleUtility { protected static final Integer T1_OFFSET = Integer.valueOf(1); protected static final Integer T2_OFFSET = Integer.valueOf(2); - public CA_0_CC_0_TRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CA_0_CC_0_TRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -68,7 +68,7 @@ public class CA_0_CC_0_TRule extends GameRuleUtility { t2CreatureDescriptor.addDescription(new AttributeDescription(t2CommonAttributeColor, null, ClothingAttribute.class)); addGlobalCreatureDescriptor(T2_OFFSET, t2CreatureDescriptor); - addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 1)); + addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 1)); addGlobalCreatureDescriptor(T0_OFFSET, new CreatureDescriptor()); } @@ -88,22 +88,22 @@ public class CA_0_CC_0_TRule extends GameRuleUtility { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { // add special creature if (lastCreature != null && lastCreature.hasAttribute(getGlobalCreatureDescriptor(T2_OFFSET).getDescriptions().get(0)) && !creatureDescriptor.containsAttributeDescription(getGlobalCreatureDescriptor(T1_OFFSET).getDescriptions().get(0))) { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, getGlobalCreatureDescriptor(T1_OFFSET), getRandomAccess())); - } else { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, getGlobalCreatureDescriptor(T1_OFFSET), getRandom())); + } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); + } } else { if ((lastCreature != null) && lastCreature.hasAttributes(getGlobalCreatureDescriptor(T2_OFFSET))) { - creatures.add(CreatureFactory.getInstance().generateCreature(null, getGlobalCreatureDescriptor(T1_OFFSET), getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(null, getGlobalCreatureDescriptor(T1_OFFSET), getRandom())); } else { - if(getRandomAccess().getRandom().nextDouble() < BAIT_RANDOM_DISTRIBUTION) { + if(getRandom().nextDouble() < BAIT_RANDOM_DISTRIBUTION) { newBaitCreatureDescription(getGlobalCreatureDescriptor(T2_OFFSET)); } else { newBaitCreatureDescription(getGlobalCreatureDescriptor(T1_OFFSET)); } - creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), null, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), null, getRandom())); } } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CCCCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CCCCRule.java index a76c005fc..d9e8cc193 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CCCCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CCCCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.easy; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -38,8 +38,8 @@ public class CCCCRule extends GameRuleUtility { private static final int GROUP_SIZE = 1; protected static final Integer T0_OFFSET = Integer.valueOf(0); - public CCCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CCCCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -61,7 +61,7 @@ public class CCCCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - addGlobalCreatureDescriptor(0, getRandomCreatureDescriptionWithTwoAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition())); + addGlobalCreatureDescriptor(0, getRandomCreatureDescriptionWithTwoAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition())); } @Override @@ -78,11 +78,11 @@ public class CCCCRule extends GameRuleUtility { for (int i = 0; i < numberOfCreatures; i++) { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { // add special creature - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); } else { CreatureDescriptor creatureDescriptorToBan = null; - if (getRandomAccess().getRandom().nextBoolean()) { + if (getRandom().nextBoolean()) { creatureDescriptorToBan = creatureDescriptorToBan1; newBaitCreatureDescription(creatureDescriptorToBan2); } else { @@ -90,7 +90,7 @@ public class CCCCRule extends GameRuleUtility { newBaitCreatureDescription(creatureDescriptorToBan1); } - creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandom())); } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_CC_0_TRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_CC_0_TRule.java index 23a347398..d81bed679 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_CC_0_TRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_CC_0_TRule.java @@ -18,7 +18,8 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.easy; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; @@ -30,8 +31,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class CC_0_CC_0_TRule extends CA_0_CC_0_TRule { - public CC_0_CC_0_TRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public CC_0_CC_0_TRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override @@ -52,12 +53,12 @@ public class CC_0_CC_0_TRule extends CA_0_CC_0_TRule { @Override protected void prepareCreatureDescriptionsC() { - CreatureDescriptor t2CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + CreatureDescriptor t2CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); AttributeDescription t2AttributeDescription = t2CreatureDescriptor.getDescriptions().get(0); addGlobalCreatureDescriptor(T2_OFFSET, t2CreatureDescriptor); BAN_ATTRIBUTES_SET_FOR_GENERATING.addDescription(t2AttributeDescription); - addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition())); + addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition())); addGlobalCreatureDescriptor(T0_OFFSET, new CreatureDescriptor()); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_notCCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_notCCRule.java index 794d7e7ad..87a7c1e38 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_notCCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/easy/CC_0_notCCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.easy; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -40,12 +40,12 @@ public class CC_0_notCCRule extends GameRuleUtility { protected Integer T1_OFFSET = Integer.valueOf(1); protected CreatureDescriptor t0CreatureDescriptorToBan; - public CC_0_notCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_0_notCCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } - public CC_0_notCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves, int groupSize) { - super(randomAccess, numberOfCreatures, numberOfThieves, groupSize); + public CC_0_notCCRule(Random random, int numberOfCreatures, int numberOfThieves, int groupSize) { + super(random, numberOfCreatures, numberOfThieves, groupSize); } @Override @@ -66,7 +66,7 @@ public class CC_0_notCCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - AttributeDescription t1AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + AttributeDescription t1AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); CreatureDescriptor t1CreatureDescriptor = new CreatureDescriptor(); t1CreatureDescriptor.addDescription(t1AttributeDescription); addGlobalCreatureDescriptor(T1_OFFSET, t1CreatureDescriptor); @@ -80,7 +80,7 @@ public class CC_0_notCCRule extends GameRuleUtility { t2BannedAttributesForGenerator.addDescriptions(BAN_ATTRIBUTES_SET_FOR_GENERATING.getDescriptions()); t2BannedAttributesForGenerator.addDescription(t1AttributeDescription); - AttributeDescription t2AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, t2BannedAttributesForGenerator, getRandomAccess()).getCreatureDescrition()); + AttributeDescription t2AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, t2BannedAttributesForGenerator, getRandom()).getCreatureDescrition()); t0CreatureDescriptorToBan = new CreatureDescriptor(); t0CreatureDescriptorToBan.addDescription(t2AttributeDescription); } @@ -123,8 +123,8 @@ public class CC_0_notCCRule extends GameRuleUtility { } - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandom())); + } else { boolean hasNotT0Attribute = true; boolean hasNotBanT1Attribute = true; @@ -144,8 +144,8 @@ public class CC_0_notCCRule extends GameRuleUtility { creatureDescriptorToForce.addDescription(getBaitCreatureDescriptionAttributeAtPosition(0)); } - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandom())); + } } return creatures; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bb_1_BbRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bb_1_BbRule.java index 4549d6d76..f446d2399 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bb_1_BbRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bb_1_BbRule.java @@ -18,7 +18,9 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.hard; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.bottom.BottomAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -28,8 +30,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class Bb_1_BbRule extends Bt_1_BtRule { - public Bb_1_BbRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public Bb_1_BbRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bt_1_BtRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bt_1_BtRule.java index 722bd7a9e..39db5830a 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bt_1_BtRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/Bt_1_BtRule.java @@ -18,7 +18,8 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.hard; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; import cz.nic.tablexia.game.games.robbery.rules.easy.Bt_0_BtRule; @@ -30,8 +31,8 @@ public class Bt_1_BtRule extends Bt_0_BtRule { private static final int GROUP_SIZE = 3; - public Bt_1_BtRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public Bt_1_BtRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); T1_OFFSET = Integer.valueOf(2); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CCCCnotCCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CCCCnotCCRule.java index 5dc15ba1d..8877bb7c6 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CCCCnotCCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CCCCnotCCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.hard; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -40,8 +40,8 @@ public class CCCCnotCCRule extends GameRuleUtility { protected static final Integer T0_OFFSET = CreatureDescriptor.THIEF_OFFSET; private AttributeDescription t0AttributeDescriptionToBan; - public CCCCnotCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CCCCnotCCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -67,7 +67,7 @@ public class CCCCnotCCRule extends GameRuleUtility { protected void prepareCreatureDescriptionsC() { CreatureDescriptor creatureDescriptorToForce = new CreatureDescriptor(); creatureDescriptorToForce.addDescription(new AttributeDescription(null, null, HeadgearAttribute.class)); - CreatureDescriptor creatureDescriptor = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 3); + CreatureDescriptor creatureDescriptor = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 3); t0AttributeDescriptionToBan = getRandomAttributeDescription(creatureDescriptor); creatureDescriptor.getDescriptions().remove(t0AttributeDescriptionToBan); addGlobalCreatureDescriptor(T0_OFFSET, creatureDescriptor); @@ -90,13 +90,13 @@ public class CCCCnotCCRule extends GameRuleUtility { for (int i = 0; i < numberOfCreatures; i++) { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, t0CreatureDescriptionToBan, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, t0CreatureDescriptionToBan, getRandom())); + } else { CreatureDescriptor baitCreatureDescriptor = new CreatureDescriptor(); CreatureDescriptor creatureDescriptorToBan = null; creatureDescriptor = new CreatureDescriptor(); - switch(getRandomAccess().getRandom().nextInt(3)) { + switch(getRandom().nextInt(3)) { case 0: creatureDescriptorToBan = creatureDescriptorToBan0; @@ -119,10 +119,10 @@ public class CCCCnotCCRule extends GameRuleUtility { newBaitCreatureDescription(baitCreatureDescriptor); CreatureDescriptor baitCreatureDescriptionRandomly = getBaitCreatureDescriptionRandomly(); if (baitCreatureDescriptionRandomly != null) { - creatures.add(CreatureFactory.getInstance().generateCreature(baitCreatureDescriptionRandomly, creatureDescriptorToBan, getRandomAccess())); - } else { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(baitCreatureDescriptionRandomly, creatureDescriptorToBan, getRandom())); + } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandom())); + } } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_CC_0_CCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_CC_0_CCRule.java index e7bb98f88..8790c429d 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_CC_0_CCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_CC_0_CCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.hard; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -39,8 +39,8 @@ public class CC_0_CC_0_CCRule extends GameRuleUtility { protected static final Integer T1_OFFSET = Integer.valueOf(1); protected static final Integer T2_OFFSET = Integer.valueOf(2); - public CC_0_CC_0_CCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_0_CC_0_CCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -62,16 +62,16 @@ public class CC_0_CC_0_CCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - CreatureDescriptor t2CreatureDescriptor = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 1); + CreatureDescriptor t2CreatureDescriptor = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 1); addGlobalCreatureDescriptor(T2_OFFSET, t2CreatureDescriptor); - addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 1)); + addGlobalCreatureDescriptor(T1_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 1)); CreatureDescriptor t0CreatureDescriptorToBan = new CreatureDescriptor(); t0CreatureDescriptorToBan.disableGenderCompatibilityCheck(); t0CreatureDescriptorToBan.addDescriptions(BAN_ATTRIBUTES_SET_FOR_GENERATING.getDescriptions()); t0CreatureDescriptorToBan.addDescription(t2CreatureDescriptor.getDescriptions().get(0)); - addGlobalCreatureDescriptor(T0_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, t0CreatureDescriptorToBan, getRandomAccess()).getCreatureDescrition(), 1)); + addGlobalCreatureDescriptor(T0_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, t0CreatureDescriptorToBan, getRandom()).getCreatureDescrition(), 1)); } @Override @@ -101,24 +101,24 @@ public class CC_0_CC_0_CCRule extends GameRuleUtility { && l0Creature.hasAttribute(getGlobalCreatureDescriptor(T1_OFFSET).getDescriptions().get(0)) && !creatureDescriptor.containsCreatureOffset(T0_OFFSET)) { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, getGlobalCreatureDescriptor(T0_OFFSET), getRandomAccess())); - } else { - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, getGlobalCreatureDescriptor(T0_OFFSET), getRandom())); + } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); + } } else { if (l1Creature != null && l0Creature != null && l1Creature.hasAttribute(getGlobalCreatureDescriptor(T2_OFFSET).getDescriptions().get(0)) && l0Creature.hasAttribute(getGlobalCreatureDescriptor(T1_OFFSET).getDescriptions().get(0))) { - creatures.add(CreatureFactory.getInstance().generateCreature(null, getGlobalCreatureDescriptor(T0_OFFSET), getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(null, getGlobalCreatureDescriptor(T0_OFFSET), getRandom())); + } else { if (l0Creature != null && l0Creature.hasAttribute(getGlobalCreatureDescriptor(T2_OFFSET).getDescriptions().get(0))) { - creatures.add(CreatureFactory.getInstance().generateCreature(getGlobalCreatureDescriptor(T1_OFFSET), null, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(getGlobalCreatureDescriptor(T1_OFFSET), null, getRandom())); + } else { newBaitCreatureDescription(getGlobalCreatureDescriptor(T2_OFFSET)); - creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), null, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), null, getRandom())); + } } } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCA_0_TRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCA_0_TRule.java index 1f8324356..7bb275008 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCA_0_TRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCA_0_TRule.java @@ -18,11 +18,13 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.hard; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -32,8 +34,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class CC_0_notCA_0_TRule extends CC_0_notCC_0_TRule { - public CC_0_notCA_0_TRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public CC_0_notCA_0_TRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override @@ -52,7 +54,7 @@ public class CC_0_notCA_0_TRule extends CC_0_notCC_0_TRule { @Override protected void prepareCreatureDescriptionsC() { - AttributeDescription t2AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + AttributeDescription t2AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); CreatureDescriptor t2CreatureDescriptor = new CreatureDescriptor(); t2CreatureDescriptor.addDescription(t2AttributeDescription); addGlobalCreatureDescriptor(T2_OFFSET, t2CreatureDescriptor); diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCC_0_TRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCC_0_TRule.java index f1935d9f3..da96ed63f 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCC_0_TRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_0_notCC_0_TRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.hard; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -42,8 +42,8 @@ public class CC_0_notCC_0_TRule extends GameRuleUtility { CreatureDescriptor t1CreatureDescriptorToBan = new CreatureDescriptor(); - public CC_0_notCC_0_TRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_0_notCC_0_TRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -63,7 +63,7 @@ public class CC_0_notCC_0_TRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - CreatureDescriptor source = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 2); + CreatureDescriptor source = getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 2); CreatureDescriptor t2CreatureDescriptor = new CreatureDescriptor(); t2CreatureDescriptor.addDescription(source.getDescriptions().get(0)); @@ -111,8 +111,8 @@ public class CC_0_notCC_0_TRule extends GameRuleUtility { creatureDescriptorToBan.addDescription(t1AttributeDescriptionToBan); } - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandom())); + } else { boolean hasNotBanT2Attribute = true; boolean nextCreatureIsSpecial = true; @@ -135,8 +135,8 @@ public class CC_0_notCC_0_TRule extends GameRuleUtility { creatureDescriptorToForce.addDescription(getBaitCreatureDescriptionAttributeAtPosition(0)); } - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, creatureDescriptorToBan, getRandom())); + } } return creatures; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_2_CCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_2_CCRule.java index ee34ea946..3c113221b 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_2_CCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/hard/CC_2_CCRule.java @@ -18,7 +18,9 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.hard; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; import cz.nic.tablexia.game.games.robbery.rules.medium.CC_1_CCRule; @@ -30,8 +32,8 @@ public class CC_2_CCRule extends CC_1_CCRule { private static final int GROUP_SIZE = 4; - public CC_2_CCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_2_CCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); T1_OFFSET = Integer.valueOf(3); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/BC_2_BCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/BC_2_BCRule.java index 126246124..4545f909d 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/BC_2_BCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/BC_2_BCRule.java @@ -18,7 +18,8 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.medium; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; import cz.nic.tablexia.game.games.robbery.rules.easy.BC_1_BCRule; @@ -30,8 +31,8 @@ public class BC_2_BCRule extends BC_1_BCRule { private static final int GROUP_SIZE = 4; - public BC_2_BCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public BC_2_BCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); super.T1_OFFSET = Integer.valueOf(3); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CA_1_CCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CA_1_CCRule.java index 0eae3eb37..8306e8cb5 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CA_1_CCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CA_1_CCRule.java @@ -18,11 +18,11 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.medium; -import cz.nic.tablexia.game.common.RandomAccess; +import cz.nic.tablexia.game.common.TablexiaRandom; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; @@ -32,8 +32,8 @@ import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; */ public class CA_1_CCRule extends CC_1_CCRule { - public CA_1_CCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves); + public CA_1_CCRule(TablexiaRandom random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves); } @Override @@ -57,7 +57,7 @@ public class CA_1_CCRule extends CC_1_CCRule { t1CreatureDescriptor.addDescription(new AttributeDescription(t1CommonAttributeColor, null, ClothingAttribute.class)); addGlobalCreatureDescriptor(T1_OFFSET, t1CreatureDescriptor); - CreatureDescriptor t0CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + CreatureDescriptor t0CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); addGlobalCreatureDescriptor(T0_OFFSET, t0CreatureDescriptor); } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CCCCCCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CCCCCCRule.java index 008f1ff49..685c86641 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CCCCCCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CCCCCCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.medium; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -39,8 +39,8 @@ public class CCCCCCRule extends GameRuleUtility { private static final int GROUP_SIZE = 1; protected static final Integer T0_OFFSET = CreatureDescriptor.THIEF_OFFSET; - public CCCCCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CCCCCCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } @Override @@ -67,7 +67,7 @@ public class CCCCCCRule extends GameRuleUtility { protected void prepareCreatureDescriptionsC() { CreatureDescriptor creatureDescriptorToForce = new CreatureDescriptor(); creatureDescriptorToForce.addDescription(new AttributeDescription(null, null, HeadgearAttribute.class)); - addGlobalCreatureDescriptor(T0_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition(), 3)); + addGlobalCreatureDescriptor(T0_OFFSET, getRandomCreatureDescriptionWithNAttributes(CreatureFactory.getInstance().generateCreature(creatureDescriptorToForce, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition(), 3)); } @Override @@ -89,11 +89,11 @@ public class CCCCCCRule extends GameRuleUtility { for (int i = 0; i < numberOfCreatures; i++) { CreatureDescriptor creatureDescriptor = specialCreatures.get(i); if (creatureDescriptor != null) { // add special creature - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, null, getRandom())); } else { CreatureDescriptor creatureDescriptorToBan = null; CreatureDescriptor baitCreatureDescriptor = new CreatureDescriptor(); - switch(getRandomAccess().getRandom().nextInt(3)) { + switch(getRandom().nextInt(3)) { case 0: creatureDescriptorToBan = creatureDescriptorToBan0; baitCreatureDescriptor.addDescription(t0AttributeDescription1); @@ -111,7 +111,7 @@ public class CCCCCCRule extends GameRuleUtility { break; } newBaitCreatureDescription(baitCreatureDescriptor); - creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandomAccess())); + creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandom())); } } diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_CCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_CCRule.java index db7c79529..66eefcb26 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_CCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_CCRule.java @@ -20,8 +20,8 @@ package cz.nic.tablexia.game.games.robbery.rules.medium; import java.util.ArrayList; import java.util.List; +import java.util.Random; -import cz.nic.tablexia.game.common.RandomAccess; import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot; @@ -39,12 +39,12 @@ public class CC_1_CCRule extends GameRuleUtility { protected static final Integer T0_OFFSET = CreatureDescriptor.THIEF_OFFSET; protected Integer T1_OFFSET = Integer.valueOf(2); - public CC_1_CCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_1_CCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); } - public CC_1_CCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves, int creatureNumber) { - super(randomAccess, numberOfCreatures, numberOfThieves, creatureNumber); + public CC_1_CCRule(Random random, int numberOfCreatures, int numberOfThieves, int creatureNumber) { + super(random, numberOfCreatures, numberOfThieves, creatureNumber); } @Override @@ -64,7 +64,7 @@ public class CC_1_CCRule extends GameRuleUtility { @Override protected void prepareCreatureDescriptionsC() { - CreatureDescriptor t1CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandomAccess()).getCreatureDescrition()); + CreatureDescriptor t1CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, BAN_ATTRIBUTES_SET_FOR_GENERATING, getRandom()).getCreatureDescrition()); addGlobalCreatureDescriptor(T1_OFFSET, t1CreatureDescriptor); CreatureDescriptor creatureDescriptorToBan = new CreatureDescriptor(); @@ -72,7 +72,7 @@ public class CC_1_CCRule extends GameRuleUtility { creatureDescriptorToBan.addDescriptions(BAN_ATTRIBUTES_SET_FOR_GENERATING.getDescriptions()); creatureDescriptorToBan.addDescriptions(t1CreatureDescriptor.getDescriptions()); - CreatureDescriptor t0CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandomAccess()).getCreatureDescrition()); + CreatureDescriptor t0CreatureDescriptor = getRandomCreatureDescriptionWithOneAttribute(CreatureFactory.getInstance().generateCreature(null, creatureDescriptorToBan, getRandom()).getCreatureDescrition()); addGlobalCreatureDescriptor(T0_OFFSET, t0CreatureDescriptor); } @@ -104,8 +104,8 @@ public class CC_1_CCRule extends GameRuleUtility { creatureDescriptorToBan.addDescription(t0AttributeDescription); } - creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandomAccess())); - } else { + creatures.add(CreatureFactory.getInstance().generateCreature(creatureDescriptor, creatureDescriptorToBan, getRandom())); + } else { // RANDOM CREATURE @@ -115,14 +115,14 @@ public class CC_1_CCRule extends GameRuleUtility { } // BAIT ATTRIBUTE - if (getRandomAccess().getRandom().nextBoolean() || lastCreatureHasT1Attribute) { + if (getRandom().nextBoolean() || lastCreatureHasT1Attribute) { newBaitCreatureDescriptionFromAttribute(t1AttributeDescription); } else { newBaitCreatureDescriptionFromAttribute(t0AttributeDescription); } - creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandomAccess())); - } + creatures.add(CreatureFactory.getInstance().generateCreature(getBaitCreatureDescriptionRandomly(), creatureDescriptorToBan, getRandom())); + } } return creatures; diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCARule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCARule.java index a2010dd27..6cbe3ce96 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCARule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCARule.java @@ -18,11 +18,13 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.medium; -import cz.nic.tablexia.game.common.RandomAccess; + +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.creature.CreatureDescriptor; import cz.nic.tablexia.game.games.robbery.creature.CreatureFactory; -import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.Attribute.AttributeColor; +import cz.nic.tablexia.game.games.robbery.creature.attribute.AttributeDescription; import cz.nic.tablexia.game.games.robbery.creature.attribute.clothing.ClothingAttribute; import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; import cz.nic.tablexia.game.games.robbery.rules.easy.CC_0_notCCRule; @@ -35,8 +37,8 @@ public class CC_1_notCARule extends CC_0_notCCRule { private static final int GROUP_SIZE = 3; - public CC_1_notCARule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_1_notCARule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); T1_OFFSET = Integer.valueOf(2); } @@ -70,7 +72,7 @@ public class CC_1_notCARule extends CC_0_notCCRule { t1BannedAttributesForGenerator.addDescriptions(BAN_ATTRIBUTES_SET_FOR_GENERATING.getDescriptions()); t1BannedAttributesForGenerator.addDescription(t0AttributeDescription); - AttributeDescription t1AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, t1BannedAttributesForGenerator, getRandomAccess()).getCreatureDescrition()); + AttributeDescription t1AttributeDescription = getRandomAttributeDescription(CreatureFactory.getInstance().generateCreature(null, t1BannedAttributesForGenerator, getRandom()).getCreatureDescrition()); CreatureDescriptor t1CreatureDescriptor = new CreatureDescriptor(); t1CreatureDescriptor.addDescription(t1AttributeDescription); addGlobalCreatureDescriptor(T1_OFFSET, t1CreatureDescriptor); diff --git a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCCRule.java b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCCRule.java index 4edd3b4f3..763743409 100644 --- a/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCCRule.java +++ b/core/src/cz/nic/tablexia/game/games/robbery/rules/medium/CC_1_notCCRule.java @@ -18,7 +18,8 @@ ******************************************************************************/ package cz.nic.tablexia.game.games.robbery.rules.medium; -import cz.nic.tablexia.game.common.RandomAccess; +import java.util.Random; + import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition; import cz.nic.tablexia.game.games.robbery.rules.easy.CC_0_notCCRule; @@ -30,8 +31,8 @@ public class CC_1_notCCRule extends CC_0_notCCRule { private static final int GROUP_SIZE = 3; - public CC_1_notCCRule(RandomAccess randomAccess, int numberOfCreatures, int numberOfThieves) { - super(randomAccess, numberOfCreatures, numberOfThieves, GROUP_SIZE); + public CC_1_notCCRule(Random random, int numberOfCreatures, int numberOfThieves) { + super(random, numberOfCreatures, numberOfThieves, GROUP_SIZE); T1_OFFSET = Integer.valueOf(2); } -- GitLab