diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java index 2d20d3f909..5735e12d60 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java @@ -1,12 +1,27 @@ package org.mage.test.utils; +import mage.cards.decks.Deck; import mage.cards.decks.DeckCardLists; +import mage.constants.MultiplayerAttackOption; +import mage.constants.PlanarDieRoll; +import mage.constants.RangeOfInfluence; +import mage.game.Game; +import mage.game.TwoPlayerDuel; +import mage.player.human.HumanPlayer; +import mage.players.Player; import mage.util.RandomUtil; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -56,5 +71,98 @@ public class RandomTest { Assert.assertNotEquals("different seed must have different deck", infoSameA, infoDifferent); } + @Test + @Ignore + public void test_GenerateRandomPng() throws IOException { + String dest = "f:/test/xmage/"; + int height = 512; + int weight = 512; + BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < weight; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, RandomUtil.nextBoolean() ? Color.white.getRGB() : Color.black.getRGB()); + } + } + ImageIO.write(image, "png", new File(dest + "xmage_random.png")); + } + @Test + @Ignore + public void test_GenerateRandomDicePng() throws IOException { + String dest = "f:/test/xmage/"; + //RandomUtil.setSeed(123); + Player player = new HumanPlayer("random", RangeOfInfluence.ALL, 1); + Game game = new TwoPlayerDuel(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, 0, 50); + + int height = 512; + int weight = 512; + BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < weight; x++) { + for (int y = 0; y < height; y++) { + // roll dice + int diceVal = player.rollDice(game, 12); + int colorMult = Math.floorDiv(255, 12); + + image.setRGB(x, y, new Color(colorMult * diceVal, colorMult * diceVal, colorMult * diceVal).getRGB()); + } + } + ImageIO.write(image, "png", new File(dest + "xmage_random_dice.png")); + } + + @Test + @Ignore + public void test_GenerateRandomPlanarDicePng() throws IOException { + String dest = "f:/test/xmage/"; + //RandomUtil.setSeed(123); + Player player = new HumanPlayer("random", RangeOfInfluence.ALL, 1); + Game game = new TwoPlayerDuel(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, 0, 50); + + int height = 512; + int weight = 512; + BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < weight; x++) { + for (int y = 0; y < height; y++) { + // roll planar dice + PlanarDieRoll res = player.rollPlanarDie(game); + image.setRGB(x, y, new Color( + res.equals(PlanarDieRoll.CHAOS_ROLL) ? 255 : 0, + res.equals(PlanarDieRoll.PLANAR_ROLL) ? 255 : 0, + res.equals(PlanarDieRoll.NIL_ROLL) ? 255 : 0 + ).getRGB()); + } + } + ImageIO.write(image, "png", new File(dest + "xmage_random_planar_dice.png")); + } + + @Test + @Ignore + public void test_GenerateRandomLibraryShufflePng() throws IOException { + String dest = "f:/test/xmage/"; + //RandomUtil.setSeed(123); + Player player = new HumanPlayer("random", RangeOfInfluence.ALL, 1); + Game game = new TwoPlayerDuel(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, 0, 50); + Deck deck = DeckTestUtils.buildRandomDeck("WGUBR", false, "GRN"); + player.getLibrary().addAll(deck.getCards(), game); + + // multiple cards analyze + for (int i = 0; i < player.getLibrary().size(); i++) { + UUID cardId = player.getLibrary().getCardList().get(i); + //int halfIndex = Math.floorDiv(player.getLibrary().size(), 2); + int colorMult = Math.floorDiv(255, player.getLibrary().size()); + + int height = 512; + int weight = 512; + BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < weight; x++) { + for (int y = 0; y < height; y++) { + // shuffle, search card position and draw + player.getLibrary().shuffle(); + int cardPos = player.getLibrary().getCardPosition(cardId); + //image.setRGB(x, y, cardPos < halfIndex ? Color.white.getRGB() : Color.black.getRGB()); + image.setRGB(x, y, new Color(colorMult * cardPos, colorMult * cardPos, colorMult * cardPos).getRGB()); + } + } + ImageIO.write(image, "png", new File(dest + "xmage_random_shuffle_" + i + ".png")); + } + } } diff --git a/Mage/src/main/java/mage/players/Library.java b/Mage/src/main/java/mage/players/Library.java index 3c896d5b83..2514aa7faa 100644 --- a/Mage/src/main/java/mage/players/Library.java +++ b/Mage/src/main/java/mage/players/Library.java @@ -1,15 +1,15 @@ - package mage.players; -import java.io.Serializable; -import java.util.*; -import java.util.stream.Collectors; import mage.cards.Card; import mage.constants.Zone; import mage.filter.FilterCard; import mage.game.Game; import mage.util.RandomUtil; +import java.io.Serializable; +import java.util.*; +import java.util.stream.Collectors; + /** * @author BetaSteward_at_googlemail.com */ @@ -234,4 +234,17 @@ public class Library implements Serializable { public void reset() { this.emptyDraw = false; } + + /** + * Tests only -- find card position in library + */ + public int getCardPosition(UUID cardId) { + UUID[] list = library.toArray(new UUID[0]); + for (int i = 0; i < list.length; i++) { + if (list[i].equals(cardId)) { + return i; + } + } + return -1; + } }