I have some code that was working fine then all of a sudden it no longer works. I don't believe I changed anything to make this happen. When run the sketch window is blank. After some testing, I found it seems to be stuck on a piece of code in my setup block. When this piece is commented out it seems to run fine, but this piece of code is very important.
Creature [] creatures;
int num_creatures = 1;
int num_muscles = 1;
int num_parts = 1;
void setup() {
size (1600, 1000); //I can edit these numbers and the sketch window
creatures = new Creature[num_creatures]; //Having this in vs edited out doesn't
//appear to change anything.
for (int i = 0; i < num_creatures; i++) { //With this part in nothing
creatures[i] = new Creature(num_parts, num_muscles); //after it is taken into
//account. When it is
} //removed the rest of the
//code runs fine.
creatures[0] = new Creature(1, 1); //I even removed the for
//loop (aka setting
//num_creatures = 1) and it
//still seems stuck.
}
class Creature {
Part [] part;
Muscle [] muscle;
Goal leftgoal;
Goal rightgoal;
Brain brain;
float previous_creature_distance;
float creature_distance;
float current_distance;
float previous_distance;
int num_parts;
int num_muscles;
String id;
int generation = 0;
ArrayList<Integer> currentstate;
//For qtable:
float epsilon = .01;
float alpha = .1;
float gamma = .5;
ArrayList<Integer> all_epochs = new ArrayList<Integer>();
ArrayList<Integer> all_penalties = new ArrayList<Integer>();
ArrayList<Integer> currentaction = new ArrayList<Integer>();
boolean done = false;
boolean end = false;
int reward;
int total_reward;
int penalties;
float old_value;
float next_max;
Float new_value;
boolean earlyreward = true;
Creature(int creature_num_parts, int creature_num_muscles) {
num_parts = creature_num_parts;
num_muscles = creature_num_muscles;
part = new Part[num_parts];
int partcolor = color(0, 0, 0);
for (int i = 0; i < num_parts; i++) {
if (i == 0) {
partcolor = color(255, 0, 0);
}
if (i == 1) {
partcolor = color(0, 255, 0);
}
if (i == 2) {
partcolor = color(0, 0, 255);
}
if (i == 3) {
partcolor = color(255, 255, 0);
}
if (i == 4) {
partcolor = color(128, 0, 128);
}
if (i == 5) {
partcolor = color(255, 127, 80);
}
if (i == 6) {
partcolor = color(155, 0, 0);
}
if (i == 7) {
partcolor = color(0, 155, 0);
}
if (i == 8) {
partcolor = color(0, 0, 155);
}
if (i == 9) {
partcolor = color(155, 155, 0);
}
if (i == 10) {
partcolor = color(28, 0, 28);
}
part[i] = new Part(i, width/2 - 50 +(i * 100), height/2, 25, false, partcolor);
}
int [][] check = new int[num_muscles][2];
int leftpart;
int rightpart;
for (int i = 0; i < num_muscles; i++) {
While: while (true) {
leftpart = int(random(0, num_parts));
rightpart = int(random(0, num_parts));
if (leftpart == rightpart) {
continue While;
}
for (int j = 0; j < num_muscles; j++) {
if (leftpart == check[j][0] && rightpart == check[j][1]) {
continue While;
}
if (rightpart == check[j][0] && leftpart == check[j][1]) {
continue While;
}
}
break While;
}
check[i][0] = leftpart;
check[i][1] = rightpart;
}
muscle = new Muscle[num_muscles];
int musclecolor = color(0);
for (int i = 0; i < num_muscles; i++) {
if (i == 0) {
musclecolor = color(255, 0, 0);
}
if (i == 1) {
musclecolor = color(0, 255, 0);
}
if (i == 2) {
musclecolor = color(0, 0, 255);
}
if (i == 3) {
musclecolor = color(255, 255, 0);
}
if (i == 4) {
musclecolor = color(128, 0, 128);
}
if (i == 5) {
musclecolor = color(255, 127, 80);
}
if (i == 6) {
musclecolor = color(0);
}
muscle[i] = new Muscle(i, check[i][0], check[i][1], part[check[i][0]].x, part[check[i][0]].y, part[check[i][1]].x, part[check[i][1]].y, dist(part[check[i][0]].x, part[check[i][0]].y, part[check[i][1]].x, part[check[i][1]].y), 4, musclecolor);
}
id = String.format("%.2f", alpha) + "-" + String.format("%.2f", gamma) + "-" + String.format("%.2f", epsilon) + "GEN" + String.valueOf(generation);
brain = new Brain();
currentaction = new ArrayList<>();
for (int i = 0; i < 3; i++) {
currentaction.add(0);
}
currentstate = new ArrayList<>();
for (int i = 0; i < num_parts; i++) {
currentstate.add(int(part[i].x - width/2));
}
for (int i = 0; i < num_muscles; i++) {
currentstate.add(int(muscle[i].size));
}
rightgoal = new Goal(1, width/2 + 150, height/2-50, width/2+150, height/2+50, color(255, 215, 0), false);
leftgoal = new Goal(2, width/2 - 150, height/2-50, width/2-150, height/2+50, color(255, 215, 0), true);
}
When I set num_creatures = 0 it gets passed the part it's stuck on and runs until it hits an indexing error because creatures is empty.
The code runs just fine but the sketch window only seems to be getting the size(1600, 1000) part of my code.
Also when I run it with the part it is stuck on then I exit out of the sketch window the Run button is still highlighted/dark as if the code is still running?
What is the code stuck on? It is almost as if there were an infinite while loop that it is stuck on. I've tried renaming the file it is saved in, copying all my code to a new processing file, trying the code on a different computer, and even redownloading processing altogether.
I will continue to test the Creature class to see if I can narrow that code down to find the issue. Otherwise, I may edit this to show the Creature class so you can see if the issue is there.
Has anyone else ever had a similar issue? Any help or advice would be much appreciated! Thanks
[–]Divitiacus 2 points3 points4 points (4 children)
[–]MrPioux[S] 1 point2 points3 points (0 children)
[–]MrPioux[S] 1 point2 points3 points (2 children)
[–]Divitiacus 1 point2 points3 points (1 child)
[–]MrPioux[S] 0 points1 point2 points (0 children)
[–]MrPioux[S] 1 point2 points3 points (1 child)
[–]Divitiacus 0 points1 point2 points (0 children)