//================================================================================================== // // the data and tension tester - 3.17.09 Joe Mariglio // //-------------------------------------------------------------------------------------------------- // // this script tests iterations of TDAT and displays the results to a hideous GUI. // rulesets / sourcetexts are represented by strings of chars, which may be mapped to *anything*. // rulesets / sourcetexts are generated with pseudorandom numbers but may (and probably should) // be tuned by hand to acheive the desired dynamic. // number of players is currently 2 - 13 but this could increase theoretically (god help us) // //================================================================================================== //get all the texts from directory names, place them into an array of texts ( ~pipe = Pipe.new("ls /Users/josephmariglio/Documents/Classes/Spring09/tdat_tests/longevity/", "r"); ~line = ~pipe.getLine; ~txt_array = []; while({ ~line.notNil }, {~line.postln; ~txt_array = ~txt_array ++ [~line]; ~line = ~pipe.getLine; }); ~pipe.close; ) ( ~charset = (0..255).select{|x| x.asAscii.isAlpha}.collect{|x| x.asAscii}; ~src = ~txt_array[12][..51]; ~txt = ~src.clump(13); ~limit = 10; //register a new game with the text, an empty array of players, and a turn limit g = TDAT_Game.new(~txt, [], ~limit); //generate unique rulesets for any number of players. current limit (due to characterset) = 13 ~rsetz = Dictionary.new!4; k = 0; ~rsetz.do{|player, i| ~txt.do{|page, j| ~rsetz[i].add(~charset[k].asString -> j); k = k + 1; } }; //register one player for each ruleset and add them to the game ~rsetz.do{|rulz| TDAT_Player.new(g, rulz, 0, 0) }; //GUI stuff. draws a hideous window full of text. ~window = GUI.window.new("tdat").front.view.background_(Color.white); ~word_label = GUI.staticText.new(~window, Rect(10, 10, 80, 40)).string_("words:").font_(Font("Monaco", 20)); ~word_boxes = g.players.collect{|player, index| GUI.staticText.new(~window, Rect(index*80 + 80, 10, 70, 70)).font_(Font("Monaco", 48)); }; ~page_label = GUI.staticText.new(~window, Rect(10, 90, 80, 40)).string_("pages:").font_(Font("Monaco", 20)); ~page_boxes = g.players.collect{|player, index| GUI.staticText.new(~window, Rect(index*80 + 80, 90, 70, 70)).font_(Font("Monaco", 48)); }; ~text_label = GUI.staticText.new(~window, Rect(10, 170, 90, 20)).string_("texts:").font_(Font("Monaco", 20)); ~texts = ~txt.collect{|page, index| GUI.staticText.new(~window, Rect(10, (40 * index) + 200, 300, 40)) .font_(Font("Monaco", 24)) .string_(index.asString++":"++(9.asAscii)++page) }; //Analysis stuff. g.initMatrix; g.initStops; //fork off routines so players can be asynchronous. ~routines = g.players.collect{|player, index| Routine({ loop({ player.turn; { ~word_boxes[index].string_(player.said.asString); ~page_boxes[index].string_(player.page.asString); if (player.stopped, { ~word_boxes[index].string_(Char.bullet.asString); }); ~window.refresh; }.defer; wait((1/64).exprand(1/128)); }) }) }; ) //control all the routines at once: ~routines.do({|x| x.play}); //to analyze lengths of games started by players ( ~player_avg0 = []; ~player_avg1 = []; ~player_avg2 = []; ~player_avg3 = []; ) //run each game manually and add length score to array g.players[0].jumpTo((~txt.size-1).rand); ~player_avg0 = ~player_avg0 ++ (g.turns / g.players.size); ~routines.do({|x| x.stop}); //write output file g.wTranMatFile("/Users/josephmariglio/Documents/Classes/Spring09/tdat_tests/longevity/"++~src++"_directory/"++"transition_matrix");