mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Tests: added random results image generators (random, shuffle, dice, planar dice);
This commit is contained in:
parent
2e6b94982e
commit
0293b91c25
2 changed files with 125 additions and 4 deletions
|
@ -1,12 +1,27 @@
|
||||||
package org.mage.test.utils;
|
package org.mage.test.utils;
|
||||||
|
|
||||||
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.DeckCardLists;
|
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 mage.util.RandomUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,5 +71,98 @@ public class RandomTest {
|
||||||
Assert.assertNotEquals("different seed must have different deck", infoSameA, infoDifferent);
|
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
package mage.players;
|
package mage.players;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.util.RandomUtil;
|
import mage.util.RandomUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
@ -234,4 +234,17 @@ public class Library implements Serializable {
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.emptyDraw = false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue