arrays - AS3 bingo game - is it possible? -


i'm @ complete loss.

i'm trying generate random bingo tickets, i'm stuck right now. point is, have following code:

var startnum:number = 1; var endnum:number = 90; var rp:randomplus = new randomplus(endnum, startnum);  var variant_1:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");  var variant_2:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");  var variant_3:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");  var variant_4:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");  var variant_5:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");  var variant_6:array = new array                     (rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(), rp.getnum(),                       "", "",  "", "",  "", "", "", "", "", "", "", "");    function shuffle(a, b):number {     var num:number = math.round(math.random()*2)-2;     return num; }   var b:array = variant_1.sort(shuffle); var cnt:uint=0; (var = 0; i<b.length/9; i++) {     (var j = 0; j<b.length/3; j++) {         var grid1:box=new box();         grid1.x=5+(grid1.width-1)*j;         grid1.y=5+(grid1.height-1)*i;         grid1.txt.text=b[cnt];         addchild(grid1);         cnt++;     } }  var c:array = variant_2.sort(shuffle); var cnt2:uint=0; (var k = 0; k<c.length/3; k++) {     (var l = 0; l<c.length/9; l++) {         var grid2:box=new box();         grid2.x=5+(grid2.width-1)*k;         grid2.y=100+(grid2.height-1)*l;         grid2.txt.text=c[cnt2];         addchild(grid2);         cnt2++;     } }  var d:array = variant_3.sort(shuffle); var cnt3:uint=0; (var m = 0; m<d.length/3; m++) {     (var n = 0; n<d.length/9; n++) {         var grid3:box=new box();         grid3.x=5+(grid3.width-1)*m;         grid3.y=200+(grid3.height-1)*n;         grid3.txt.text=d[cnt3];         addchild(grid3);         cnt3++;     } }  var e:array = variant_4.sort(shuffle); var cnt4:uint=0; (var o = 0; o<e.length/3; o++) {     (var p = 0; p<e.length/9; p++) {         var grid4:box=new box();         grid4.x=5+(grid4.width-1)*o;         grid4.y=300+(grid4.height-1)*p;         grid4.txt.text=e[cnt4];         addchild(grid4);         cnt4++;     } }  var f:array = variant_5.sort(shuffle); var cnt5:uint=0; (var q = 0; q<f.length/3; q++) {     (var r = 0; r<f.length/9; r++) {         var grid5:box=new box();         grid5.x=5+(grid5.width-1)*q;         grid5.y=400+(grid5.height-1)*r;         grid5.txt.text=f[cnt5];         addchild(grid5);         cnt5++;     } }  var g:array = variant_6.sort(shuffle); var cnt6:uint=0; (var s = 0; s<g.length/3; s++) {     (var t = 0; t<g.length/9; t++) {         var grid6:box=new box();         grid6.x=5+(grid6.width-1)*s;         grid6.y=500+(grid6.height-1)*t;         grid6.txt.text=g[cnt6];         addchild(grid6);         cnt6++;     } } 

which outputs this:

bingo can see, i've got 162 cells divided 9x3 tables. each table contains 15 numbers , 12 empty spaces. numbers between 1-90 , not repeat. positions of numbers random.

the real problem have conform few rules:

  • the sum of numbers in each table equal.
  • there 9 columns, must arranged so: first column 1-9, second column 10-19, third column 20-29, ... , ninth column 80-90.
  • each row has 4 spaces.

what now? seems impossible.

you should improve code. don't need variable each variant, can using bidimensional array. this:

var tables:array = new array();  for(var i:uint = 0; <= 6; 6++){     tables[i] = filltable();     drawtables(tables); }  ...  function filltable():array{     var emptyspaces:array = new array();     var tabledata:array   = new array();     emptyspaces = getrandomelements(); //this function should return array represent 12 empty spaces, otherwise, 12 numbers between 0 , 26     (var = 0; <= 27; i++) {        if(emptyspaces.indexof(i) < 0){ // if current isn't empty space give value            tabledata[i] = generaterandombasedonindex(i);        }    } }  function generaterandombasedonindex(i):uint{     var maxint = (i+1) * 10 - 1;     var minint = math.abs(maxint + 1 - 9);      return new randomplus(maxint, minint).getnum(); }  function getrandomelements():array{     // todo - homework :) }  function drawtables(tabledata:array):void{     // use tabledata array place yours display objects on stage } 

why need sum of number equal on tables? rule? don't think happens in real life bingos.

ps.: don't have actionscript editor here, may find syntax error, give in these lines, think logic should work fine.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -