Skip to content

Instantly share code, notes, and snippets.

@sanslan
Created April 23, 2022 18:38
Show Gist options
  • Save sanslan/e30afbcd62075ed93f25a2a2cadfab32 to your computer and use it in GitHub Desktop.
Save sanslan/e30afbcd62075ed93f25a2a2cadfab32 to your computer and use it in GitHub Desktop.
Test
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SlotCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'slot';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make a bet';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
private function calculatePayment(array $payouts)
{
$total = 0;
foreach ($payouts as $payout) {
switch ($payout) {
case 3:
$total += 0.2;
break;
case 4:
$total += 1;
break;
case 5:
$total += 5;
break;
}
}
return $total;
}
private function generateBoard(array $symbols, int $row_count, int $column_count): array
{
$arr = [];
for($i=0; $i < $row_count; $i++){
$row = [];
for($j=0; $j < $column_count; $j++){
$row[] = $symbols[array_rand($symbols)];
}
$arr[] = $row;
}
return $arr;
}
public function handle()
{
$symbols = [9, 10, 'J', 'Q','K', 'A', 'cat', 'dog', 'monkey' , 'bird'];
$board = $this->generateBoard($symbols,3,5);
$board = [['J', 'J', 'J', 'J', 'J'],['cat', 'J', 'Q', 'monkey', 'bird'],[ 'bird', 'bird', 'J', 'Q', 'A']];
$payouts = [];
foreach ($board as $row){
$match_count = 0;
$previous_symbol = null;
foreach ($row as $symbol){
if($previous_symbol && $symbol !== $previous_symbol){
break;
}
$previous_symbol = $symbol;
$match_count++;
}
if($match_count >= 3){
$payouts[] = $match_count;
}
}
if( $board[0][0] === $board[1][1] && $board[1][1] === $board[2][2]){
$payouts[] = 3;
}
if($payouts){
print_r($payouts) . PHP_EOL;
print_r($board);
echo $this->calculatePayment($payouts);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment