2 Replies - 328 Views - Last Post: 28 October 2013 - 05:02 PM

#1 EdNolan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 249
  • Joined: 22-September 13

Odds of whats left in cloneArray - I need advise

Posted 27 October 2013 - 06:26 PM

I'm trying to figure out how to do 2 things. The first thing I need advise on is if I should put this list in an array. It's a list of the odds. I determine the odds, by what is inside the shownImages array. An explanation of the list is as follows...
No of images found-group.........images left for group.......total images to pick from...........odds
...................0..................................... 4................./..................43............................. 10:1
...................1..................................... 3................./..................43............................. 14:1
...................2..................................... 2................./..................43............................. 21:1
...................3..................................... 1................./..................43............................. 43:1
...................0..................................... 0................./..................43............................. 0:0
The odds would be displayed and then the program would pickAgain() reducing the total images from 43 to 42 for the next turn. A total of 13 groups would have to be checked for this above, and consecutive turns.

Here's a list of the odds for two turns.

0....4/43...10:1 // The shownImages array holds a list of images that have already been randomly selected and
1....3/43...14:1 // displayed. Each image is numbered like, "1.png", "2.png", "3.png", "4.png",
2....2/43...21:1 // "5.png", "6.png", "7.png"... Here's the tricky part. Four images make up one group.
3....1/43...43:1 // I don't want to confuse you so please know going forward that I don't want to code the
4....0/43...0:0 // groups. I want to keep the groups as a sort of mental note for coding what I need.
//
0....4/42...10:1 // Group one would actually consist of "1.png", "2.png", "3.png", "4.png". Group two would
1....3/42...13:1 // consist of "5.png", "6.png", "7.png", 8.png", and so on.
2....2/42...22:1 // As the code below randomly selects a picture it gets displayed and is pushed to
3....1/42...42:1 // var shownImages = []; So what I want to do now is look inside shownImages and count
4....0/42...0:0 // if "1.png", "2.png", "3.png", "4.png" are there, and if so, how many of group one are there.

Lets say we found for group one, 2 entries, say it's "1.png", and "4.png". The odds for group one would then be 21:1 for the next turn. Lets say we found for group two, 1 entry, "6.png". The odds for group two would then be 14:1.

The odds list is long.
1). Do I put the list in an array and have the code check the array. If so this would be the first multiple array I have ever written. Can you give me an example of how to write it.
2). I am not sure but I wrote this and am wondering if this is how I should write it?
3). I am using log as an example. I actually want to diplay it on screen somehow. Would I be able to use something like
document.body.appendChild(text); to display the information?
4). Would it be better and would it work if this part of the code is written and saved as a separate bit of code and called when needed or should I add it within pickAgain()?
5). Or can I somehow add 13 compartments to shownImages and have the images go to their compartment when randomly picked, making counting them later easier? If so how do I add the compartments and I am guessing I will have to make changes to the finished code below to sort the random image to the correct compartment. What would I have to edit?
 I am thinking a compartment might be something like this...
shownImages [0][0] // holds 1-4.png
shownImages [0][1] // holds 5-8.png
shownImages [0][2] // holds 9-12.png
shownImages [0][3] // holds 13-16.png
shownImages [0][4] // holds 17-20.png
shownImages [0][5] // holds 21-24.png
shownImages [0][6] // holds 25-28.png
shownImages [0][7] // holds 29-32.png
shownImages [0][8] // holds 33-36.png
shownImages [0][9] // holds 37-40.png
shownImages [0][10] // holds 41-44.png
shownImages [0][11] // holds 45-48.png
shownImages [0][12] // holds 49-52.png



var count1 = {      // Would this be the best way to make the object array?
  found0: '10:1',   // This would be looped for the 13 groups. the count1 is actually the first turn in the game.
  found1: '14:1',   // after the first 9 images are displayed the odds are calculated and shown to the player
  found2: '21:1',   // for the 13 different groups. So, this code would actually be inserted within the pickAgain()
  found3: '43:1',   // I would have to display the 13 groups as well as the images that are currently being displayed.
  found4: '0:0',    // These are the odds for the first turn of play.
   doSomething : function() {...}  
}  
console.log(count1.x,x,x,x,x,x,x,x,...); // group 1 14:1  group 2 43:1  group 3 14:1   group 4 10:1 ... group 13 21:1

// I am using log as an example. I actually want to diplay it on screen somehow. Would I be able to use something like
//          document.body.appendChild(text);  to display the information?

var count27 = [   
  {found0: '4:1'},
  {found1: '5:1'},    // These are the odds for the last turn of play
  {found2: '8:1'},
  {found3: '16:1'},
  {found4: '0:0'},
   doSomething : function() {...}  
];  
console.log(count27.x,x,x,,x,x); // group1...group2...group3...



Here is the code it will go into.
<script type="text/javascript">

var imgArray = ["1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png", 
"11.png", "12.png", "13.png", "14.png", "15.png", "16.png", "17.png", "18.png", "19.png", 
"20.png", "21.png", "22.png", "23.png", "24.png", "25.png", "26.png", "27.png", "28.png", "29.png", 
"30.png", "31.png", "32.png", "33.png", "34.png", "35.png", "36.png", "37.png", "38.png", "39.png"];
           //make a clone of imgArray

var basePath = "///C:/Users/Dads/Desktop/game/";  // This is the file location of all the card images.

function imgRandom() {          // This is the main program.
var clone = imgArray.slice(0);  // We are copying imgArray and will use clone as our working array.
for (i = 0; i < 9; i++) {       // We need our first nine images of the game, this is the start of our loop.
        var i, rand, image;     // These are just some of the variables used in the program
        var shownImages = [];   // I made an empty array that will store each image picked, serves as a record.
var randIndex = Math.floor(Math.random() * clone.length);  // We randomly pick from clone array here.
var rand = clone[randIndex];    // Our image is now known as rand and it's location in the clone array is known as randIndex
        image = new Image();    // or new Image(144, 192); // Here wa are telling the computer we are going to show a new image.
        image.src = basePath + rand;  // Now we have to tell the program to take the random image now called rand from the folder.
        shownImages.push(rand);  // Now I am writing(push) a record of the image(rand). Im putting(push) it in the shownImages array
//        console.log(shownImages[0])
        image.width = 54;        // This sets the images display size that players see on their screens.
        image.height = 72;       // This sets the images display size that players see on their screens.
        document.body.appendChild(image);  // This actually puts the images onto the page as a new image.
clone.splice(randIndex,1);      // This will cut out the image/index from the clone array to avoid duplicates.
}

picAgain()
// I NEED TO DISPLAY THE ODDS FOR EACH TURN OF PLAY NOW !!!
function picAgain(limit) {
    var count = 0;
    function liveCount() {
        count += 1
        if (count <= 28) {    // There are a total of 28 turns of play
var randIndex = Math.floor(Math.random() * clone.length);
var rand = clone[randIndex];
        image = new Image();    // or new Image(144, 192);
        image.src = basePath + rand;
        shownImages.push(rand);
//        console.log(shownImages[0])
        image.width = 54;
        image.height = 72;
        document.body.appendChild(image);
clone.splice(randIndex,1);
        } else{
            clearInterval();
        }
    }
    var counter = setInterval(liveCount, 3000);
}
}  // This ends imgRandom

imgRandom()
        </script>


This post has been edited by EdNolan: 27 October 2013 - 07:59 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Odds of whats left in cloneArray - I need advise

#2 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,829
  • Joined: 30-April 10

Re: Odds of whats left in cloneArray - I need advise

Posted 28 October 2013 - 09:53 AM

I really don't understand what you are asking here.
Was This Post Helpful? 0
  • +
  • -

#3 EdNolan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 249
  • Joined: 22-September 13

Re: Odds of whats left in cloneArray - I need advise

Posted 28 October 2013 - 05:02 PM

Say I have entries in my shownImages array [1.png, 12.png, 30.png, 15.png, 2.png, 8.png, 19.png, 11.png. 25.png],
I would like to iterate the array, and add certain entries together to come up with a certain value for the group.
I then want to iterate an odds array (that needs to be created) to set the odds for the group.
How do I iterate the shownImages ()? My attempt doesn't work!

0    4/43   10:1
1    3/43   14:1    This is part of the odds chart that would have to be made into an array and iterated.
2    2/43   21:1
3    1/43   43:1
4    0/43   0:0

var groupOne = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 1.png)
       { groupOne++; }
    if(shownImages[i] == 2.png)
       { groupOne++; }
    if(shownImages[i] == 3.png)
       { groupOne++; }
    if(shownImages[i] == 4.png)
       { groupOne++; }
} //  groupOne = 2 entries so I would hope my code displays, groupOne odds eqauls 21:1


var groupTwo = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 5.png)
        { groupTwo++; }
    if(shownImages[i] == 6.png)
        { groupTwo++; }
    if(shownImages[i] == 7.png)
        { groupTwo++; }
    if(shownImages[i] == 8.png)
        { groupTwo++; }
} //  groupTwo = 1 entry so I would hope my code displays, groupTwo odds eqauls 14:1

var groupThree = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 9.png)
        { groupThree++; }
    if(shownImages[i] == 10.png)
        { groupThree++; }
    if(shownImages[i] == 11.png)
        { groupThree++; }
    if(shownImages[i] == 12.png)
        { groupThree++; }
} //  groupThree = 1 entry so I would hope my code displays, groupThree odds eqauls 21:1

var groupFour = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 13.png)
        { groupFour++; }
    if(shownImages[i] == 14.png)
        { groupFour++; }
    if(shownImages[i] == 15.png)
        { groupFour++; }
    if(shownImages[i] == 16.png)
        { groupFour++; }
} //  groupFour = 1 entry so I would hope my code displays, groupFour odds eqauls 21:1

var groupFive = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 17.png)
        { groupFive++; }
    if(shownImages[i] == 18.png)
        { groupFive++; }
    if(shownImages[i] == 19.png)
        { groupFive++; }
    if(shownImages[i] == 20.png)
        { groupFive++; }
} //  groupFive = 1 entry so I would hope my code displays, groupFive odds eqauls 21:1

var groupSix = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 21.png)
        { groupSix++; }
    if(shownImages[i] == 22.png)
        { groupSix++; }
    if(shownImages[i] == 23.png)
        { groupSix++; }
    if(shownImages[i] == 24.png)
        { groupSix++; }
}} //  groupSix = 0 entries so I would hope my code displays, groupSix odds eqauls 10:1

var groupSeven = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 25.png)
        { groupSeven++; }
    if(shownImages[i] == 26.png)
        { groupSeven++; }
    if(shownImages[i] == 27.png)
        { groupSeven++; }
    if(shownImages[i] == 28.png)
        { groupSeven++; }
} //  groupSeven = 1 entries so I would hope my code displays, groupSeven odds eqauls 21:1

var groupEight = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 29.png)
        { groupEight++; }
    if(shownImages[i] == 30.png)
        { groupEight++; }
    if(shownImages[i] == 31.png)
        { groupEight++; }
    if(shownImages[i] == 32.png)
        { groupEight++; }
} //  groupEight = 1 entries so I would hope my code displays, groupEight odds eqauls 21:1

var groupNine = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 33.png)
        { groupNine++; }
    if(shownImages[i] == 34.png)
        { groupNine++; }
    if(shownImages[i] == 35.png)
        { groupNine++; }
    if(shownImages[i] == 36.png)
        { groupNine++; }
} //  groupNine = 0 entries so I would hope my code displays, groupNine odds eqauls 10:1

var groupTen = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 37.png)
        { groupTen++; }
    if(shownImages[i] == 38.png)
        { groupTen++; }
    if(shownImages[i] == 39.png)
        { groupTen++; }
    if(shownImages[i] == 40.png)
        { groupTen++; }
} //  groupTen = 0 entries so I would hope my code displays, groupTen odds eqauls 10:1

var groupEleven = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 41.png)
        { groupEleven++; }
    if(shownImages[i] == 42.png)
        { groupEleven++; }
    if(shownImages[i] == 43.png)
        { groupEleven++; }
    if(shownImages[i] == 44.png)
        { groupEleven++; }
} //  groupEleven = 0 entries so I would hope my code displays, groupEleven odds eqauls 10:1

var groupTwelve = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 45.png)
        { groupTwelve++; }
    if(shownImages[i] == 46.png)
        { groupTwelve++; }
    if(shownImages[i] == 47.png)
        { groupTwelve++; }
    if(shownImages[i] == 48.png)
        { groupTwelve++; }
} //  groupTwelve= 0 entries so I would hope my code displays, groupTwelve odds eqauls 10:1

var groupThirteen = 0;
for(var i = 0; i < shownImages.length; i++){
    if(shownImages[i] == 49.png)
        { groupThirteen++; }
    if(shownImages[i] == 50.png)
        { groupThirteen++; }
    if(shownImages[i] == 51.png)
        { groupThirteen++; }
    if(shownImages[i] == 52.png)
        { groupThirteen++; }
} //  groupThirteen = 0 entries so I would hope my code displays, groupThirteen odds eqauls 10:1


This post has been edited by EdNolan: 28 October 2013 - 05:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1