AS3 bingo game - impossible?
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3 bingo game - impossible?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    4

    AS3 bingo game - impossible?

    Hello everyone.

    I'm at a complete loss.

    I'm trying to generate random Bingo tickets, but I'm stuck right now. The point is, that have the following code:

    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;
    for (var i = 0; i<b.length/9; i++) {
        for (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;
    for (var k = 0; k<c.length/3; k++) {
        for (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;
    for (var m = 0; m<d.length/3; m++) {
        for (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;
    for (var o = 0; o<e.length/3; o++) {
        for (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;
    for (var q = 0; q<f.length/3; q++) {
        for (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;
    for (var s = 0; s<g.length/3; s++) {
        for (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:

    Untitled-1.jpg

    As you can see, I've got 162 cells divided into 9x3 tables. Each table contains 15 numbers and 12 empty spaces. All the numbers are between 1-90 and do not repeat. The positions of the numbers are random.

    The real problem is that I have to conform to a few rules:

    • The sum of the numbers in each table must be equal.
    • There are 9 columns, which must be arranged like so: first column 1-9, second column 10-19, third column 20-29, ... , ninth column 80-90.
    • Each row must have 4 spaces.


    What now? It seems impossible.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    Hello Jack-
    I am trying to follow your code, and understand what you really are wanting. All the bingo games I played were on a 5x5 board with a wild space in the middle. It looks like you are playing a slightly different type of bingo.

    If I were to approach the problem:
    1) I would start by creating arrays that hold the numbers for each columns (an array for 10's 20's 30's 40's etc)
    2) I would randomize the arrays like you are doing,
    3) I would create a single function that would populate each 9x3 box
    a) the rows are built by splicing from each array. (the first column is from 10s, second column from 20 etc)
    b) you need to use logic that for each row of nine, you will only place a number 5 times for each row and the other for will be blank spaces.
    c) you can force a column position to be a space, when that array is empty
    4) as far as the sum of numbers being equal in each table, I would need to think a little more about that. It seems like every time the number would always be 455. (I got that number by adding all the numbers from 1-90 and then dividing that by 9.)
    When you are building each row, you can start with a variable goalNumber:uint= 455, and then minus each cell from goalNumber for each row. When as you are in the final row, use logic to say if the goalNumber is Large, then pick a large # from the array for each column... or conversely if the goalNumber is small, you could choose a small number from each of the column arrays.

    I hope that helps- I have started by populating and randomizing the column arrays for you. Good luck!

    Code:
     var array10s:Array = []
    var array20s:Array = []
    var array30s:Array = []
    var array40s:Array = []
    var array50s:Array = []
    var array60s:Array = []
    var array70s:Array = []
    var array80s:Array = []
    var array90s:Array = []
    var array100s:Array = []
    
    for(var i:uint;i<99;i++){
    	//trace(i);
    	if(i<10){
    		array10s.push(i);
    	}
    	if(i<20&&i>=10){
    		array20s.push(i);
    	}
    	if(i<30&&i>=20){
    		array30s.push(i);
    	}
    	if(i<40&&i>=30){
    		array40s.push(i);
    	}
    	if(i<50&&i>=40){
    		array50s.push(i);
    	}
    	if(i<60&&i>=50){
    		array60s.push(i);
    	}
    	if(i<70&&i>=60){
    		array70s.push(i);
    	}
    	if(i<80&&i>=70){
    		array80s.push(i);
    	}
    	if(i<90&&i>=80){
    		array90s.push(i);
    	}
    	if(i<100&&i>=90){
    		array100s.push(i);
    	}
    }
    
    function shuffle(a,b):Number {
        var num:Number = Math.round(Math.random()*2)-2;
        return num;
    }
    
    array10s.sort(shuffle);
    array20s.sort(shuffle);
    array30s.sort(shuffle);
    array40s.sort(shuffle);
    array50s.sort(shuffle);
    array60s.sort(shuffle);
    array70s.sort(shuffle);
    array80s.sort(shuffle);
    array90s.sort(shuffle);
    array100s.sort(shuffle);
    
    trace(array10s,
    	  array20s,
    	  array30s,
    	  array40s,
    	  array50s,
    	  array60s,
    	  array70s,
    	  array80s,
    	  array90s,
    	  array100s);

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    4
    Thanks for your answer.

    I'll try to apply the hints and code you've given me.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com