Skip to content

Commit 0a387ac

Browse files
committed
bugs fixed
1 parent 24a9dfb commit 0a387ac

9 files changed

Lines changed: 23 additions & 54 deletions

File tree

JCoreWars.iml

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/fabaindaiz/jcorewars/Juno.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ public static void main(String[] args) {
1515
mars.setMenuDisplay();
1616

1717
Vector<String> wArgs = new Vector<>();
18-
wArgs.add("C:/informatica/Core Wars/warriors/Validate.red");
19-
//wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
20-
//wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
21-
//wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
18+
wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
19+
wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
20+
wArgs.add("C:/informatica/Core Wars/warriors/imp.red");
2221
marsCore.setWarriors(wArgs);
2322

2423
aplicationCore.application_start();

src/fabaindaiz/jcorewars/display/DisplayManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public DisplayManager(AplicationCore core) {
3535

3636
public void setMenuDisplay() {
3737
menuDisplay = new MenuDisplay(frame);
38+
39+
frame.setVisible(true);
40+
frame.repaint();
3841
}
3942

4043
private JPanel getCorePanel() {
4144
JPanel panel = new JPanel(new BorderLayout());
42-
4345
appCore.application_display(panel);
4446

4547
return panel;

src/fabaindaiz/jcorewars/jMARS.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public class jMARS
4444
* Starting function for the application. It sets up a frame and adds the applet to it.
4545
* @param args - array of command line arguments
4646
*/
47-
public static void main(String[] args)
48-
{
47+
public static void main(String[] args) {
4948
Vector<String> wArgs = new Vector<>();
5049
int numWarriors = 0;
5150

51+
args = new String[]{"C:/informatica/Core Wars/warriors/Validate.red"};
52+
5253
if (args.length == 0)
5354
{
5455
System.out.println("usage: jMARS [options] warrior1.red [warrior2.red ...]");

src/fabaindaiz/jcorewars/marsVM/MarsCore.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public void init() {
7272
}
7373
}
7474
MARS = new MarsVM(coreSize, maxProc);
75-
MARS.warriorManager.loadWarriors(warriors, minWarriorDistance);
76-
75+
MARS.warriorManager.loadWarriors(warriors, minWarriorDistance, maxWarriorLength);
7776
application.application_update();
7877

7978
runWarriors = numWarriors;
@@ -122,10 +121,9 @@ public void run() {
122121
startTime = new Date();
123122

124123
MARS.reset();
125-
runWarriors = numWarriors;
126-
MARS.warriorManager.loadWarriors(warriors, minWarriorDistance);
127-
124+
MARS.warriorManager.loadWarriors(warriors, minWarriorDistance, maxWarriorLength);
128125
application.application_update();
126+
runWarriors = numWarriors;
129127

130128
cycleNum = 0;
131129
}

src/fabaindaiz/jcorewars/marsVM/StepReport.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ public class StepReport {
77

88
public Memory[] core;
99
protected WarriorExecutor warrior;
10-
protected int numProc;
1110

1211
protected int[] readAddr;
13-
protected int[] indirReadAddr;
1412
protected int[] writeAddr;
1513
protected int[] decAddr;
1614
protected int[] incAddr;
1715

1816
protected int numRead;
19-
protected int numIndirRead;
2017
protected int numWrite;
2118
protected int numDec;
2219
protected int numInc;
2320

21+
protected int numProc;
2422
protected int execAddr;
23+
2524
protected boolean pDie;
2625
protected boolean wDeath;
2726

2827
protected final static int MAX_READS = 4;
2928
protected final static int MAX_WRITES = 4;
30-
protected final static int MAX_INDIR_READS = 4;
3129
protected final static int MAX_DECS = 5;
3230
protected final static int MAX_INCS = 5;
3331

@@ -39,13 +37,11 @@ public StepReport(Memory[] core, WarriorExecutor warrior) {
3937
this.warrior = warrior;
4038

4139
readAddr = new int[MAX_READS];
42-
indirReadAddr = new int[MAX_INDIR_READS];
4340
writeAddr = new int[MAX_WRITES];
4441
decAddr = new int[MAX_DECS];
4542
incAddr = new int[MAX_INCS];
4643

4744
numRead = 0;
48-
numIndirRead = 0;
4945
numWrite = 0;
5046
numDec = 0;
5147
numInc = 0;
@@ -76,15 +72,6 @@ public void read(int addr) {
7672
numRead++;
7773
}
7874

79-
/**
80-
* Set a location read from indirection
81-
* @param addr - address of location read
82-
*/
83-
public void indirRead(int addr) {
84-
indirReadAddr[numIndirRead] = addr;
85-
numIndirRead++;
86-
}
87-
8875
/**
8976
* Set a location that was written to
9077
* @param addr - address written to
@@ -160,16 +147,6 @@ public int[] addrRead() {
160147
return value;
161148
}
162149

163-
/**
164-
* Get the addresses read through indirection
165-
* @return int[] - array of addresses
166-
*/
167-
public int[] addrIndirRead() {
168-
int[] value = new int[numIndirRead];
169-
if (numIndirRead >= 0) System.arraycopy(indirReadAddr, 0, value, 0, numIndirRead);
170-
return value;
171-
}
172-
173150
/**
174151
* Get the addresses written to
175152
* @return int[] - array of addresses

src/fabaindaiz/jcorewars/steplistener/CoreList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void loadCore(Memory[] core) {
4444
int i = 0;
4545

4646
for (Memory mem: core) {
47-
instr.addElement(String.format("%04d", i) + mem.toString());
47+
instr.addElement(String.format("%06d", i) + mem.toString());
4848
instrColor.add(Color.white);
4949
i++;
5050
}

src/fabaindaiz/jcorewars/steplistener/ProcList.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ public void loadProc(Vector<WarriorProcess<Integer>> list, Vector<Color> color)
5353
proc1.removeAll();
5454
proc1.add(procList.get(0));
5555

56-
//proc2.removeAll();
57-
//proc2.add(procList.get(1));
56+
if (procList.size() >= 2) {
57+
proc2.removeAll();
58+
proc2.add(procList.get(1));
59+
}
60+
5861
}
5962

6063
@Override

src/fabaindaiz/jcorewars/warrior/WarriorManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public WarriorManager(MarsVM marsVM) {
2222
this.coreSize = marsVM.coreSize;
2323
}
2424

25-
public void loadWarriors(WarriorLoader[] warriors, int minWarriorDistance) {
25+
public void loadWarriors(WarriorLoader[] warriors, int minWarriorDistance, int maxWarriorLength) {
2626

2727
loadWarrior(warriors[0], 0, 0);
2828
int[] location = new int[warriors.length];
@@ -37,15 +37,15 @@ public void loadWarriors(WarriorLoader[] warriors, int minWarriorDistance) {
3737
validSpot = false;
3838
}
3939
for (int k : location) {
40-
if (r < (minWarriorDistance + k) && r > (minWarriorDistance + k)) {
40+
if (r < (k + maxWarriorLength + minWarriorDistance) && r > (k - minWarriorDistance)) {
4141
validSpot = false;
4242
break;
4343
}
4444
}
4545
} while (!validSpot);
4646

4747
loadWarrior(warriors[i], r, i);
48-
//location[i] = r;
48+
location[i] = r;
4949
}
5050
}
5151

0 commit comments

Comments
 (0)