Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import javax.swing.*;
- /**
- * This script reproduces the method aoe2 uses to handle roles with "chance" triggers for players
- * We divide an amount of roles that equal to the amount of players and choose the chance for each player.
- * Each player can only get 1 role in every scenario.
- * The program shall then tell us how much times each player got a certain role, after iterating scenarios X times.
- * We can then keep tweaking the chance numbers until we get the deviation we require, using The law of large numbers.
- *
- * The program will show you exactly what will be the distribution of roles depending on the chances you give to each trigger
- * @author Bidderlyn
- */
- public class Main {
- public static void main(String[] args) {
- int amountOfPlayers; // the total amount of players. Input by user
- String playersInput = JOptionPane.showInputDialog("Enter the amount of players");
- amountOfPlayers = Integer.valueOf(playersInput);
- Player player[] = new Player[amountOfPlayers];
- int roles = player.length;
- int result[][] = new int[player.length][roles]; // first array represents the player N, 2nd array is the role. Index value is the amount of times player got the role.
- for(int j=0; j<player.length; j++)
- {
- player[j] = new Player(roles);
- }
- for(int i=0; i<roles; i++)
- {
- // i = role iteration
- // j = player iteration
- for(int j=0; j<player.length; j++)
- {
- // Setting the "chance" for each player in each role
- String chanceInput = JOptionPane.showInputDialog("Set the 'chance' condition for player"+(j+1)+" to get role number "+(i+1));
- player[j].chance[i] = Integer.valueOf(chanceInput);
- }
- }
- // SETUP INPUTS DONE
- // testing the scenario X times and posting the distribution. X determined by user.
- String testInput = JOptionPane.showInputDialog("Enter the amount of scenario simulations youd like to run");
- Integer scenarios = Integer.valueOf(testInput);
- for(int z=0; z<scenarios; z++)
- {
- // z = scenario iteration
- // i = role iteration
- // j = player iteration
- for(int i=0; i<player.length; i++)
- {
- // resetting all players data from previous scenario
- player[i].hasRole = false;
- player[i].role = 0;
- }
- for(int i=0; i<roles; i++ )
- {
- // handing out role <i>
- boolean roleHanded = false;
- while(!roleHanded)
- {
- for(int j=0; j<player.length; j++ )
- {
- // Attempting to give the role to each player by order, loops back to 1st player if no one got the role.
- if(!roleHanded && !player[j].hasRole && player[j].chance[i] > (Math.random() * 100) ) // player's chance against a random number between 1-100
- {
- //player[j] got the role
- roleHanded = true;
- player[j].hasRole = true;
- player[j].role = i;
- result[j][i]++; // updating the external results
- }
- // iterate to the next player.
- }
- // if no one got the role, it loops back to the 1st player and tries to hand it out again
- // if the role was given, while breaks and role iteration increases to hand out the next role.
- } // a role was handed
- } // finished handing all roles
- } // finished iteration scenarios
- for(int i=0; i<roles; i++)
- {
- String output = "";
- for(int j=0; j<player.length; j++)
- {
- output += "player"+(j+1)+" got role "+(i+1)+" "+result[j][i]+" amount of times \n";
- }
- //displaying the distribution to the user
- JFrame f=new JFrame();
- JOptionPane.showMessageDialog(f,output);
- }
- }
- }
Add Comment
Please, Sign In to add comment