Skip to content

Commit

Permalink
added comment instruction "/" , added check to make sure Y logic chec…
Browse files Browse the repository at this point in the history
…k is within 0-255
  • Loading branch information
aspwil committed Nov 18, 2020
1 parent e052460 commit 7cf2ae6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/ndballsim/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public static Instr[] parse(String file) {
String line = scanner.nextLine().replaceAll(" ", "").replaceAll("\t", "");

try {
//this allows us to tell an error if there is no instructions on a line
//this allows us to skip a line if there is nothing in a line
line.charAt(0);
} catch (StringIndexOutOfBoundsException e) {
error(lineNum, "Line empty");
//skip the parcing of this line
continue;
}
//parse the position identifier
switch (line.charAt(0)) {
Expand Down Expand Up @@ -121,6 +122,10 @@ public static Instr[] parse(String file) {
error(lineNum, "Invalid position statement, missing closeing }");
}
break;
//this line is a comment
case '/':
//skip this line and start with the next one
continue;
default:
//if we dont find a ( or { as the first char then the position decoration is malformed
error(lineNum, "Invalid start of new line, must be a position decloration (a,b,c...) or {a,b|c,d...}");
Expand Down Expand Up @@ -198,6 +203,10 @@ public static Instr[] parse(String file) {
} catch (NumberFormatException e) {
error(lineNum, "\"" + inputs[0] + "\" could not be converted into a number");
}
//error if the provided value is out of (0-255)
if(value < 0 || value > 255){
error(lineNum, "Y logic operation only excepts values from 0 to 255");
}
//check if the first movement instruction includes a movement
if (inputs[1].charAt(0) == '>' || inputs[1].charAt(0) == '<') {
//parse in first dimention
Expand Down
12 changes: 9 additions & 3 deletions src/ndballsim/Pos.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public Pos(int... ints) {
}
}

public Pos(Pos p) {
this.list = p.list;
this.highestDim = p.highestDim;
}

public int getLength(int dim) {
for (Vector v : list) {
if (v.dim == dim) {
Expand All @@ -90,8 +95,8 @@ public void setLength(int dim, int length) {
}
list.add(new Vector(dim, length));
}
public int getHighestDim(){

public int getHighestDim() {
return highestDim;
}

Expand All @@ -112,7 +117,7 @@ public boolean equals(Object o) {
// Compare the data members and return accordingly
//if they are not the same length they dont have the same number of defined dimentions
//they dont share highest dim, must not be be the same
if(p.highestDim != highestDim){
if (p.highestDim != highestDim) {
return false;
}
if (list.size() != p.list.size()) {
Expand All @@ -127,6 +132,7 @@ public boolean equals(Object o) {
}
return true;
}

//added to keep hash codes in order whn overrideing equals method
@Override
public int hashCode() {
Expand Down
1 change: 1 addition & 0 deletions src/ndballsim/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
break;
//Y logic case
case "Y":
//check if Y logiv operator is checking for impossible number
//if ballVal is less then info 0 we want to send the ball along dimention info 2
if (ballVal < (int) instrs[i].info[0]) {
switch ((String) instrs[i].info[1]) {
Expand Down

0 comments on commit 7cf2ae6

Please sign in to comment.