Skip to content

Commit

Permalink
Added Evolution Randomization. Fixed rare Move Randomization bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
anmart committed Jul 19, 2016
1 parent e1ca2a2 commit c77d01b
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/randomizer/Pokemon_TCG/MonCardData.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class MonCardData {

public static int moveSize = 19;

//non data variables
boolean highestStage = false;

public MonCardData(byte[] rom, int startIndex){
int c = startIndex;

Expand Down Expand Up @@ -63,9 +66,7 @@ public MonCardData(byte[] rom, int startIndex){
weight = new Word(rom,c,true); c+=2;
description = new Word(rom,c,true); c+=2;
unknownByte2 = rom[c++];



}

public void writeToRom(byte[] rom, int startIndex){
Expand Down
105 changes: 99 additions & 6 deletions src/randomizer/Pokemon_TCG/PTCG1_Randomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,34 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){
ArrayList<Move> moveList = new ArrayList<Move>();
ArrayList<MonCardData> monList = new ArrayList<MonCardData>();



for(int i = 0; i < monAmount; i++){
moveList.add(mons[i].move1);
if(mons[i].move2.isExists())
moveList.add(mons[i].move2);
monList.add(mons[i]);
}


Collections.shuffle(moveList, rand);
Collections.shuffle(monList, rand);

for(int i = moveList.size()-1; i >= 0; i--){

if(moveList.get(i).isPokePower()){
moveList.add(moveList.remove(i++));//move it to the back of the list
moveList.add(moveList.remove(i));//move it to the back of the list
}
}


for(int i = 0; i< monList.size(); i++){
MonCardData curr = monList.get(i);
int stage = 0xFF & curr.stage;
// System.out.println(stage);
boolean foundPokePower = false;



for(int j = moveList.size()-1; j >= 0; j--){
Move currMove = moveList.get(j);

Expand Down Expand Up @@ -341,14 +348,12 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){


}

if(foundPokePower){
//if after all that we got two moves (move + pokepower), remove self from list
monList.remove(i--);

}
}

//Alright so where are we now?
//we have a list of mons with only one move, and a list of moves that still don't have a home
for(int i = 0; i< monList.size(); i++){
Expand All @@ -366,7 +371,6 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){


}

for(int i = 0; i < monList.size(); i++){
monList.get(i).move2 = blankMove;

Expand Down Expand Up @@ -523,7 +527,96 @@ public void setInstantText(){
rom[ldaLocation] = 0x00;
}


public ArrayList<MonCardData> indicesOfPokemonFromNamePointer(Word namePointer, ArrayList<MonCardData> mons){
ArrayList<MonCardData> ret = new ArrayList<MonCardData>();
for(int i = 0; i < mons.size(); i++){

if(mons.get(i).name.equals(namePointer))
ret.add(mons.get(i));
}
return ret;
}
public void randomizeEvolutions(int maxSize, boolean monoType){

ArrayList<MonCardData> randMons = new ArrayList<MonCardData>(Arrays.asList(mons));
Collections.shuffle(randMons, rand);
ArrayList<MonCardData> tempInd; // used a few times for a short amount of time
ArrayList<MonCardData> usedMons = new ArrayList<MonCardData>();

while(randMons.size() > 0){

MonCardData currMon = randMons.get(0);

tempInd = indicesOfPokemonFromNamePointer(currMon.name, randMons);
for(MonCardData mc : tempInd){
mc.stage = 0x0; // basic
mc.preEvoName = new Word(); // no pre evo (default constructor returns 0000 word)
usedMons.add(mc);
randMons.remove(mc);
}



int maxBound = maxSize;
if(randMons.size() < maxBound)
maxBound = randMons.size();


//this lets us skip randomization and the for loop if we have no pokems left
//we go straight to setting this mon to highest evo
int rnum;
if(maxBound < 1)
rnum = 0;
else
rnum = rand.nextInt(maxBound);


for(int i = rnum; i > 0; i--){

boolean monFound = false;
int newMonNum;

for(newMonNum = 0; newMonNum < randMons.size(); newMonNum++){
if(!monoType || randMons.get(newMonNum).type == currMon.type){
monFound = true;
break;
}
}

if(!monFound)
break;

MonCardData newMon = randMons.get(newMonNum);

if(currMon.stage > 0)
newMon.stage = 0x02;
else
newMon.stage = 0x01;



tempInd = indicesOfPokemonFromNamePointer(newMon.name, randMons);
for(MonCardData mc : tempInd){
mc.stage = newMon.stage;
mc.preEvoName = currMon.name;
usedMons.add(mc);
randMons.remove(mc);
}


currMon = newMon;
}

tempInd = indicesOfPokemonFromNamePointer(currMon.name, randMons);
for(MonCardData mc : tempInd){
mc.highestStage = true;
}


}


}

public void setMoveTypeToMonType() {
for( MonCardData mon : mons){
Expand Down
2 changes: 1 addition & 1 deletion src/randomizer/Pokemon_TCG/PTCG1_UI.form
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
<Component class="javax.swing.JCheckBox" name="setMaxEvolutionChain">
<Properties>
<Property name="text" type="java.lang.String" value="Set Max Evolution Size:"/>
<Property name="toolTipText" type="java.lang.String" value="If selected, sets evolution chanes between 1 and value in the textbox"/>
<Property name="toolTipText" type="java.lang.String" value="If selected, sets evolution chains between 1 and value in the textbox"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="maxEvolutionChainValue">
Expand Down
20 changes: 17 additions & 3 deletions src/randomizer/Pokemon_TCG/PTCG1_UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
keepEvolutionsMonotype.setToolTipText("Generated after types are modified.");

setMaxEvolutionChain.setText("Set Max Evolution Size:");
setMaxEvolutionChain.setToolTipText("If selected, sets evolution chanes between 1 and value in the textbox");
setMaxEvolutionChain.setToolTipText("If selected, sets evolution chains between 1 and value in the textbox");

maxEvolutionChainValue.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
maxEvolutionChainValue.setText("3");
Expand Down Expand Up @@ -615,6 +615,19 @@ else if(movesCostColorless.isSelected()){
rando.randomizeTypes();
}



// Has to go after type randomization, before HP Fix though
if(randomizeEvolutions.isSelected()){
String maxSize = maxEvolutionChainValue.getText();
if(!maxSize.matches("[0-9]+"))
maxSize = "999";

rando.randomizeEvolutions(Integer.parseInt(maxSize), keepEvolutionsMonotype.isSelected());
}


//goes after evolution randomization
if(randomizeMovesInStages.isSelected()){
rando.randomizeMoves(true, false);
}
Expand All @@ -623,11 +636,12 @@ else if(randomizeMovesFully.isSelected()){
}



// THIS MUST GO AFTER TYPE AND MOVE RANDOMIZATION
if(movesCostSameAsType.isSelected()){
rando.setMoveTypeToMonType();
}

}

fc.setSelectedFile(new File("TCG Randomized.gbc"));
fc.showOpenDialog(PTCG1_UI.this);
Expand Down
9 changes: 9 additions & 0 deletions src/randomizer/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@ public byte getHigh(){
public String toString(){
return "" + (0xFFFF & ((0xFF00 & high << 8) + (low & 0xFF)));
}
public boolean equals(Object other){
if (other instanceof Word){
Word o = (Word) other;
return o.high == high && o.low == low;

}
return false;

}
}

0 comments on commit c77d01b

Please sign in to comment.