From 2d0aa355c1adc21820d37b6cbd4f6bf341345584 Mon Sep 17 00:00:00 2001 From: aspwil Date: Sat, 21 Nov 2020 10:35:21 -0700 Subject: [PATCH] fixed spacing issues making the doc look ugly --- src/ndballsim/Instr.java | 27 +++---- src/ndballsim/Main.java | 148 +++++++++++++++++++------------------- src/ndballsim/Parser.java | 12 ++-- 3 files changed, 95 insertions(+), 92 deletions(-) diff --git a/src/ndballsim/Instr.java b/src/ndballsim/Instr.java index 15384c8..5e414a6 100644 --- a/src/ndballsim/Instr.java +++ b/src/ndballsim/Instr.java @@ -1,39 +1,40 @@ /* * NDBall Simulator by Aspen Wilson is licensed under CC0 1.0. To view a copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0 */ - //this class defines the Instruction object, it has no real maningful data, its just to group together data together package ndballsim; import java.util.Arrays; public class Instr implements Comparable { + //pos the position of the instruction in n-dim space public Pos pos; //the name of the instruction, this will be used to indentify what the instruction does during simlation public String name; //this array of objects will be used for extra info needed to be used when running specific instructions, such as memory cells or Y logic public Object[] info; - + //the constructer - public Instr(Pos pos,String name, Object... inputs){ + public Instr(Pos pos, String name, Object... inputs) { this.pos = pos; this.name = name; - this.info = inputs; + this.info = inputs; } - - public Pos getPos(){ + + public Pos getPos() { return pos; } - + @Override - public String toString(){ - return "Instr: "+name+", "+pos+", "+Arrays.toString(info); + public String toString() { + return "Instr: " + name + ", " + pos + ", " + Arrays.toString(info); } + //this allows us to call collections.sort and sort by highest dim in an array list @Override - public int compareTo(Instr instr) { - return ((Integer)pos.getHighestDim()).compareTo(((Integer)instr.pos.getHighestDim())); + public int compareTo(Instr instr) { + return ((Integer) pos.getHighestDim()).compareTo(((Integer) instr.pos.getHighestDim())); } - -} \ No newline at end of file + +} diff --git a/src/ndballsim/Main.java b/src/ndballsim/Main.java index 2c28b30..4dd5e3c 100644 --- a/src/ndballsim/Main.java +++ b/src/ndballsim/Main.java @@ -3,10 +3,11 @@ */ package ndballsim; //this is the calss is run with the jar file, it will handle the command line input + public class Main { public static void main(String[] args) { - + boolean step = false; boolean log = false; boolean info = false; @@ -27,8 +28,8 @@ public static void main(String[] args) { if (args.length == 0) { System.out.println(help); } else { - for(int i = 0; i < args.length; i++){ - switch(args[i]){ + for (int i = 0; i < args.length; i++) { + switch (args[i]) { case "-h": case "-help": System.out.println(help); @@ -36,7 +37,7 @@ public static void main(String[] args) { case "-s": case "-step": step = true; - //no break because step also enables log + //no break because step also enables log case "-l": case "-log": log = true; @@ -44,12 +45,12 @@ public static void main(String[] args) { case "-m": case "-max": try { - max = Integer.parseInt(args[i+1]); - } catch (NumberFormatException|ArrayIndexOutOfBoundsException e) { - error("Max tag (-m -max) requires a valid number"); - } - i++; - break; + max = Integer.parseInt(args[i + 1]); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + error("Max tag (-m -max) requires a valid number"); + } + i++; + break; case "-i": case "-info": info = true; @@ -57,79 +58,80 @@ public static void main(String[] args) { case "-d": case "-docs": System.out.println("the ball starts at 0,0,0...\n" - + "\n" - + "dimensions are 5 spaces long (from 0 to 4)\n" - + "\n" - + "all instructions take up a cell in the n-dim space\n" - + "\n" - + "cells are defined with the following syntax\n" - + "\n" - + "POS INSTR EX: (0,1,...) >1\n" - + "\n" - + "position are assumed to in the 0th position for all undefined positions\n" - + "EX: (1,1,0) = (1,1)\n" - + "\n" - + "position can also be defined as a list of dim|value as this\n" - + "EX: {0,1|5,1} = (1,0,0,0,0,1)\n" - + "this is useful for defining things instead of using a lot of zeros \n" - + "\n" - + "the ball moves along dimensions according to movement instructions\n" - + "\n" - + ">n :ball moves forward on dim n\n" - + "3), if the ball's movement is the same as the cell direction then the memory cell is written to, becoming the balls value. if not the cell is read and the ball becomes the value of the memory cell. they start with a value of 0\n" - + "\n" - + "APIOFORMS:\n" - + "these instructions allows you to keep a single value apart from the balls value and change it\n" - + "a :an apioform joins the hive, increasing the have value by 1\n" - + "f :an apioform leaves the hive to polinate flowers, decreasing the value of the hive by 1\n" - + "q :the queen leaves the hive, taking all apioforms with her, hive value is now 0\n" - + "n :nector attract apioforms to or away from the hive untill its value matches the ball\n" - + "H :the hive itself, when run into the ball`s value becomes the hive value\n" - + "SPECIAL INSTR:\n" - + "E end program\n" - + "\n" - + "Check out the wiki for more info https://esolangs.org/wiki/NDBall" - + ""); - break; + + "\n" + + "dimensions are 5 spaces long (from 0 to 4)\n" + + "\n" + + "all instructions take up a cell in the n-dim space\n" + + "\n" + + "cells are defined with the following syntax\n" + + "\n" + + "POS INSTR EX: (0,1,...) >1\n" + + "\n" + + "position are assumed to in the 0th position for all undefined positions\n" + + "EX: (1,1,0) = (1,1)\n" + + "\n" + + "position can also be defined as a list of dim|value as this\n" + + "EX: {0,1|5,1} = (1,0,0,0,0,1)\n" + + "this is useful for defining things instead of using a lot of zeros \n" + + "\n" + + "the ball moves along dimensions according to movement instructions\n" + + "\n" + + ">n :ball moves forward on dim n\n" + + "3), if the ball's movement is the same as the cell direction then the memory cell is written to, becoming the balls value. if not the cell is read and the ball becomes the value of the memory cell. they start with a value of 0\n" + + "\n" + + "APIOFORMS:\n" + + "these instructions allows you to keep a single value apart from the balls value and change it\n" + + "a :an apioform joins the hive, increasing the have value by 1\n" + + "f :an apioform leaves the hive to polinate flowers, decreasing the value of the hive by 1\n" + + "q :the queen leaves the hive, taking all apioforms with her, hive value is now 0\n" + + "n :nector attract apioforms to or away from the hive untill its value matches the ball\n" + + "H :the hive itself, when run into the ball`s value becomes the hive value\n" + + "SPECIAL INSTR:\n" + + "E end program\n" + + "\n" + + "Check out the wiki for more info https://esolangs.org/wiki/NDBall" + + ""); + break; default: Simulator.run(args[i], max, log, step, info); System.exit(0); break; - + } } } System.exit(0); } + //tells user error and ends program - private static void error(String str){ - System.out.println("ERROR: "+str); + private static void error(String str) { + System.out.println("ERROR: " + str); System.exit(1); } } diff --git a/src/ndballsim/Parser.java b/src/ndballsim/Parser.java index 7f2d031..7224d5d 100644 --- a/src/ndballsim/Parser.java +++ b/src/ndballsim/Parser.java @@ -204,7 +204,7 @@ public static Instr[] parse(String file) { 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){ + 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 @@ -292,11 +292,11 @@ public static Instr[] parse(String file) { break; case 'K': try { - list.add(new Instr(pos, "K", line.charAt(1), Integer.parseInt(line.substring(2,line.length())))); - }catch (NumberFormatException e) { - error(lineNum, "\"" + line.substring(2, line.length()) + "\" could not be converted into a number"); - } - break; + list.add(new Instr(pos, "K", line.charAt(1), Integer.parseInt(line.substring(2, line.length())))); + } catch (NumberFormatException e) { + error(lineNum, "\"" + line.substring(2, line.length()) + "\" could not be converted into a number"); + } + break; case 'n': list.add(new Instr(pos, "n")); break;