[Polycasso-commit] SF.net SVN: polycasso:[59] trunk/polycasso/src/com/mebigfatguy/polycasso/ Improv
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-26 06:31:22
|
Revision: 59
http://polycasso.svn.sourceforge.net/polycasso/?rev=59&view=rev
Author: dbrosius
Date: 2009-11-26 06:31:08 +0000 (Thu, 26 Nov 2009)
Log Message:
-----------
a class to maintain success/failure statistics per improvement type, so that 'random' selection of new improvement types can increase the probability of success, by favoring types that are higher successes
also make MovePoint more controlled so to be more effective
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-26 06:30:31 UTC (rev 58)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Improver.java 2009-11-26 06:31:08 UTC (rev 59)
@@ -37,6 +37,7 @@
private Dimension imageSize;
private List<PolygonData> polygons = null;
+ private ImprovementTypeStats stats;
private Random r;
/**
@@ -46,6 +47,7 @@
*/
public Improver(Dimension size) {
imageSize = size;
+ stats = new ImprovementTypeStats();
r = new Random();
}
@@ -68,6 +70,16 @@
}
/**
+ * updates the stats for types that successfully improved the image
+ *
+ * @param type the improvement type that was successful
+ * @param successful whether the improvement was successful
+ */
+ public void typeWasSuccessful(ImprovementType type, boolean successful) {
+ stats.typeWasSuccessful(type, successful);
+ }
+
+ /**
* attempts to improve on one polygon randomly by adjusting it according to a randomly
* selected improvement type
*
@@ -80,7 +92,7 @@
return ImprovementType.AddPolygon;
}
- ImprovementType type = ImprovementType.getRandomImprovement();
+ ImprovementType type = stats.getRandomImprovementType();
switch (type) {
case AddPolygon: {
@@ -146,8 +158,12 @@
PolygonData pd = (PolygonData)polygons.get(idx).clone();
Polygon polygon = pd.getPolygon();
int movePos = r.nextInt(polygon.npoints);
- polygon.xpoints[movePos] = r.nextInt(imageSize.width);
- polygon.ypoints[movePos] = r.nextInt(imageSize.height);
+ int moveX = r.nextInt(20) - 10;
+ int moveY = r.nextInt(20) - 10;
+ polygon.xpoints[movePos] += moveX;
+ polygon.ypoints[movePos] += moveY;
+ clipToRange(0, imageSize.width, polygon.xpoints[movePos]);
+ clipToRange(0, imageSize.height, polygon.ypoints[movePos]);
polygons.set(idx, pd);
}
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|