Skip to content

Instantly share code, notes, and snippets.

View anissen's full-sized avatar

Anders Nissen anissen

View GitHub Profile
@anissen
anissen / Test.hx
Created January 29, 2016 17:00
Generative grammar for procedural quest generation
// Inspired by
// http://www.jorisdormans.nl/pdf/dormans2010_AdventuresInLevelDesign.pdf
// http://larc.unt.edu/ian/pubs/pcg2011.pdf
// http://larc.unt.edu/ian/pubs/DoranParberryQuests2015.pdf
// Idea: Use a macro to extract Symbol and Terminal information and populate enums
enum Symbol {
Quest;
SubQuest;
@anissen
anissen / Test.hx
Last active January 24, 2016 20:59
Generative grammar for procedural generation
// Inspired by http://www.jorisdormans.nl/pdf/dormans2010_AdventuresInLevelDesign.pdf
enum Symbol {
Dungeon;
Obstacle;
}
enum Terminal {
Treasure;
Key;
@anissen
anissen / Test.hx
Created January 7, 2016 21:41
hscript revised test
class Script {
var program :hscript.Expr;
var interp :hscript.Interp;
public function new(source :haxe.io.Input) {
var parser = new hscript.Parser();
interp = new hscript.Interp();
try {
program = parser.parse(source);
@anissen
anissen / ThreadPool.hx
Created December 16, 2015 20:27 — forked from hamaluik/ThreadPool.hx
Platform-agnostic thread pool for Haxe / OpenFL
package com.blazingmammothgames.util;
#if neko
import neko.vm.Thread;
import neko.vm.Mutex;
#elseif cpp
import cpp.vm.Thread;
import cpp.vm.Mutex;
#end
@anissen
anissen / Immutable.hx
Created December 9, 2015 09:10
Using abstract to creating immutable objects in Haxe
class Foo {
public function new( val ) x = val;
public var x : Int;
}
abstract ConstFoo(Foo) from Foo {
public var x(get, never) : Int;
function get_x() return this.x;
}
@anissen
anissen / Main.hx
Last active November 26, 2015 13:13 — forked from francescoagati/Main.hx
Import JSON in Haxe at compile time
#if macro
import haxe.macro.Context;
#end
class Main {
macro static function load_json(file :String) {
var data = sys.io.File.getContent(file);
var json = haxe.Json.parse(data);
return Context.makeExpr(json, Context.currentPos());
@anissen
anissen / maybe.hx
Created November 3, 2015 07:12
Test of pseudo-monads in haxe
import haxe.ds.Option;
using Test.OptionTools;
class OptionTools {
static public function fmap<T>(m :Option<T>, f :T->T) :Option<T> {
switch m {
case Some(x): return Some(f(x));
case None: return None;
}
@anissen
anissen / MainTest.hx
Created June 18, 2015 11:57
Haxe hxcpp cppia test
class MainTest {
static public function main() {
trace("Hello world!");
trace('Fibonacci of 7 is: ${fibonacci(7)}');
}
static function fibonacci(n) {
if (n == 0) return 0;
else if (n == 1) return 1;
@anissen
anissen / perlin.hx
Last active March 5, 2017 18:16
Perlin noise test
// Haxe implementation ported from https://gist.github.com/Flafla2/f0260a861be0ebdeef76
// Related article: http://flafla2.github.io/2014/08/09/perlinnoise.html
class Perlin {
public var repeat :Int;
public function new(repeat :Int = -1) {
this.repeat = repeat;
}
@anissen
anissen / Markov.hx
Created April 5, 2015 13:46
Markov chain text generator v2
class Markov {
var cache :Map<String, Array<String>>;
var starting_keys :Array<Array<String>>;
public function new() {
cache = new Map<String, Array<String>>();
starting_keys = [];
}
public function train(input :String) {