Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix learnset bug #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/Moveset.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,20 @@ public Moveset(List<Move> newMoves) {

//returns the 4 most recently learned moves for a pokemon of this level
public static Moveset defaultMoveset(Species species, int level, String dataVersion){
ArrayList<Move> distinctMoves = new ArrayList<Move>();
HashSet<Move> movesSet = new HashSet<Move>();
ArrayList<Move> moves = new ArrayList<Move>();
Learnset l = Learnset.getLearnset(species.getPokedexNum(), dataVersion);
if (l == null) {
if (l == null)
return new Moveset();
}
LevelMove[] lms = l.getLevelMoves();
for(int i = 0; i < lms.length; i++) {
Move m = lms[i].getMove();
if (!movesSet.contains(m) && lms[i].getLevel() <= level) {
movesSet.add(m);
distinctMoves.add(m);
if (!moves.contains(m) && lms[i].getLevel() <= level) {
if (moves.size() == 4)
moves.remove(0);
moves.add(m);
}
}

if (distinctMoves.size() <= 4)
return new Moveset(distinctMoves);
else {
int n = distinctMoves.size();
return new Moveset(distinctMoves.subList(n-4, n));
}

return new Moveset(moves);
}

public String toString() {
Expand Down