Commits

wiza...@PHOENIX.local  committed d608177

cleanup symmetries, right mousbutton does not work yet

  • Participants
  • Parent commits 0936cb3

Comments (0)

Files changed (2)

File hackathonAlpha.html

 
 <script type="text/javascript">
 
-var nrSimsRows = 3;
-var nrSimsCols = 2;
+var nrSimsRows = 5;
+var nrSimsCols = 5;
 
 var nrSims = nrSimsRows * nrSimsCols;
 var caCanvas, caSims;
 
 	caCanvas = new EvoCell.CACanvas($("#c")[0]);
 	
-	width = 1280;
-	height = 700;
+	width = 1200;
+	height = 800;
 	
 	ctlXRes.value = width;
 	ctlYRes.value = height;
 	clickedCA = nrSimsCols * Math.floor(nrSimsRows * (height - coords.y) / height);
 	clickedCA += Math.floor(nrSimsCols * coords.x / width);
 	
+	var mutReg;
+	var mutTarget;
+	var mutTimes;
+
+	//if (evt.button == 0) 
+	{
+		mutReg = ["?", "?", "?", "?", "?", "?", 0, 0, 0];
+		mutTarget = "?";
+		mutTimes = 100;
+	}
+	/*
+	else
+	{
+		mutReg = ["?", "?", "?", "?", "?", "?", 0, 0, 0];
+		mutTarget = 0;
+		mutTimes = 500;
+	}
+	*/
+
+	
 	var rule = caSims[clickedCA].ruleData;
 	
 	for (var i = 0; i < nrSims; i++)
 			var newRule = myClone(rule);
 			newRule.ruleTable = new Uint8Array(rule.ruleTable);
 			
-			EvoCell.mutateEvoCellRule(newRule, ["?", "?", "?", "?", "?", "?", 0, 0, 0], 150);
+			EvoCell.mutateEvoCellRule(newRule, mutReg, mutTarget, mutTimes);
 			caSims[i].setRule(newRule);
 		}
 	}

File src/evocellweb.js

 		evoCellData.containsNeighbourhood = true;
 		evoCellData.nrDimensions = nrDimensions;
 		evoCellData.neighbourhood = neighbourhood;
+		evoCellData.symmetries = calculateSymmetries(evoCellData);
 	}
 	else
 		evoCellData.containsNeighbourhood = false;
 	}
 	else
 		evoCellData.containsPattern = false;
-	
+	       
 	return evoCellData;
 }
 
-function myClone(a)
+function calculateSymmetries(evoCellData) 
 {
-	b = {};
-	for (f in a) {
-		b[f] = a[f];
-	}
-	return b;
-}
-	
-
-
-function getRandInt(min, max)
-{
-	return min + parseInt( Math.random() * max);
-}
-
-function rot90(xy)
-{
-	return [-xy[1], xy[0]];
-}
-
-
-function mutRotSym(evoCellData, vals, targetState)
-{
-	var localRot = rot90;
+	symmetryPermutations = [];
 	
 	for (var rot = 0; rot < 4; rot++)
 	{
 				}
 			}
 		}
+		// check if rotation was successful
+		if (rotVals.length == evoCellData.neighbourhood.length) 
+		{
+			symmetryPermutations.push(rotVals);
+		}
+	}
+	return symmetryPermutations;
+}
+
+function myClone(a)
+{
+	b = {};
+	for (f in a) {
+		b[f] = a[f];
+	}
+	return b;
+}
+	
+
+
+function getRandInt(min, max)
+{
+	return min + parseInt( Math.random() * max);
+}
+
+function rot90(xy)
+{
+	return [-xy[1], xy[0]];
+}
+
+
+function mutRotSym(evoCellData, vals, targetState)
+{
+	for (sidx in evoCellData.symmetries) {
+		var s = evoCellData.symmetries[sidx];
 		var idx = 0;
-		for (var j = evoCellData.nrNeighbours-1; j >= 0; j--)
+		for (var j = s.length-1; j >= 0; j--)
 		{
-			idx = idx * evoCellData.nrStates + vals[rotVals[j]];
+			idx = idx * evoCellData.nrStates + vals[s[j]];
 		}
 		evoCellData.ruleTable.set([targetState], idx);
+		//break;
 	}
 	
 }
 
+function evalRegexpr(r, evoCellData) 
+{
+	if (r == "?")
+		return getRandInt(0, evoCellData.nrStates);
+	else
+		return r;
+}
 
-EvoCell.mutateEvoCellRule = function(evoCellData, regExprs, n)
+EvoCell.mutateEvoCellRule = function(evoCellData, regExprs, targetRegExpr, n)
 {
 	for (var i = 0; i < n; i++)
 	{
-		//var idx = getRandInt(0, evoCellData.ruleTableSize);
-		
-		var idx = 0;
 		var nr = 0;
 		var vals = [];
 		for (var j = 0; j < evoCellData.nrNeighbours; j++)
 		{
-			if (regExprs[j] == "?")
-			{
-				nr = getRandInt(0, evoCellData.nrStates);
-			}
-			else
-				nr = regExprs[j];
-			
+			nr = evalRegexpr(regExprs[j], evoCellData);
 			vals.push(nr);
-			idx = idx * evoCellData.nrStates + nr;
 		}
 				
-		var targetState = getRandInt(0, evoCellData.nrStates);
+		var targetState = evalRegexpr(targetRegExpr, evoCellData);
 		mutRotSym(evoCellData, vals, targetState);
-		
 	}
 }