Commits

Philipp Tiefenbacher committed cb01a69

fixing bugs, nX and aX works now

  • Participants
  • Parent commits 9282af1

Comments (0)

Files changed (2)

File hackathonAlpha.html

 			mutReg = [];
 			for (i = 0; i < rule.neighbourhood.length; i++)
 			{
-				mutReg[i] = document.getElementById('nPattern_' + i).value;
+				mutReg.push(document.getElementById('nPattern_' + i).value);
 			}
-			mutTarget = document.getElementById('nPattern_target').value;
+			mutTarget = mutTimes = document.getElementById('nPattern_target').value;			
+			
+			//alert(document.getElementById('nPattern_all').checked);
 
 			
 
-			mutTimes = 1300;
+			mutTimes = document.getElementById('nPattern_mutations').value;
 		}
 		/*
 		else
 
 function fillPalette(evoCellData)
 {
+	var leftOffset = 55, topOffset = 75, xOffset = 55;
 	var s="<div style=\"background-color:#ccf;\">Dont hesitate...MUTATE!</div>";
-
+	
+ 
+	s+="mutations: <input type='number' id='nPattern_mutations' value='1000' style='width:70px;' /> <input type='checkbox' id='nPattern_all' /> All rules ";
 	
 	for (var nIndex = 0; nIndex < evoCellData.neighbourhood.length; nIndex++)
 	{
 		
 		var x = neighbour[0];
 		var y = neighbour[1];
-		var posx = 55 + x*55;
-		var posy = 45 + y*25;
+		var posx = leftOffset + x * xOffset;
+		var posy = topOffset + y * 25;
 
 	 	s+= "<input type=\"text\" id=\"nPattern_" + nIndex + "\" value=\"?\" style=\"position:absolute; width:40px; left:" + posx + "px; top:" + posy + "px;\" />";
 	}
 
-	var posx = 55 + 2.5 * 55;
-	var posy = 45;
+	var posx = leftOffset + 2.3 * xOffset;
+	var posy = topOffset;
 	s+="<input type=\"text\" id=\"nPattern_target\" value=\"?\" style=\"position:absolute; width:40px; left:" + posx + "px; top:" + posy + "px;\" />";
 
 	var div = document.getElementById('floatingPalette');
 </head>
 <body onload="setup()">
 
-	<div id="floatingPalette" style="position:fixed; width:240px; height:100px; left:200px; top:200px; background-color:#fdd; cursor:move;">hello world</div>
+	<div id="floatingPalette" style="position:fixed; width:240px; height:150px; left:200px; top:200px; background-color:#fdd; cursor:move;">hello world</div>
 
 	<canvas id="c" width="1000" height="3333"></canvas>
 

File src/evocellweb.js

 
 function getRandInt(min, max)
 {
-	return min + parseInt( Math.random() * max);
+	return min + Math.floor(Math.random() * (max-min));
 }
 
 function rot90(xy)
 		{
 			idx = idx * evoCellData.nrStates + vals[s[j]];
 		}
+		try
+		{
 		evoCellData.ruleTable.set([targetState], idx);
 		//break;
+		}
+		catch (ex)
+		{
+			alert(vals + " -> " + targetState); 
+		}
 	}
 	
 }
 		return parseInt(r);
 }
 
+function evalTargetRegexpr(r, evoCellData, vals)
+{
+	if (r.length > 0 && r[0]=='n')
+	{
+		return vals[parseInt(r.substr(1))];
+	}
+	if (r.length > 0 && r[0]=='a')
+	{
+		var sum = parseInt(r.substr(1));
+
+		for (var i = 0; i < vals.length; i++)
+		{	
+			sum += vals[i];
+		}
+		var zS = Math.floor(sum/vals.length);
+		return zS;
+	}
+	return evalRegexpr(r, evoCellData);
+}
+
 EvoCell.mutateEvoCellRule = function(evoCellData, regExprs, targetRegExpr, n)
 {
 	for (var i = 0; i < n; i++)
 			vals.push(nr);
 		}
 				
-		var targetState = evalRegexpr(targetRegExpr, evoCellData);
+		var targetState = evalTargetRegexpr(targetRegExpr, evoCellData, vals);
 		mutRotSym(evoCellData, vals, targetState);
 	}
 }