mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor: fixed wrong random value usage
This commit is contained in:
parent
01dd8c33ba
commit
cacf8226aa
4 changed files with 8 additions and 5 deletions
|
|
@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import mage.client.constants.Constants;
|
import mage.client.constants.Constants;
|
||||||
import mage.client.dialog.PreferencesDialog;
|
import mage.client.dialog.PreferencesDialog;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,7 +128,7 @@ public class MusicPlayer {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
while (!stopped) {
|
while (!stopped) {
|
||||||
int it = (int) Math.abs(Math.random() * (filelist.getItemCount()));
|
int it = (int) Math.abs(RandomUtil.nextDouble() * (filelist.getItemCount()));
|
||||||
File file = new File(filepath + filelist.getItem(it));
|
File file = new File(filepath + filelist.getItem(it));
|
||||||
load(file);
|
load(file);
|
||||||
Thread PlayThread = new Thread(new PlayThread());
|
Thread PlayThread = new Thread(new PlayThread());
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import mage.client.dialog.PreferencesDialog;
|
||||||
import mage.components.ImagePanel;
|
import mage.components.ImagePanel;
|
||||||
import mage.components.ImagePanelStyle;
|
import mage.components.ImagePanelStyle;
|
||||||
import mage.interfaces.plugin.ThemePlugin;
|
import mage.interfaces.plugin.ThemePlugin;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
import net.xeoh.plugins.base.annotations.PluginImplementation;
|
import net.xeoh.plugins.base.annotations.PluginImplementation;
|
||||||
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
||||||
import net.xeoh.plugins.base.annotations.meta.Author;
|
import net.xeoh.plugins.base.annotations.meta.Author;
|
||||||
|
|
@ -111,7 +112,7 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
private BufferedImage loadbuffer_random() throws IOException {
|
private BufferedImage loadbuffer_random() throws IOException {
|
||||||
BufferedImage res;
|
BufferedImage res;
|
||||||
if (loadimages()) {
|
if (loadimages()) {
|
||||||
int it = (int) Math.abs(Math.random() * (flist.getItemCount()));
|
int it = (int) Math.abs(RandomUtil.nextDouble() * (flist.getItemCount()));
|
||||||
String filename = BackgroundDir + flist.getItem(it);
|
String filename = BackgroundDir + flist.getItem(it);
|
||||||
res = ImageIO.read(new File(filename));
|
res = ImageIO.read(new File(filename));
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ import mage.abilities.common.PassAbility;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.Combat;
|
import mage.game.combat.Combat;
|
||||||
import mage.game.combat.CombatGroup;
|
|
||||||
import mage.game.turn.Step.StepPart;
|
import mage.game.turn.Step.StepPart;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,7 +113,7 @@ public class MCTSNode {
|
||||||
uct = ((node.visits - node.wins) / (node.visits)) + (selectionCoefficient * Math.sqrt(Math.log(visits) / (node.visits)));
|
uct = ((node.visits - node.wins) / (node.visits)) + (selectionCoefficient * Math.sqrt(Math.log(visits) / (node.visits)));
|
||||||
else
|
else
|
||||||
// ensure that a random unvisited node is played first
|
// ensure that a random unvisited node is played first
|
||||||
uct = 10000 + 1000 * Math.random();
|
uct = 10000 + 1000 * RandomUtil.nextDouble();
|
||||||
if (uct > bestValue) {
|
if (uct > bestValue) {
|
||||||
bestChild = node;
|
bestChild = node;
|
||||||
bestValue = uct;
|
bestValue = uct;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.common.TargetOpponent;
|
import mage.target.common.TargetOpponent;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author noxx
|
* @author noxx
|
||||||
|
|
@ -70,7 +71,7 @@ class TyrantOfDiscordEffect extends OneShotEffect {
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
int count = game.getBattlefield().countAll(new FilterPermanent(), opponent.getId(), game);
|
int count = game.getBattlefield().countAll(new FilterPermanent(), opponent.getId(), game);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
int random = (int)(Math.random()*count);
|
int random = (int)(RandomUtil.nextDouble() * count);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponent.getId())) {
|
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponent.getId())) {
|
||||||
if (index == random) {
|
if (index == random) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue