## This is a JS-EDEN script automatically generated using the environment's script generator feature.
## JS-EDEN is an open source empirical modelling environment based on research, principles and work
## conducted at University of Warwick.
## Web site: https://github.com/emgroup/js-eden
## Firstly, turn off automatic calculation until the construal is fully loaded.
autocalc = 0;
## Include Files:
## Observable Assignments:
randomSeed = @;
right = @;
bottom = @;
x = 200;
y = 60;
sqWidth = 50;
sqHeight = 80;
val1 = "red";
val2 = @;
val3 = @;
val4 = @;
val5 = @;
val6 = @;
val7 = @;
val8 = @;
val9 = @;
val10 = @;
val11 = @;
val12 = @;
val13 = @;
val14 = @;
val15 = @;
blackCells = 4;
yellowCells = 4;
redCells = 4;
blueCells = 3;
## Observable Definitions:
dep1 is [2,4,5];
dep2 is [1,5,3];
dep3 is [2,5,6];
dep4 is [1,5,7,8,9];
dep5 is [1,2,3,4,6,9];
dep6 is [3,5,9,10,11];
dep7 is [4,8];
dep8 is [4,7,9,12,13];
dep9 is [4,5,6,8,10,13];
dep10 is [6,9,11,13,14];
dep11 is [6,10];
dep12 is [8,13,15];
dep13 is [8,9,10,12,14,15];
dep14 is [10,13,15];
dep15 is [12,13,14];
isRed2 is val2 == "red";
isRed4 is val4 == "red";
isRed5 is val5 == "red";
canBeRed1 is !(isRed2 || isRed4 || isRed5);
isRed1 is val1 == "red";
isRed3 is val3 == "red";
canBeRed2 is !(isRed1 || isRed5 || isRed3);
isRed6 is val6 == "red";
canBeRed3 is !(isRed2 || isRed5 || isRed6);
isRed7 is val7 == "red";
isRed8 is val8 == "red";
isRed9 is val9 == "red";
canBeRed4 is !(isRed1 || isRed5 || isRed7 || isRed8 || isRed9);
canBeRed5 is !(isRed1 || isRed2 || isRed3 || isRed4 || isRed6 || isRed9);
isRed10 is val10 == "red";
isRed11 is val11 == "red";
canBeRed6 is !(isRed3 || isRed5 || isRed9 || isRed10 || isRed11);
canBeRed7 is !(isRed4 || isRed8);
isRed12 is val12 == "red";
isRed13 is val13 == "red";
canBeRed8 is !(isRed4 || isRed7 || isRed9 || isRed12 || isRed13);
canBeRed9 is !(isRed4 || isRed5 || isRed6 || isRed8 || isRed10 || isRed13);
isRed14 is val14 == "red";
canBeRed10 is !(isRed6 || isRed9 || isRed11 || isRed13 || isRed14);
canBeRed11 is !(isRed6 || isRed10);
isRed15 is val15 == "red";
canBeRed12 is !(isRed8 || isRed13 || isRed15);
canBeRed13 is !(isRed8 || isRed9 || isRed10 || isRed12 || isRed14 || isRed15);
canBeRed14 is !(isRed10 || isRed13 || isRed15);
canBeRed15 is !(isRed12 || isRed13 || isRed14);
isGreen2 is val2 == "green";
isGreen4 is val4 == "green";
isGreen5 is val5 == "green";
canBeGreen1 is !(isGreen2 || isGreen4 || isGreen5);
isGreen1 is val1 == "green";
isGreen3 is val3 == "green";
canBeGreen2 is !(isGreen1 || isGreen5 || isGreen3);
isGreen6 is val6 == "green";
canBeGreen3 is !(isGreen2 || isGreen5 || isGreen6);
isGreen7 is val7 == "green";
isGreen8 is val8 == "green";
isGreen9 is val9 == "green";
canBeGreen4 is !(isGreen1 || isGreen5 || isGreen7 || isGreen8 || isGreen9);
canBeGreen5 is !(isGreen1 || isGreen2 || isGreen3 || isGreen4 || isGreen6 || isGreen9);
isGreen10 is val10 == "green";
isGreen11 is val11 == "green";
canBeGreen6 is !(isGreen3 || isGreen5 || isGreen9 || isGreen10 || isGreen11);
canBeGreen7 is !(isGreen4 || isGreen8);
isGreen12 is val12 == "green";
isGreen13 is val13 == "green";
canBeGreen8 is !(isGreen4 || isGreen7 || isGreen9 || isGreen12 || isGreen13);
canBeGreen9 is !(isGreen4 || isGreen5 || isGreen6 || isGreen8 || isGreen10 || isGreen13);
isGreen14 is val14 == "green";
canBeGreen10 is !(isGreen6 || isGreen9 || isGreen11 || isGreen13 || isGreen14);
canBeGreen11 is !(isGreen6 || isGreen10);
isGreen15 is val15 == "green";
canBeGreen12 is !(isGreen8 || isGreen13 || isGreen15);
canBeGreen13 is !(isGreen8 || isGreen9 || isGreen10 || isGreen12 || isGreen14 || isGreen15);
canBeGreen14 is !(isGreen10 || isGreen13 || isGreen15);
canBeGreen15 is !(isGreen12 || isGreen13 || isGreen14);
isYellow2 is val2 == "yellow";
isYellow4 is val4 == "yellow";
isYellow5 is val5 == "yellow";
canBeYellow1 is !(isYellow2 || isYellow4 || isYellow5);
isYellow1 is val1 == "yellow";
isYellow3 is val3 == "yellow";
canBeYellow2 is !(isYellow1 || isYellow5 || isYellow3);
isYellow6 is val6 == "yellow";
canBeYellow3 is !(isYellow2 || isYellow5 || isYellow6);
isYellow7 is val7 == "yellow";
isYellow8 is val8 == "yellow";
isYellow9 is val9 == "yellow";
canBeYellow4 is !(isYellow1 || isYellow5 || isYellow7 || isYellow8 || isYellow9);
canBeYellow5 is !(isYellow1 || isYellow2 || isYellow3 || isYellow4 || isYellow6 || isYellow9);
isYellow10 is val10 == "yellow";
isYellow11 is val11 == "yellow";
canBeYellow6 is !(isYellow3 || isYellow5 || isYellow9 || isYellow10 || isYellow11);
canBeYellow7 is !(isYellow4 || isYellow8);
isYellow12 is val12 == "yellow";
isYellow13 is val13 == "yellow";
canBeYellow8 is !(isYellow4 || isYellow7 || isYellow9 || isYellow12 || isYellow13);
canBeYellow9 is !(isYellow4 || isYellow5 || isYellow6 || isYellow8 || isYellow10 || isYellow13);
isYellow14 is val14 == "yellow";
canBeYellow10 is !(isYellow6 || isYellow9 || isYellow11 || isYellow13 || isYellow14);
canBeYellow11 is !(isYellow6 || isYellow10);
isYellow15 is val15 == "yellow";
canBeYellow12 is !(isYellow8 || isYellow13 || isYellow15);
canBeYellow13 is !(isYellow8 || isYellow9 || isYellow10 || isYellow12 || isYellow14 || isYellow15);
canBeYellow14 is !(isYellow10 || isYellow13 || isYellow15);
canBeYellow15 is !(isYellow12 || isYellow13 || isYellow14);
isBlue2 is val2 == "blue";
isBlue4 is val4 == "blue";
isBlue5 is val5 == "blue";
canBeBlue1 is !(isBlue2 || isBlue4 || isBlue5);
isBlue1 is val1 == "blue";
isBlue3 is val3 == "blue";
canBeBlue2 is !(isBlue1 || isBlue5 || isBlue3);
isBlue6 is val6 == "blue";
canBeBlue3 is !(isBlue2 || isBlue5 || isBlue6);
isBlue7 is val7 == "blue";
isBlue8 is val8 == "blue";
isBlue9 is val9 == "blue";
canBeBlue4 is !(isBlue1 || isBlue5 || isBlue7 || isBlue8 || isBlue9);
canBeBlue5 is !(isBlue1 || isBlue2 || isBlue3 || isBlue4 || isBlue6 || isBlue9);
isBlue10 is val10 == "blue";
isBlue11 is val11 == "blue";
canBeBlue6 is !(isBlue3 || isBlue5 || isBlue9 || isBlue10 || isBlue11);
canBeBlue7 is !(isBlue4 || isBlue8);
isBlue12 is val12 == "blue";
isBlue13 is val13 == "blue";
canBeBlue8 is !(isBlue4 || isBlue7 || isBlue9 || isBlue12 || isBlue13);
canBeBlue9 is !(isBlue4 || isBlue5 || isBlue6 || isBlue8 || isBlue10 || isBlue13);
isBlue14 is val14 == "blue";
canBeBlue10 is !(isBlue6 || isBlue9 || isBlue11 || isBlue13 || isBlue14);
canBeBlue11 is !(isBlue6 || isBlue10);
isBlue15 is val15 == "blue";
canBeBlue12 is !(isBlue8 || isBlue13 || isBlue15);
canBeBlue13 is !(isBlue8 || isBlue9 || isBlue10 || isBlue12 || isBlue14 || isBlue15);
canBeBlue14 is !(isBlue10 || isBlue13 || isBlue15);
canBeBlue15 is !(isBlue12 || isBlue13 || isBlue14);
canBeRed is [canBeRed1, canBeRed2, canBeRed3, canBeRed4, canBeRed5, canBeRed6, canBeRed7, canBeRed8, canBeRed9, canBeRed10, canBeRed11, canBeRed12, canBeRed13, canBeRed14, canBeRed15];
canBeGreen is [canBeGreen1, canBeGreen2, canBeGreen3, canBeGreen4, canBeGreen5, canBeGreen6, canBeGreen7, canBeGreen8, canBeGreen9, canBeGreen10, canBeGreen11, canBeGreen12, canBeGreen13, canBeGreen14, canBeGreen15];
canBeBlue is [canBeBlue1, canBeBlue2, canBeBlue3, canBeBlue4, canBeBlue5, canBeBlue6, canBeBlue7, canBeBlue8, canBeBlue9, canBeBlue10, canBeBlue11, canBeBlue12, canBeBlue13, canBeBlue14, canBeBlue15];
canBeYellow is [canBeYellow1, canBeYellow2, canBeYellow3, canBeYellow4, canBeYellow5, canBeYellow6, canBeYellow7, canBeYellow8, canBeYellow9, canBeYellow10, canBeYellow11, canBeYellow12, canBeYellow13, canBeYellow14, canBeYellow15];
values is [val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,val12,val13,val14,val15];
valuesPointers is [&val1,&val2,&val3,&val4,&val5,&val6,&val7,&val8,&val9,&val10,&val11,&val12,&val13,&val14,&val15];
hex1 is drawHex(1, -75+x,40+y,values);
hex2 is drawHex(2, x,y,values);
hex3 is drawHex(3, 75+x,40+y,values);
hex4 is drawHex(4, -75+x,120 + y,values);
hex5 is drawHex(5, x,80 + y,values);
hex6 is drawHex(6, 75+x,120 + y,values);
hex7 is drawHex(7, -150+x,160+y,values);
hex8 is drawHex(8, -75+x,200+y,values);
hex9 is drawHex(9, x,160 + y,values);
hex10 is drawHex(10, 75+x,200 + y,values);
hex11 is drawHex(11, 150+x,160+y,values);
hex12 is drawHex(12, -75+x,280+y,values);
hex13 is drawHex(13, 0+x,240+y,values);
hex14 is drawHex(14, 75+x,280+y,values);
hex15 is drawHex(15, 0+x,320+y,values);
corner1 is hex1[1].points[2];
corner2 is hex2[1].points[2];
corner3 is hex3[1].points[2];
corner4 is hex4[1].points[2];
corner5 is hex5[1].points[2];
corner6 is hex6[1].points[2];
corner7 is hex7[1].points[2];
corner8 is hex8[1].points[2];
corner9 is hex9[1].points[2];
corner10 is hex10[1].points[2];
corner11 is hex11[1].points[2];
corner12 is hex12[1].points[2];
corner13 is hex13[1].points[2];
corner14 is hex14[1].points[2];
corner15 is hex15[1].points[2];
topCorners is [corner1, corner2, corner3, corner4, corner5, corner6, corner7, corner8, corner9, corner10, corner11, corner12, corner13, corner14, corner15];
xPart is floor((mouseDown.x - 50) / 25, 1);
yPart is floor((mouseDown.y - 60) / 40, 1);
near1 is (sqrt((mousePosition.x - (corner1.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner1.y + sqHeight / 2)) ^ 2) < 25);
near2 is (sqrt((mousePosition.x - (corner2.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner2.y + sqHeight / 2)) ^ 2) < 25);
near3 is (sqrt((mousePosition.x - (corner3.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner3.y + sqHeight / 2)) ^ 2) < 25);
near4 is (sqrt((mousePosition.x - (corner4.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner4.y + sqHeight / 2)) ^ 2) < 25);
near5 is (sqrt((mousePosition.x - (corner5.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner5.y + sqHeight / 2)) ^ 2) < 25);
near6 is (sqrt((mousePosition.x - (corner6.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner6.y + sqHeight / 2)) ^ 2) < 25);
near7 is (sqrt((mousePosition.x - (corner7.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner7.y + sqHeight / 2)) ^ 2) < 25);
near8 is (sqrt((mousePosition.x - (corner8.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner8.y + sqHeight / 2)) ^ 2) < 25);
near9 is (sqrt((mousePosition.x - (corner9.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner9.y + sqHeight / 2)) ^ 2) < 25);
near10 is (sqrt((mousePosition.x - (corner10.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner10.y + sqHeight / 2)) ^ 2) < 25);
near11 is (sqrt((mousePosition.x - (corner11.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner11.y + sqHeight / 2)) ^ 2) < 25);
near12 is (sqrt((mousePosition.x - (corner12.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner12.y + sqHeight / 2)) ^ 2) < 25);
near13 is (sqrt((mousePosition.x - (corner13.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner13.y + sqHeight / 2)) ^ 2) < 25);
near14 is (sqrt((mousePosition.x - (corner14.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner14.y + sqHeight / 2)) ^ 2) < 25);
near15 is (sqrt((mousePosition.x - (corner15.x + sqWidth / 2)) ^ 2) < 25) && (sqrt((mousePosition.y - (corner15.y + sqHeight / 2)) ^ 2) < 25);
proc changeHex : mouseDown {
auto diffX, selectedH;
if(near1){
diffX = mouseDown.x - corner1.x;
selectedH = 1;
}
if(near2){
diffX = mouseDown.x - corner2.x;
selectedH = 2;
}
if(near3){
diffX = mouseDown.x - corner3.x;
selectedH = 3;
}
if(near4){
diffX = mouseDown.x - corner4.x;
selectedH = 4;
}
if(near5){
diffX = mouseDown.x - corner5.x;
selectedH = 5;
}
if(near6){
diffX = mouseDown.x - corner6.x;
selectedH = 6;
}
if(near7){
diffX = mouseDown.x - corner7.x;
selectedH = 7;
}
if(near8){
diffX = mouseDown.x - corner8.x;
selectedH = 8;
}
if(near9){
diffX = mouseDown.x - corner9.x;
selectedH = 9;
}
if(near10){
diffX = mouseDown.x - corner10.x;
selectedH = 10;
}
if(near11){
diffX = mouseDown.x - corner11.x;
selectedH = 11;
}
if(near12){
diffX = mouseDown.x - corner12.x;
selectedH = 12;
}
if(near13){
diffX = mouseDown.x - corner13.x;
selectedH = 13;
}
if(near14){
diffX = mouseDown.x - corner14.x;
selectedH = 14;
}
if(near15){
diffX = mouseDown.x - corner15.x;
selectedH = 15;
}
if((diffX >= 5) && (diffX < 15) && canBeRed[selectedH]){
*valuesPointers[selectedH] = "red";
}
if((diffX >= 15) && (diffX < 25) && canBeGreen[selectedH]){
*valuesPointers[selectedH] = "green";
}
if((diffX >= 25) && (diffX < 35) && canBeYellow[selectedH]){
*valuesPointers[selectedH] = "yellow";
}
if((diffX >= 35) && (diffX < 45) && canBeBlue[selectedH]){
*valuesPointers[selectedH] = "blue";
}
if((diffX >= 45) && (diffX < 55) && !(*valuesPointers[selectedH] == @)){
*valuesPointers[selectedH] = @;
}
}
## Action Definitions:
## Function Definitions:
func drawHex {
para num, x, y, values;
point1 is {x - sqWidth / 2, y + sqHeight / 2};
point2 is {x, y};
point3 is {x, y + sqHeight};
point4 is {x + sqWidth * 1.5, y + sqHeight / 2};
point5 is {x + sqWidth, y};
point6 is {x + sqWidth, y + sqHeight};
hexagon is Polygon([point1, point2, point5, point4, point6, point3], values[num], "black");
potentialRed is (canBeRed[num] && redsLeft > 0) ? Rectangle(x+5,y - 5 + sqHeight / 2,10,10,"red") : Point(x,y);
potentialGreen is (canBeGreen[num] && greensLeft > 0) ? Rectangle(x+15,y - 5 + sqHeight / 2,10,10,"green") : Point(x,y);
potentialYellow is (canBeYellow[num] && yellowsLeft > 0) ? Rectangle(x+25,y - 5 + sqHeight / 2,10,10,"yellow") : Point(x,y);
potentialBlue is (canBeBlue[num] && bluesLeft > 0) ? Rectangle(x+35,y - 5 + sqHeight / 2,10,10,"blue") : Point(x,y);
resetBtn is Rectangle(x+45,y - 5 + sqHeight / 2,10,10,"white");
display is Text(num, x+25, y + 40);
return [hexagon, display, potentialRed, potentialGreen, potentialYellow, potentialBlue, resetBtn];
}
solvedText is solved ? Text("Well done! You've solved the puzzle!", 0, 0,18, "green","black") : @;
## Picture Definition:
picture is hex1 // hex2 // hex3 // hex4 // hex5 // hex6 // hex7 // hex8 // hex9 // hex10 // hex11 // hex12 // hex13 // hex14 // hex15 // solvedText;
yellowsUsed is isYellow1 + isYellow2 + isYellow3 + isYellow4 + isYellow5 + isYellow6 + isYellow7 + isYellow8 + isYellow9 + isYellow10 + isYellow11 + isYellow12 + isYellow13 + isYellow14 + isYellow15;
redsUsed is isRed1 + isRed2 + isRed3 + isRed4 + isRed5 + isRed6 + isRed7 + isRed8 + isRed9 + isRed10 + isRed11 + isRed12 + isRed13 + isRed14 + isRed15;
bluesUsed is isBlue1 + isBlue2 + isBlue3 + isBlue4 + isBlue5 + isBlue6 + isBlue7 + isBlue8 + isBlue9 + isBlue10 + isBlue11 + isBlue12 + isBlue13 + isBlue14 + isBlue15;
greensUsed is isGreen1 + isGreen2 + isGreen3 + isGreen4 + isGreen5 + isGreen6 + isGreen7 + isGreen8 + isGreen9 + isGreen10 + isGreen11 + isGreen12 + isGreen13 + isGreen14 + isGreen15;
valid1 is (canBeBlue1 && isBlue1) || (canBeRed1 && isRed1) || (canBeYellow1 && isYellow1) || (canBeGreen1 && isGreen1);
valid2 is (canBeBlue2 && isBlue2) || (canBeRed2 && isRed2) || (canBeYellow2 && isYellow2) || (canBeGreen2 && isGreen2);
valid3 is (canBeBlue3 && isBlue3) || (canBeRed3 && isRed3) || (canBeYellow3 && isYellow3) || (canBeGreen3 && isGreen3);
valid4 is (canBeBlue4 && isBlue4) || (canBeRed4 && isRed4) || (canBeYellow4 && isYellow4) || (canBeGreen4 && isGreen4);
valid5 is (canBeBlue5 && isBlue5) || (canBeRed5 && isRed5) || (canBeYellow5 && isYellow5) || (canBeGreen5 && isGreen5);
valid6 is (canBeBlue6 && isBlue6) || (canBeRed6 && isRed6) || (canBeYellow6 && isYellow6) || (canBeGreen6 && isGreen6);
valid7 is (canBeBlue7 && isBlue7) || (canBeRed7 && isRed7) || (canBeYellow7 && isYellow7) || (canBeGreen7 && isGreen7);
valid8 is (canBeBlue8 && isBlue8) || (canBeRed8 && isRed8) || (canBeYellow8 && isYellow8) || (canBeGreen8 && isGreen8);
valid9 is (canBeBlue9 && isBlue9) || (canBeRed9 && isRed9) || (canBeYellow9 && isYellow9) || (canBeGreen9 && isGreen9);
valid10 is (canBeBlue10 && isBlue10) || (canBeRed10 && isRed10) || (canBeYellow10 && isYellow10) || (canBeGreen10 && isGreen10);
valid11 is (canBeBlue11 && isBlue11) || (canBeRed11 && isRed11) || (canBeYellow11 && isYellow11) || (canBeGreen11 && isGreen11);
valid12 is (canBeBlue12 && isBlue12) || (canBeRed12 && isRed12) || (canBeYellow12 && isYellow12) || (canBeGreen12 && isGreen12);
valid13 is (canBeBlue13 && isBlue13) || (canBeRed13 && isRed13) || (canBeYellow13 && isYellow13) || (canBeGreen13 && isGreen13);
valid14 is (canBeBlue14 && isBlue14) || (canBeRed14 && isRed14) || (canBeYellow14 && isYellow14) || (canBeGreen14 && isGreen14);
valid15 is (canBeBlue15 && isBlue15) || (canBeRed15 && isRed15) || (canBeYellow15 && isYellow15) || (canBeGreen15 && isGreen15);
solved is valid1 && valid2 && valid3 && valid4 && valid5 && valid6 && valid7 && valid8 && valid9 && valid10 && valid11 && valid12 && valid13 && valid14 && valid15;
yellowsLeft is 4 - yellowsUsed;
redsLeft is 4 - redsUsed;
bluesLeft is 4 - bluesUsed;
greensLeft is 3 - greensUsed;
## Turn on automatic calculation and execute any triggered actions pending.
autocalc = 1;
## End of automatically generated script.