Generate tambola (housie) game ticket using php

Tambola game logic :-


  • Tambola ticket consists 3 rows and 9 columns which makes 27 spaces. 
  •  Each row has a total 5 numbers printed and total 4 spaces are empty.
  • And column can have 1,2 or 3 numbers printed on it.
  • Number should not be repeat in each spaces.

Code :-

<?php
$numberOfRows = 3;          //decides number of rows
$totalNumber = 100;           //decides total number
$numberOfColoumn = 9;   // decides number of coloums
$emptySpace = 4;              // decides empty spaces 
$number = array_chunk(range(1,$totalNumber), 10);

$col1 = [];
$array1 = $number[0];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col1[$i] =  $array1[$randIndex1[$i]];
}
$col2 = [];
$array1 = $number[1];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col2[$i] =  $array1[$randIndex1[$i]];
}
$col3 = [];
$array1 = $number[2];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col3[$i] =  $array1[$randIndex1[$i]];
}
$col4 = [];
$array1 = $number[3];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col4[$i] =  $array1[$randIndex1[$i]];
}
$col5 = [];
$array1 = $number[4];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col5[$i] =  $array1[$randIndex1[$i]];
}
$col6 = [];
$array1 = $number[5];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col6[$i] =  $array1[$randIndex1[$i]];
}
$col7 = [];
$array1 = $number[6];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col7[$i] =  $array1[$randIndex1[$i]];
}
$col8 = [];
$array1 = $number[7];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col8[$i] =  $array1[$randIndex1[$i]];
}
$col9 = [];
$array1 = $number[8];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col9[$i] =  $array1[$randIndex1[$i]];
}
$col10 = [];
$array1 = $number[9];
$randIndex1 = array_rand($array1,$numberOfRows);
for ($i=0; $i < $numberOfRows; $i++) { 
$col10[$i] =  $array1[$randIndex1[$i]];
}

$arrayI = [];
$arrayJ = [];
$arrayK = [];

for($i = 0; $i < 1; $i++) { 
$j = 0;
$arrayI[$j] = $col1[$i];
$j++;
$arrayI[$j] = $col2[$i]; 
$j++;
$arrayI[$j] = $col3[$i];
$j++;
$arrayI[$j] = $col4[$i];
$j++;
$arrayI[$j] = $col5[$i];
$j++;
$arrayI[$j] = $col6[$i];
$j++;
$arrayI[$j] = $col7[$i];
$j++;
$arrayI[$j] = $col8[$i];
$j++;
$arrayI[$j] = $col9[$i];
$j++;
$arrayI[$j] = $col10[$i];
$j++;
}
for($i = 1; $i < 2; $i++) { 
$j = 0;
$arrayJ[$j] = $col1[$i];
$j++;
$arrayJ[$j] = $col2[$i]; 
$j++;
$arrayJ[$j] = $col3[$i];
$j++;
$arrayJ[$j] = $col4[$i];
$j++;
$arrayJ[$j] = $col5[$i];
$j++;
$arrayJ[$j] = $col6[$i];
$j++;
$arrayJ[$j] = $col7[$i];
$j++;
$arrayJ[$j] = $col8[$i];
$j++;
$arrayJ[$j] = $col9[$i];
$j++;
$arrayJ[$j] = $col10[$i];
$j++;
}
for($i = 2; $i < 3; $i++) { 
$j = 0;
$arrayK[$j] = $col1[$i];
$j++;
$arrayK[$j] = $col2[$i]; 
$j++;
$arrayK[$j] = $col3[$i];
$j++;
$arrayK[$j] = $col4[$i];
$j++;
$arrayK[$j] = $col5[$i];
$j++;
$arrayK[$j] = $col6[$i];
$j++;
$arrayK[$j] = $col7[$i];
$j++;
$arrayK[$j] = $col8[$i];
$j++;
$arrayK[$j] = $col9[$i];
$j++;
$arrayK[$j] = $col10[$i];
$j++;
}

$a = 1;
$b = 10;
for ($i=0; $i < $numberOfColoumn; $i++) { 
if($arrayI[$i] == $arrayJ[$i])
{
$arrayI[$i] = rand($a,$b);
}
elseif ($arrayJ[$i] == $arrayK[$i]) {
$arrayJ[$i] = rand($a,$b);
}
elseif ($arrayK[$i] == $arrayI[$i]) {
$arrayK[$i] = rand($a,$b);
}
$a = $a +10;
$b = $b + 10;
}
$rowOne = [];
$rowTwo = [];
$rowThree = [];
for ($i=0; $i < $numberOfColoumn; $i++) { 
$rowOne[$i] = $arrayI[$i];
$rowTwo[$i] = $arrayJ[$i];
$rowThree[$i] = $arrayK[$i];
}

for ($i=0; $i < $emptySpace; $i++) { 
$randIndex = array_rand($rowOne,$emptySpace);
$index1 = $randIndex[$i];
$rowOne[$index1] = "";
$randIndex = array_rand($rowTwo,$emptySpace);
$index1 = $randIndex[$i];
$rowTwo[$index1] = "";
$randIndex = array_rand($rowThree,$emptySpace);
$index1 = $randIndex[$i];
$rowThree[$index1] = "";
}
echo '<table border = "1">';
echo "<tr>";
for ($i=0; $i < 9; $i++) { 
echo "<td>";
print_r($rowOne[$i]);
echo "</td>";
}

echo "</tr>";
echo "<tr>";
for ($i=0; $i < 9; $i++) { 
echo "<td>";
print_r($rowTwo[$i]);
echo "</td>";
}
echo "</tr>";
echo "<tr>";
for ($i=0; $i < 9; $i++) { 
echo "<td>";
print_r($rowThree[$i]);
echo "</td>";
}
echo "</tr>";
echo "</tr>";
echo "</table>";

Output :-

                                                       Generated Tambola Ticket 

Comments

  1. Nice Blog!

    I Like to play online or mobile games specially Tambola Game, it is really interesting game.

    ReplyDelete
  2. Are you Planning to Play Tambola Housie with your colleagues, friends and family sitting in any corner of the Home. Play Online Tambola games and Bring your virtual team members together, build stronger connections.

    ReplyDelete

Post a Comment

If you have any doubts, Please let me know

Popular posts from this blog

How to create website using HTML, JS, PHP and CSS

Add backend validation in wordpress using php