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
import kotlin.math.abs | |
import kotlin.random.Random | |
const val target = "Hello World!" | |
const val possibilities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 .,!?" | |
const val mutationProbability = 0.05 // each block of chromosome mutates with this probability | |
const val populationSize = 1000 // this many individuals will be in each generation | |
const val keepNBest = 200 // this many best individuals will be taken without change to next gen | |
const val tournamentSize = 3 // this many individuals will fight in tournament |
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
import kotlin.math.abs | |
import kotlin.math.pow | |
import kotlin.random.Random | |
const val target = "Hello World!" | |
const val possibilities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 .,!?" | |
val random = Random(System.currentTimeMillis()) | |
val String.fitness: Int get() = // lower fitness better (for this case) fitness of 0 = solution |
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
import kotlin.math.abs | |
const val target = "Hello World!" | |
const val possibilities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 .,!?" | |
val String.fitness: Int get() = // lower fitness better (for this case) fitness of 0 = solution | |
indices.sumOf { index -> | |
val indexFirst = possibilities.indexOf(target[index]) | |
val indexSecond = possibilities.indexOf(this[index]) | |
val high = maxOf(indexFirst, indexSecond) |
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
import kotlin.math.abs | |
const val target = "Hello World!" | |
const val possibilities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 .,!?" | |
val String.fitness: Int get() = // lower fitness better (for this case) fitness of 0 = solution | |
indices.sumOf { index -> | |
val indexFirst = possibilities.indexOf(target[index]) | |
val indexSecond = possibilities.indexOf(this[index]) | |
val high = maxOf(indexFirst, indexSecond) |
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
import kotlin.math.absoluteValue | |
import kotlin.random.Random | |
const val chromosomeSize = 8 | |
const val mutationProbability = 0.05 // each block of chromosome mutates with this probability | |
const val populationSize = 1000 // this many individuals will be in each generation | |
const val keepNBest = 200 // this many best individuals will be taken without change to next gen | |
const val tournamentSize = 3 // this many individuals will fight in tournament | |
val random = Random(System.currentTimeMillis()) |
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
import kotlin.math.absoluteValue | |
import kotlin.math.sin | |
import kotlin.random.Random | |
const val chromosomeSize = 100 | |
const val mutationProbability = 0.05 // each block of chromosome mutates with this probability | |
const val populationSize = 1000 // this many individuals will be in each generation | |
const val keepNBest = 200 // this many best individuals will be taken without change to next gen | |
const val tournamentSize = 3 // this many individuals will fight in tournament |
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
import java.awt.Color | |
import java.awt.Dimension | |
import java.awt.Graphics | |
import java.io.File | |
import javax.imageio.ImageIO | |
import javax.swing.BorderFactory | |
import javax.swing.JFrame | |
import javax.swing.JPanel | |
import kotlin.math.* |
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
package sk.ssnd.platformer; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.math.Vector2; | |
import com.badlogic.gdx.physics.box2d.*; | |
public class Game extends ApplicationAdapter { |
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
package sk.ssnd; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.Input; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.Sprite; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.math.Vector2; |
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
import java.awt.Color | |
import java.awt.Dimension | |
import java.awt.Graphics | |
import java.io.File | |
import javax.imageio.ImageIO | |
import javax.swing.BorderFactory | |
import javax.swing.JFrame | |
import javax.swing.JPanel | |
import kotlin.math.* |
OlderNewer