//================================================================================================== // // the data and tension tester - 3.11.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) // //================================================================================================== ( //generate sourcetext. should be a string of unique letters, divided between four pages. ~txt = ""; ~charset = (0..255).select{|x| x.asAscii.isAlpha}.collect{|x| x.asAscii}; ~charset.do{|x| ~txt = ~txt++x}; ~txt = ~txt.scramble.clump(13); //register a new game with the text and an empty array of players. g = TDAT_Game.new(~txt, []); //generate unique rulesets for any number of players. current limit (due to characterset) = 13 ~rsetz = Dictionary.new!13; 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) }; //fork off routines so players can be asynchronous. ~routines = g.players.collect{|player, index| Routine({ loop({ player.turn; if(player.index > (~txt[player.page].size - 1), { player.index = ~txt[player.page].size-1 }); { ~word_boxes[index].string_(player.said.asString); ~page_boxes[index].string_(player.page.asString); ~window.refresh; }.defer; wait(0.5.rand); }) }) } ) //control all the routines at once: ~routines.do({|x| x.play}); ~routines.do({|x| x.stop});