//======================================================================================== // // the data and tension - 3.10.09 Joe Mariglio // //----------------------------------------------------------------------------------------- // // this library is for simulating tests of tdat rulesets and sourcetexts. // it should do so sonically. // // TDAT_Player : a single player. // each player has a potentially unique ruleset // players in the same game 'listen' for trigger words from each other, // changing state accordingly // turns may be taken synchronously or asynchronously, that's up to you. // // TDAT_Game : a game instance. // //========================================================================================= TDAT_Game { var <>txt, //-------> array of strings <>players; //--> array of TDAT_Players *new {| txt, players | ^super.newCopyArgs( txt ?? [""], players ?? [] ).initGame } initGame { players.do{_.game_(this)} } addPlayer {| player | if (players.includes(player).not, { players = players.add(player); }); } } TDAT_Player { var <>game, //-------> TDAT_Game <>rules, //-------> Dictionary <>page, //-------> Integer <>index, //-------> Integer <>said; //-------> 'word', at this point a Char *new {| game, rules, page, index | ^super.newCopyArgs( game ? {TDAT_Game.new}, rules ? {Dictionary.new}, page ? 0, index ? 0 ).initPlayer } initPlayer { game.addPlayer(this) } hear {| input | var state = rules.at(input); if (state.notNil, { if(state!=page, { page = state; index = 0; }); }); } readNext {| txt, pg, in | ^txt[pg][in] } others { ^game.players.reject({|x| x==this}) } speak {| word | this.others.do({| player | player.hear(word) }); said = word; //"player index: ".post; // game.players.indexOf(this).postln; // "page index: ".post; // this.page.postln; // "word: ".post; // word.postln; } turn { var txt = this.game.txt; var word = this.readNext(txt, page, index); index = index + 1; this.speak(word.asString); } }