Jump to content

Some Math Help Needed


troy_mccormick

Recommended Posts

Alright...so I'm making this poker web site and I need a bit of help displaying the chips when a bet is made.  I currently am able to calculate how many of each denomination is needed to fulfill the bet, but I don't know how to go about displaying them.

 

My denominations are:

 

$1, $5, $25, $100, $1000, $5000, $25000, $100000

 

I then pass the bet amount to a function that provides me this information:

 

Array

(

    [1] => 0

    [5] => 1

    [25] => 0

    [100] => 7

    [1000] => 0

    [5000] => 0

    [25000] => 0

    [100000] => 0

)

 

This shows how many of each chip is needed to be displayed.  On the page for this to be displayed I have two rows of ten stacks.  Each stack contains six chips.  Stacks are labeled from 0 to 9 and chips are labeled from 0 to 5.

 

I have tried for loops and such but just can't seem to get it to work correctly.  Does anyone have any ideas?

 

Thanks a ton,

 

Troy

Link to comment
https://forums.phpfreaks.com/topic/37211-some-math-help-needed/
Share on other sites

I'm not real sure what you are asking. Assuming you have an image for each chip you could do this (where $bet is the array)

 

<?php
foreach ($bet as $chipValue => $chipCount) {
  if ($chipCount>0) {
    for ($i=0; $i<$chipCount; $i++) {
      echo '<img src="images\' . $chipValue . '.jpg" \>';
    }
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/37211-some-math-help-needed/#findComment-177770
Share on other sites

Ok....I guess I didn't explain very well.  Let me try again  :D

 

What you provided will just list out the chips.  Here is the setup I have:

 

If the bet was really big, I would have chips for all 60 positions:

 

<img class="chip_pos0-0" src="images/chips/d1.png" />
<img class="chip_pos0-1" src="images/chips/1.png" />
<img class="chip_pos0-2" src="images/chips/1.png" />
<img class="chip_pos0-3" src="images/chips/1.png" />
<img class="chip_pos0-4" src="images/chips/1.png" />
<img class="chip_pos0-5" src="images/chips/1.png" />

<img class="chip_pos1-0" src="images/chips/5.png" />
<img class="chip_pos1-1" src="images/chips/5.png" />
<img class="chip_pos1-2" src="images/chips/5.png" />
<img class="chip_pos1-3" src="images/chips/5.png" />
<img class="chip_pos1-4" src="images/chips/5.png" />
<img class="chip_pos1-5" src="images/chips/5.png" />

<img class="chip_pos2-0" src="images/chips/25.png" />
<img class="chip_pos2-1" src="images/chips/25.png" />
<img class="chip_pos2-2" src="images/chips/25.png" />
<img class="chip_pos2-3" src="images/chips/25.png" />
<img class="chip_pos2-4" src="images/chips/25.png" />
<img class="chip_pos2-5" src="images/chips/25.png" />

<img class="chip_pos3-0" src="images/chips/100.png" />
<img class="chip_pos3-1" src="images/chips/100.png" />
<img class="chip_pos3-2" src="images/chips/100.png" />
<img class="chip_pos3-3" src="images/chips/100.png" />
<img class="chip_pos3-4" src="images/chips/100.png" />
<img class="chip_pos3-5" src="images/chips/100.png" />

<img class="chip_pos4-0" src="images/chips/1000.png" />
<img class="chip_pos4-1" src="images/chips/1000.png" />
<img class="chip_pos4-2" src="images/chips/1000.png" />
<img class="chip_pos4-3" src="images/chips/1000.png" />
<img class="chip_pos4-4" src="images/chips/1000.png" />
<img class="chip_pos4-5" src="images/chips/1000.png" />

<img class="chip_pos5-0" src="images/chips/5000.png" />
<img class="chip_pos5-1" src="images/chips/5000.png" />
<img class="chip_pos5-2" src="images/chips/5000.png" />
<img class="chip_pos5-3" src="images/chips/5000.png" />
<img class="chip_pos5-4" src="images/chips/5000.png" />
<img class="chip_pos5-5" src="images/chips/5000.png" />

<img class="chip_pos6-0" src="images/chips/25000.png" />
<img class="chip_pos6-1" src="images/chips/25000.png" />
<img class="chip_pos6-2" src="images/chips/25000.png" />
<img class="chip_pos6-3" src="images/chips/25000.png" />
<img class="chip_pos6-4" src="images/chips/25000.png" />
<img class="chip_pos6-5" src="images/chips/25000.png" />

<img class="chip_pos7-0" src="images/chips/100000.png" />
<img class="chip_pos7-1" src="images/chips/100000.png" />
<img class="chip_pos7-2" src="images/chips/100000.png" />
<img class="chip_pos7-3" src="images/chips/100000.png" />
<img class="chip_pos7-4" src="images/chips/100000.png" />
<img class="chip_pos7-5" src="images/chips/100000.png" />

<img class="chip_pos8-0" src="images/chips/100000.png" />
<img class="chip_pos8-1" src="images/chips/100000.png" />
<img class="chip_pos8-2" src="images/chips/100000.png" />
<img class="chip_pos8-3" src="images/chips/100000.png" />
<img class="chip_pos8-4" src="images/chips/100000.png" />
<img class="chip_pos8-5" src="images/chips/100000.png" />

<img class="chip_pos9-0" src="images/chips/100000.png" />
<img class="chip_pos9-1" src="images/chips/100000.png" />
<img class="chip_pos9-2" src="images/chips/100000.png" />
<img class="chip_pos9-3" src="images/chips/100000.png" />
<img class="chip_pos9-4" src="images/chips/100000.png" />
<img class="chip_pos9-5" src="images/chips/100000.png" />

 

What I need to do is dynamically create the above code...

 

chip_pos(stack_num)-(chip_num)

 

Does that make more sense?

Link to comment
https://forums.phpfreaks.com/topic/37211-some-math-help-needed/#findComment-177773
Share on other sites

Hmm, still not 100% clear. Let me paraphrase what I understand. You have a bet which includes the number and denomination of the chips needed for the bet. The chips displayed must fit into a format of two rows, ten stacks each, and each stack can include up to 6 chips.

 

Ok, then my previous logic will work with a little tweaking for the display format.

 

Inthe following code I am placing the chips in table cells, but you can rework it if you are using DIVs or something else. The code will also continue to create multiple columns until all the chips have been dislayed.

 

<?php

$bet = array (
    '1' => 20,
    '5' => 1,
    '25' => 3,
    '100' => 7,
    '1000' => 20,
    '5000' => 30,
    '25000' => 18,
    '100000' => 0
);


$row   = 1; //Chip row: 1 or 2
$stack = 1; //Chip stack: 1 thru 10
$pos   = 1; //Chip position in the stack: 1 thru 6
$displayChips = true; //switch to controll too many chips from being displayed

echo "<table border='1'>\n";

foreach ($bet as $chipValue => $chipCount) {
  if ($chipCount>0) {

    for ($i=0; $i<$chipCount; $i++) {

      if ($displayChips) {

        //Check for new column or stack
        if($pos == 1) {
          if ($stack == 1) { //Create new row
            echo "<tr>\n";
          }
          //Create new stack
          echo "<td>\n";
        }

        //Show the chip
//        echo $chipValue . '<br>'; //For testing purposes
        echo '<img src="images/chips/' . $chipValue . '.png" \><br>';
        $pos++;

        //Change the values for position/column/row
        if ($pos>6) {
          echo "</td>\n";
          $pos = 1;
          $stack++;
        }
        if ($stack>10) {
          echo "</tr>\n";
          $stack = 1;
          $row++;
        }

       //Set switch if all positions have been filled to prevent
       //additional chips from being dislayed
       if ($row>2) { $displayChips = false; }

      }
    }
  }
}

//Close out TDs, TRs & TABLE
if ($pos!=1) { echo "</td>\n"; }
if ($stack!=1) { echo "</tr>\n"; }
echo "</table>\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/37211-some-math-help-needed/#findComment-177817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.