-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
9,166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
| ||
|
||
namespace StarcraftBot.BW | ||
{ | ||
class Unit | ||
{ | ||
public SWIG.BWAPI.Unit theUnit; | ||
public SWIG.BWAPI.Unit theTarget; | ||
|
||
public Unit(SWIG.BWAPI.Unit u) | ||
{ | ||
theUnit = u; | ||
theTarget = null; | ||
} | ||
|
||
public bool HasTarget() | ||
{ | ||
return (theTarget != null); | ||
} | ||
|
||
public void Attack(SWIG.BWAPI.Unit t) | ||
{ | ||
if (t == null && theTarget != null) | ||
{ | ||
theUnit.stop(); | ||
theTarget = null; | ||
} | ||
else if (t != null && t != theTarget) | ||
{ | ||
theTarget = t; | ||
theUnit.attackUnit(theTarget); | ||
} | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
mampf-scai/StarcraftBot/EvolutionaryAlgorithms/Chromosome.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace StarcraftBot.EvolutionaryAlgorithms | ||
{ | ||
|
||
/// <summary> | ||
/// This class holds a list of genes whose values can be adjusted to solve a specific problem. | ||
/// The class also holds the fitness value used to deside how well the Chromosome solves the specific problem. | ||
/// @author Thomas Willer Sandberg (http://twsandberg.dk/) | ||
/// @version (1.0, January 2011) | ||
/// </summary> | ||
class Chromosome | ||
{ | ||
protected static GaussianRandom GausianRandom = new GaussianRandom(); | ||
|
||
public Chromosome() | ||
{ | ||
Gene = new List<float>(); | ||
} | ||
|
||
public Chromosome(List<float> gene) | ||
{ | ||
Gene = gene; | ||
} | ||
|
||
public Chromosome(float[] genesFloat) | ||
{ | ||
Gene = new List<float>(); | ||
|
||
SetGene(genesFloat); | ||
} | ||
|
||
/// <summary> | ||
/// Mutate a randomly number of the genes/values in the current Chromosome with a random number drawn from a Gaussian distribution. with a mean and standard deviation | ||
/// </summary> | ||
/// <param name="mean"></param> | ||
/// <param name="deviation"></param> | ||
public void MutateGaussianRandom(float mean, float deviation) | ||
{ | ||
int y = RandomNumber.RandomInt(0, 5); | ||
int numberOfRuns = Gene.Count; | ||
while (y < numberOfRuns) | ||
{ | ||
Gene[y] += Convert.ToSingle(GausianRandom.NextGaussian(mean, deviation)); | ||
y += RandomNumber.RandomInt(1, 5); | ||
} | ||
} | ||
|
||
/** | ||
* Mutate all the genes/values in the current Chromosome with a random number drawn from a Gaussian distribution. with a mean and standard deviation | ||
* @param float mean | ||
* @param float deviation - standard deviation | ||
*/ | ||
public void MutateGaussian(float mean, float deviation) | ||
{ | ||
int numberOfRuns = Gene.Count; | ||
|
||
for (int y = 0; y < numberOfRuns; y++) | ||
{ | ||
Gene[y] += Convert.ToSingle(GausianRandom.NextGaussian(mean, deviation));//r; | ||
} | ||
} | ||
|
||
private float FlipFloatRandom(float aFloat) | ||
{ | ||
float r = RandomNumber.RandomInt(0,1); | ||
if(r==0) | ||
r = -1; | ||
return aFloat*r; | ||
} | ||
|
||
public void FlipRandomAllWeights() | ||
{ | ||
foreach (float f in Gene) | ||
FlipFloatRandom(f); | ||
} | ||
|
||
//Properties | ||
public void SetGene(float[] genesFloat) | ||
{ | ||
foreach (float f in genesFloat) | ||
Gene.Add(f); | ||
} | ||
|
||
public List<float> Gene { get; set; } | ||
public int Fitness { get; set; } | ||
} | ||
} |
Oops, something went wrong.