Solved

Translating Java to Delphi - Part 2

Posted on 2006-12-01
9
234 Views
Last Modified: 2010-04-05
Hi,
  This is related to my last question from a few days ago which was answered. Basically I want to convert a java program I obtained to Delphi - it's a simulation of an online slot machine. The java code has a lot of "classes" and "private" and "public" stuff in it. I can do some Delphi programming, but I don't know about "classes" etc, and never use them (or should I say, *avoid* using them. I know, I'm very old-school...shame on me).
   If I show one of the smaller Java units below, would someone be able to translate it into its Delphi "equivalent", just to get me started? I know I gotta learn this stuff. Thanks, Shawn.


package slotsimulator;

public class Thunderstruck extends MG5ReelSlot {


    //Data start.
    private  String slotName="Thunderstruck";
    private  int numberOfLines=9;
    private  int wildMultiplier= 2;
    private  int numberOfFreeSpins=15;
    private  int freeSpinMultiplier=3;
    private  int numberOfScattersToStartFeature=3;
    private  boolean reTriggersAllowed=true;

    private  ReelSymbol thor = new ReelSymbol("T",Boolean.TRUE,Boolean.FALSE,Boolean.FALSE,new int[]{0,10,200,2000,10000});
    private  ReelSymbol ram = new ReelSymbol("R",Boolean.FALSE,Boolean.TRUE,Boolean.FALSE,new int[]{0,2,5,20,500});
    private  ReelSymbol staff = new ReelSymbol("S",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,2,25,100,750});
    private  ReelSymbol hammer = new ReelSymbol("H",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,2,25,100,750});
    private  ReelSymbol castle = new ReelSymbol("C",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,15,100,400});
    private  ReelSymbol lightning = new ReelSymbol("L",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,10,75,250});
    private  ReelSymbol horn = new ReelSymbol("I",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,10,50,250});
    private  ReelSymbol ace = new ReelSymbol("A",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,10,50,125});
    private  ReelSymbol king = new ReelSymbol("K",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,5,50,125});
    private  ReelSymbol queen = new ReelSymbol("Q",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,5,25,100});
    private  ReelSymbol jack = new ReelSymbol("J",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,5,25,100});
    private  ReelSymbol ten = new ReelSymbol("X",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,0,5,25,100});
    private  ReelSymbol nine = new ReelSymbol("9",Boolean.FALSE,Boolean.FALSE,Boolean.TRUE,new int[]{0,2,5,25,100});

    private  ReelSymbol[] reel1Symbols=new ReelSymbol[]{jack,queen,castle,staff,hammer,castle,jack,ten,horn,ace,jack,queen,nine,jack,queen,lightning,horn,thor,staff,nine,horn,hammer,staff,king,ten,jack,horn,lightning,ace,ram};
    private  ReelSymbol[] reel2Symbols=new ReelSymbol[]{jack,ten,castle,jack,staff,lightning,castle,ace,jack,lightning,nine,king,queen,jack,thor,nine,ram,lightning,staff,hammer,nine,jack,horn,ace,king,jack,nine,lightning,horn,castle};
    private  ReelSymbol[] reel3Symbols= new ReelSymbol[]{ten,queen,horn,ace,ten,king,castle,queen,lightning,hammer,queen,ten,jack,queen,thor,staff,ten,queen,hammer,lightning,king,ten,queen,ace,ten,ram,castle,hammer,ace,nine};
    private  ReelSymbol[] reel4Symbols= new ReelSymbol[]{ten,jack,castle,king,lightning,horn,nine,king,castle,ram,ace,staff,hammer,horn,ace,ten,nine,thor,lightning,jack,king,nine,ace,horn,hammer,staff,king,queen,king,nine};
    private  ReelSymbol[] reel5Symbols= new ReelSymbol[]{jack,hammer,ten,ace,queen,king,horn,castle,queen,jack,castle,hammer,staff,horn,ten,ace,lightning,jack,hammer,horn,ram,staff,lightning,thor,castle,staff,jack,queen,lightning,hammer,staff,horn,king,nine,ace,ten,queen,king,staff,lightning,ten,castle,ace,nine};
    // Data end.

    private  Reel reel1 = new Reel();
    private  Reel reel2= new Reel();
    private  Reel reel3= new Reel();
    private  Reel reel4= new Reel();
    private  Reel reel5= new Reel();

    public Thunderstruck(){
        reel1.setSymbols(reel1Symbols);
        reel2.setSymbols(reel2Symbols);
        reel3.setSymbols(reel3Symbols);
        reel4.setSymbols(reel4Symbols);
        reel5.setSymbols(reel5Symbols);
    }

    public boolean getReTriggersAllowed(){
        return reTriggersAllowed;
    }

    public Reel getReel1(){
        return reel1;
    }

    public Reel getReel2(){
        return reel2;
    }

    public Reel getReel3(){
        return reel3;
    }

    public Reel getReel4(){
        return reel4;
    }

    public Reel getReel5(){
        return reel5;
    }

    public ReelSymbol getWild(){
        return thor;
    }


    public ReelSymbol getScatter(){
        return ram;
    }

    public int getNumberOfLines(){
        return numberOfLines;
    }

    public void setNumberOfLines(int n){
       this.numberOfLines=n;
    }

    public int getWildMultiplier(){
        return wildMultiplier;
    }

    public String getSlotName(){
        return slotName;
    }

    public int getNumberOfFreeSpins(){
        return numberOfFreeSpins;
    }

    public int getFreeSpinMultiplier(){
        return freeSpinMultiplier;
    }

    public int getNumberOfScattersToStartFeature(){
        return numberOfScattersToStartFeature;
    }


}
0
Comment
Question by:aztec
  • 3
  • 3
  • 2
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
you need also the "super"-Class MG5ReelSlot
(Thunderstruck is a descandend of MG5ReelSlot)

do you have this class in source?

meikl ;-)
0
 

Author Comment

by:aztec
Comment Utility
Yes I do Meikl.... it's a bit bigger than the other one though. Here it is:
(Thanks, Shawn)


  package slotsimulator;

import javax.swing.*;
import java.text.DecimalFormat;

public abstract class MG5ReelSlot implements Runnable{

    public static int RUNMODE_UNDEFINED=0;
    public static int RUNMODE_ANALYSE=1;
    public static int RUNMODE_FINDMAXIMUMWINCOMBINATION=2;
    public static int RUNMODE_SIMULATE=3;

    private int runmode=RUNMODE_UNDEFINED;

    protected JTextArea text = null;

    public abstract int getNumberOfLines();
    public abstract int getWildMultiplier();
    public abstract boolean getReTriggersAllowed();
    public abstract Reel getReel1();
    public abstract Reel getReel2();
    public abstract Reel getReel3();
    public abstract Reel getReel4();
    public abstract Reel getReel5();
    public abstract ReelSymbol getWild();
    public abstract ReelSymbol getScatter();
    public abstract String getSlotName();
    public abstract int getNumberOfFreeSpins();
    public abstract void setNumberOfLines(int n); //Used for over-ruling when analyzing only.
    public abstract int getNumberOfScattersToStartFeature();
    public abstract int getFreeSpinMultiplier();


    private long startTime=System.currentTimeMillis();
    private int maxWin=0;
    private long iterations=0;
    private long addedWins=0;
    private long totalPay=0;
    private int freeSpinsLeft=0;
    private long sumOfWins=0;
    private long sumOfWinsSquared=0;
    private int numberOfFreeSpinFeatureStarts=0;
    private long totalWinOfFreeSpins=0;
    private int specifikWinOfFreeSpin=0;
    private int maxFeatureWin=0;
    private long iterationsBetweenLog=1000000;
    private boolean isFeatureMode=false;
    private int numberOfBets=0;
    private long maximumBankroll=0;
    private long numberOfSpinsAtMaximumBankroll=0;
    private long lastestBreakEvenOrBetter =0;

    public int getRunmode() {
        return runmode;
    }

    public void setRunmode(int runmode) {
        this.runmode = runmode;
    }

    //Find the excact payout%
    public void analyze() {

      //  text.append("************ MG 5 reel slot analyzer ************\n");
        text.append("Analyzing "+this.getSlotName()+" , iterating through all combinations to calculate payout%.\n");
        text.append("It takes 2-5 minutes to analyze depending on the speed of your computer.\n");
        text.append("\n");
        text.append("Closing this window will stop the process.");
        text.append("\n");
        text.append("Analyzing, please wait: ");

        //this.setNumberOfLines(1); // will not change the payout%, will just make the analysis go faster

        //SlotUtil.printSymbols(this);
        // System.out.println("---------------------------------------------");
        // SlotUtil.printReels(this);
        // SlotUtil.printInfo(this);



        int numbeofFeatureStarts=0;
        for (int reel5Position=0;reel5Position<getReel5().getSymbols().length;reel5Position++){
            text.append("*");
            for (int reel4Position=0;reel4Position<getReel4().getSymbols().length;reel4Position++){
                for (int reel3Position=0;reel3Position<getReel3().getSymbols().length;reel3Position++){
                    for (int reel2Position=0;reel2Position<getReel2().getSymbols().length;reel2Position++){
                        for (int reel1Position=0;reel1Position<getReel1().getSymbols().length;reel1Position++) {
                            iterations++;
                            totalPay += this.getNumberOfLines();
                            int[] reels= new  int[]{reel1Position,reel2Position,reel3Position,reel4Position,reel5Position};
                            SpinResult spin = new SpinResult(reels,this);
                                  // spin.print();


                            int scatters= SlotUtil.countScatters(spin);

                            if(scatters >=this.getNumberOfScattersToStartFeature()){
                                numbeofFeatureStarts++;
                            }

                            int addLineWins=0;
                            int[] lineWins=SlotUtil.getWins(spin,this);


                            for (int i=0;i<lineWins.length;i++){
                                addLineWins+=lineWins[i];
                            }

                            int scatterWin=this.getScatter().getPays()[Math.max(scatters-1,0)]*this.getNumberOfLines();
                            int totalWin=addLineWins+scatterWin;
                            addedWins+=totalWin;
                        }
                    }
                }
            }
        }

        text.append("\n");
        double basePayback=(double) addedWins/(double) totalPay;
        double averageNumberOfFreeSpinsEachFeatureStart=0d;
        double f = (double)numbeofFeatureStarts/(double) iterations;
        if(this.getReTriggersAllowed()){
            if (f*this.getNumberOfFreeSpins()>=1){
                text.append("Payout% is infinite. Freespin mode has positive probability for" +
                        " going into an infinite loop.\n" +
                        "The is due to the following parameters:\n");
                text.append("1. Number of freespins each feature\n");
                text.append("2. Probability for getting a retrigger\n");
                text.append("\n");
                text.append("Probability for getting a feature each spin:"+f+"~"+SlotUtil.double2Faction(f)+"\n");

                return;
            }

            averageNumberOfFreeSpinsEachFeatureStart= (double) this.getNumberOfFreeSpins()*1/(1-f*this.getNumberOfFreeSpins());
        }
        else{
            averageNumberOfFreeSpinsEachFeatureStart=this.getNumberOfFreeSpins();
        }

        double payExcact= basePayback*(1+this.getFreeSpinMultiplier()*f*averageNumberOfFreeSpinsEachFeatureStart);
        text.append("************** Analysis complete *************\n");
        printTime(text);
        text.append("Number of iterations:"+iterations+"\n");
        text.append("Total cost:"+totalPay+"\n");
        text.append("Total added wins:"+addedWins+"\n");
        text.append("Number of feature starts:"+numbeofFeatureStarts+"\n");
        text.append("Base payback(no free spins):"+basePayback+"\n");
        text.append("Probability for getting a feature each spin:"+f+"~"+SlotUtil.double2Faction(f)+"\n");
        text.append("Average number of spins each feature with retriggers (calculated):"+averageNumberOfFreeSpinsEachFeatureStart+"\n");
        text.append("Average number of win each feature(in bet size):"+this.getFreeSpinMultiplier()*basePayback*averageNumberOfFreeSpinsEachFeatureStart+"\n");
        text.append("Total payout (excact!)= "+ payExcact+"~ "+SlotUtil.double2Percent(payExcact)+"\n");
    }


    //This is the core of the simulation.
    public void simulate(){

        text.append(this.getNumberOfLines()+"-line " +this.getSlotName()+" simulation, random spins\n");
        text.append("\n");
        text.append("Closing this window will stop the process.\n");
        text.append("The simulation will log a spin whenever the payout of that spin exceeds a previous one.\n");
        text.append("The current payout% will be logged every "+iterationsBetweenLog+" spin.(About every 15 seconds)\n");

        System.out.println();
        while (true) {

            iterations++;
            int  reel1Position=(int) (Math.random()*getReel1().getSymbols().length);
            int  reel2Position=(int) (Math.random()*getReel2().getSymbols().length);
            int  reel3Position=(int) (Math.random()*getReel3().getSymbols().length);
            int  reel4Position=(int) (Math.random()*getReel4().getSymbols().length);
            int  reel5Position=(int) (Math.random()*getReel5().getSymbols().length);

            int[] reels= new  int[]{reel1Position,reel2Position,reel3Position,reel4Position,reel5Position};

            int multiplier=1;
            boolean freeSpinsEnded=false;

            if(freeSpinsLeft>0){
                isFeatureMode=true;
                freeSpinsLeft--;
                multiplier=this.getFreeSpinMultiplier();
                if (freeSpinsLeft==0){
                    freeSpinsEnded=true;
                }
            }
            else{
                numberOfBets++;
                totalPay+=this.getNumberOfLines();
            }
            SpinResult spin = new SpinResult(reels,this);

            int scatters= SlotUtil.countScatters(spin);

            int addLineWins=0;
            int[] lineWins=SlotUtil.getWins(spin,this);

            for (int i=0;i<lineWins.length;i++){
                addLineWins+=lineWins[i];
            }

            int scatterWin=this.getScatter().getPays()[Math.max(scatters-1,0)]*this.getNumberOfLines();
            int totalWin=(addLineWins+scatterWin)*multiplier;




            addedWins+=totalWin;

            if (!isFeatureMode){
                sumOfWins+=totalWin;
                sumOfWinsSquared+=totalWin*totalWin;
            }



            if (scatters>=this.getNumberOfScattersToStartFeature()){ // Simulate free spins
                if (this.getReTriggersAllowed()){ //always add free spins
                    freeSpinsLeft+=this.getNumberOfFreeSpins();
                    freeSpinsEnded=false;
                }
                else { //Only add if we are not in free spin mode
                    if (!isFeatureMode){
                        freeSpinsLeft+=this.getNumberOfFreeSpins();
                        freeSpinsEnded=false;
                    }


                }
            }

            if(isFeatureMode){//We are in feature mode
                specifikWinOfFreeSpin+=totalWin;
            }

            if (freeSpinsEnded){
                isFeatureMode=false;
                numberOfFreeSpinFeatureStarts++;
                totalWinOfFreeSpins+=specifikWinOfFreeSpin;
                if (specifikWinOfFreeSpin>maxFeatureWin){
                    sumOfWins+=specifikWinOfFreeSpin;
                    sumOfWinsSquared+=specifikWinOfFreeSpin*specifikWinOfFreeSpin;
                    maxFeatureWin=specifikWinOfFreeSpin;
                }
                if (specifikWinOfFreeSpin> 18000){
                    System.out.println("CAP:"+specifikWinOfFreeSpin);

                }
                specifikWinOfFreeSpin=0; // reset variable
            }

            double currentPayback=(double) addedWins/(double) totalPay;
            double avgFeatureWin =(double) totalWinOfFreeSpins/(double) numberOfFreeSpinFeatureStarts;
            double avgFeatureWinInBets=avgFeatureWin/(double) this.getNumberOfLines();

            if (addedWins>=totalPay){
                this.lastestBreakEvenOrBetter=iterations;
            }

            if (addedWins-totalPay>=maximumBankroll){
                this.maximumBankroll=addedWins-totalPay;
                numberOfSpinsAtMaximumBankroll=iterations;
            }


            if (totalWin>maxWin){
                maxWin=totalWin;
                text.append("New maximum win\n");
                text.append("\n");
                text.append(spin.toString());
                text.append("\n");
                text.append("Total win:"+totalWin+"\n");
                text.append("Multiplier:"+multiplier+"\n");
                text.append("Freespins left:"+freeSpinsLeft+"\n");
                text.append("Iterations:"+iterations+"\n");
                text.append("Total cost:"+totalPay+"\n");
                text.append("Added wins:"+addedWins+"\n");
                text.append("Last break-even or better (#spins):"+lastestBreakEvenOrBetter+"\n");
                text.append("Maximum bankroll (units):"+maximumBankroll+" after "+numberOfSpinsAtMaximumBankroll+" spins"+"\n");
                text.append("Payout%:"+currentPayback+"~ "+SlotUtil.double2Percent(currentPayback)+"\n");
                text.append("---------------------------------------------------\n");
            }

            if (iterations % iterationsBetweenLog == 0) {

                printTime(text);
                text.append("Iterations:"+iterations+"\n");
                text.append("Number of bets:"+numberOfBets+"\n");
                text.append("Total cost:"+totalPay+"\n");
                text.append("Added wins:"+addedWins+"\n");
                text.append("Max feature win:"+maxFeatureWin+"\n");
                text.append("Last break-even or better (#spins):"+lastestBreakEvenOrBetter+"\n");
                text.append("Maximum bankroll (units):"+maximumBankroll+" after "+numberOfSpinsAtMaximumBankroll+" spins"+"\n");
                text.append("Total number of feature starts:"+numberOfFreeSpinFeatureStarts+"\n");
                text.append("Average feature win(in bet size):"+avgFeatureWinInBets+"\n");
                text.append("Payout%:"+currentPayback+"~ "+SlotUtil.double2Percent(currentPayback)+"\n");
                text.append("Variance:"+( ((double)sumOfWinsSquared/(double) numberOfBets) - ((double) sumOfWins/(double) numberOfBets)*((double) sumOfWins/(double) numberOfBets))+"\n" );
                text.append("---------------------------------------------------\n");
            }
        }
    }


    public void findMaxWinCombination() {
        text.append("************ MG 5 reel slot analyzer ************\n");
        text.append("Finding maximum win combination for "+this.getNumberOfLines()+"-line "+this.getSlotName()+"\n");
        text.append("---------------------------------------------\n");


       // SlotUtil.printSymbols(this);
       // SlotUtil.printReels(this);
       // SlotUtil.printInfo(this);



        for (int reel5Position=0;reel5Position<getReel5().getSymbols().length;reel5Position++){
            for (int reel4Position=0;reel4Position<getReel4().getSymbols().length;reel4Position++){
                for (int reel3Position=0;reel3Position<getReel3().getSymbols().length;reel3Position++){
                    for (int reel2Position=0;reel2Position<getReel2().getSymbols().length;reel2Position++){
                        for (int reel1Position=0;reel1Position<getReel1().getSymbols().length;reel1Position++) {
                            iterations++;
                            totalPay += this.getNumberOfLines();
                            int[] reels= new  int[]{reel1Position,reel2Position,reel3Position,reel4Position,reel5Position};
                            SpinResult spin = new SpinResult(reels,this);

                            int scatters= SlotUtil.countScatters(spin);

                            int addLineWins=0;
                            int[] lineWins=SlotUtil.getWins(spin,this);


                            for (int i=0;i<lineWins.length;i++){
                                addLineWins+=lineWins[i];
                            }


                            int scatterWin=this.getScatter().getPays()[Math.max(scatters-1,0)]*this.getNumberOfLines();
                            int totalWin=addLineWins+scatterWin;

                            if (totalWin>maxWin){
                                maxWin=totalWin;
                                printTime(text);
                                text.append("New maximum win:\n");
                                text.append(spin.toString());
                                text.append("Total win :"+totalWin+"\n");
                                text.append("Scatter win:"+scatterWin+"\n");

                                for (int i=0;i<lineWins.length;i++){
                                text.append("Line "+(i+1)+":"+lineWins[i]+"\n");
                                }
                                text.append("----------------------------------------\n");
                            }
                        }
                    }
                }
            }
        }
       text.append("************ Iteration finished ************\n");

    }



//This is the core of the simulation.
    public void simulateLifeTime(){
        System.out.println("************ MG 5 reel slot simulator ************");
        System.out.println(this.getNumberOfLines()+"-line " +this.getSlotName()+" lifetime simulation, random spins");


        while (true) {

            maxWin=0;
            iterations=0;
            addedWins=0;
            totalPay=0;
            freeSpinsLeft=0;
            sumOfWins=0;
            sumOfWinsSquared=0;
            numberOfFreeSpinFeatureStarts=0;
            totalWinOfFreeSpins=0;
            specifikWinOfFreeSpin=0;
            maxFeatureWin=0;
            isFeatureMode=false;
            numberOfBets=0;
            maximumBankroll=0;
            numberOfSpinsAtMaximumBankroll=0;
            lastestBreakEvenOrBetter =0;



            for (int k=0;k<1000000;k++){

                //*

                iterations++;
                int  reel1Position=(int) (Math.random()*getReel1().getSymbols().length);
                int  reel2Position=(int) (Math.random()*getReel2().getSymbols().length);
                int  reel3Position=(int) (Math.random()*getReel3().getSymbols().length);
                int  reel4Position=(int) (Math.random()*getReel4().getSymbols().length);
                int  reel5Position=(int) (Math.random()*getReel5().getSymbols().length);

                int[] reels= new  int[]{reel1Position,reel2Position,reel3Position,reel4Position,reel5Position};

                int multiplier=1;
                boolean freeSpinsEnded=false;

                if(freeSpinsLeft>0){
                    isFeatureMode=true;
                    freeSpinsLeft--;
                    multiplier=this.getFreeSpinMultiplier();
                    if (freeSpinsLeft==0){
                        freeSpinsEnded=true;
                    }
                }
                else{
                    numberOfBets++;
                    totalPay+=this.getNumberOfLines();
                }
                SpinResult spin = new SpinResult(reels,this);

                int scatters= SlotUtil.countScatters(spin);

                int addLineWins=0;
                int[] lineWins=SlotUtil.getWins(spin,this);

                for (int i=0;i<lineWins.length;i++){
                    addLineWins+=lineWins[i];
                }

                int scatterWin=this.getScatter().getPays()[Math.max(scatters-1,0)]*this.getNumberOfLines();
                int totalWin=(addLineWins+scatterWin)*multiplier;

                addedWins+=totalWin;

                if (!isFeatureMode){
                    sumOfWins+=totalWin;
                    sumOfWinsSquared+=totalWin*totalWin;
                }



                if (scatters>=this.getNumberOfScattersToStartFeature()){ // Simulate free spins
                    if (this.getReTriggersAllowed()){ //always add free spins
                        freeSpinsLeft+=this.getNumberOfFreeSpins();
                        freeSpinsEnded=false;
                    }
                    else { //Only add if we are not in free spin mode
                        if (!isFeatureMode){
                            freeSpinsLeft+=this.getNumberOfFreeSpins();
                            freeSpinsEnded=false;
                        }


                    }
                }

                if(isFeatureMode){//We are in feature mode
                    specifikWinOfFreeSpin+=totalWin;
                }

                if (freeSpinsEnded){
                    isFeatureMode=false;
                    numberOfFreeSpinFeatureStarts++;
                    totalWinOfFreeSpins+=specifikWinOfFreeSpin;
                    if (specifikWinOfFreeSpin>maxFeatureWin){
                        sumOfWins+=specifikWinOfFreeSpin;
                        sumOfWinsSquared+=specifikWinOfFreeSpin*specifikWinOfFreeSpin;
                        maxFeatureWin=specifikWinOfFreeSpin;
                    }

                    specifikWinOfFreeSpin=0; // reset variable
                }



                if (addedWins>=totalPay){
                    this.lastestBreakEvenOrBetter=iterations;
                }

                if (addedWins-totalPay>=maximumBankroll){
                    this.maximumBankroll=addedWins-totalPay;
                    numberOfSpinsAtMaximumBankroll=iterations;
                }




            }
            System.out.println(lastestBreakEvenOrBetter+","+maximumBankroll+","+numberOfSpinsAtMaximumBankroll+","+(addedWins-totalPay)+","+((double) addedWins/(double) totalPay));
        }

        //***

    }


    public void run(){
    if (runmode==RUNMODE_ANALYSE)
        analyze();
    else if (runmode==RUNMODE_FINDMAXIMUMWINCOMBINATION)
        findMaxWinCombination();
    else if (runmode==RUNMODE_SIMULATE)
        simulate();
    else
        throw new IllegalArgumentException("Unknown mode:"+runmode);
    }



    private void printTime(JTextArea text){
        long timeRunning=System.currentTimeMillis()-startTime;
        text.append("Seconds running:"+((float) (timeRunning/100L)/10));
        text.append("\n");
    }



}
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
Comment Utility

Shawn,

No one can give you a complete translation based on the code due to missing class references, but I can give you some tips. Hopefully it will help.

Russell

1.) public class Thunderstruck extends MG5ReelSlot {

would translate to:

type
  Thunderstruck  = class(MG5ReelSlot)
  private
   //
  protected
   //
  public
   //
  end;

This of course requires the definition for MG5ReelSlot to be defined first.


2.) The private defines are simple, but you will note that many of the values are pre-seeded. That means you will need to perform this in the constructor of your component, eg:

  //Data start.
    private  String slotName="Thunderstruck";
    private  int numberOfLines=9;
    private  int wildMultiplier= 2;
    private  int numberOfFreeSpins=15;
    private  int freeSpinMultiplier=3;
    private  int numberOfScattersToStartFeature=3;
    private  boolean reTriggersAllowed=true;

 private
  // Private declarations
  slotName:         String;
  numberOfLines: Integer;
  ram:           ReelSymbol;
  etc...

to intialize these, use the class construtor

constructor Thunderstruck.Create;
begin
 
  inherited Create;

  slotName="Thunderstruck";
  numberOfLines=9;
  etc...

end;

3.) The object property variables, eg:

ReelSymbol ram = new ReelSymbol("R",Boolean.FALSE,Boolean.TRUE,Boolean.FALSE,new int[]{0,2,5,20,500});

would require the class definition for ReelSymbol first, then would be created using:

ram:=ReelSymbol.Create("R", False, True, False, [0,2,5,20,500]);
 
4.) There are also some object arrays, eg:
    private  ReelSymbol[] reel1Symbols=new ReelSymbol[]{jack,queen,castle,staff,hammer,castle,jack,ten,horn,ace,jack,queen,nine,jack,queen,lightning,horn,thor,staff,nine,horn,hammer,staff,king,ten,jack,horn,lightning,ace,ram};

which could be defined as:

reel1Symbols:  Array [0..29] of ReelSymbol;

and then filled during the constructor.

ram:=ReelSymbol.Create("R", False, True, False, [0,2,5,20,500]);
king:=ReelSymbol.Create(...);
etc...

reel1Symbols[0]:=jack;
reel1Symbols[1]:=queen;
reel1Symbols[2]:=castle;
etc...

5.) The construtor in Java looks like:

public Thunderstruck(){
        reel1.setSymbols(reel1Symbols);
        reel2.setSymbols(reel2Symbols);
        reel3.setSymbols(reel3Symbols);
        reel4.setSymbols(reel4Symbols);
        reel5.setSymbols(reel5Symbols);
    }

and in delphi would be


constructor Thunderstruck.Create;
begin
 
  inherited Create;

  // Initialize all the variables and arrays here

  reel1.setSymbols(reel1Symbols);
  reel2.setSymbols(reel2Symbols);
  reel3.setSymbols(reel3Symbols);
  reel4.setSymbols(reel4Symbols);
  reel5.setSymbols(reel5Symbols);

end;

Also remember to .Free all these objects in the class destructor.

destructor Thunderstruck.Destroy;
begin

  try
    reel1.Free;
    reel2.Free;
    etc...
  finally  
    perform inherited;
  end;

end;

6.) The public defines are pretty easy:
 public int getNumberOfFreeSpins(){
        return numberOfFreeSpins;
    }

becomes

 public
   constructor
   etc...
   property getNumberOfFreeSpins: Integer read numberOfFreeSpins;
   etc...


7.) When doing conversions, I prefer to start with the lowest level building block (classes), and convert those first. These are the classes that have no dependencies or inheritence to other classes. Once those are done, then work on the remaining classes. Going only by what you listed, I personally would start in the following order.

- ReelSymbol
- MG5ReelSlot
- Thunderstruck


0
 

Author Comment

by:aztec
Comment Utility
Thank you VERY much Rllibby! I'm going to get to work on this.

Is it okay if I leave this question open for just a *wee* bit longer in case I just have one more question or two for you?

Thanks
   Shawn

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
No problem

Russell
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
> I just don't have the time here right now to do it myself . . .

sorry again, same issue by me

meikl ;-)
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
Yep, pretty much a no-no... you might take a look at other sites that specialize in coding projects.

Russell
0
 

Author Comment

by:aztec
Comment Utility
Sorry everybody!  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now