Created
June 24, 2018 08:26
-
-
Save back2dos/ec900b76bb01c9c1ffed4f6cf5890bf3 to your computer and use it in GitHub Desktop.
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 tink.state.*; | |
import coconut.data.*; | |
@:enum abstract Side(String) to String { | |
var North = "North"; | |
var East = "East"; | |
var South = "South"; | |
var West = "West"; | |
} | |
class Main { | |
static function main() { | |
var g = new GameModel({}); | |
var rules = new RulesModel({ | |
players: g.players, | |
}); | |
rules.observables.isComplete.bind({ direct: true }, function (x) trace(x)); | |
g.players.get(East).update({pool:43}); | |
g.players.get(West).update({pool:46}); | |
g.players.get(South).update({pool:55}); | |
} | |
} | |
class RulesModel implements Model { | |
@:constant var convention:{ final pool:Int; } = { pool: 42 }; | |
@:external var players:Mapping<Side,PlayerModel>; | |
@:computed var isComplete:Bool = { | |
var isPoolGreaterOrEqual = true; | |
for (p in players) { | |
trace('${p.side} pool: ${p.pool}'); | |
if (p.pool <= convention.pool) { | |
isPoolGreaterOrEqual = false; | |
} | |
} | |
return isPoolGreaterOrEqual; | |
} | |
} | |
class PlayerModel implements Model { | |
@:observable var pool:Int = @byDefault 0; | |
@:constant var side:Side; | |
@:transition function update(patches) return patches; | |
} | |
class GameModel implements Model { | |
@:constant var players:Mapping<Side,PlayerModel> = [ | |
for (side in [South, West, East]) | |
side => new PlayerModel({ side: side }) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment