<?php

namespace freedom\utils;

class RouletteUtil
{
    /**
     * 分析统计 分析结果 控制端传入一个数 方法对其分析 输出结果
     * @param $result
     * @return array
     */
    public static function parseCount($result): array
    {
        $returnArray = [];

        if ($result != 0) {
            if ($result >= 1 && $result <= 18) {
                $returnArray[] = 'low';
            }
            if ($result >= 19 && $result <= 36) {
                $returnArray[] = 'high';
            }
            if ($result % 2 == 0) {
                $returnArray[] = 'even';
            } else {
                $returnArray[] = 'odd';
            }
            if(in_array($result,[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])){
                $returnArray[] = 'red';
            }
            if(in_array($result,[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35])){
                $returnArray[] = 'black';
            }
        } else {
            $returnArray[] = 'zero';
        }
        return $returnArray;
    }

    /**
     * 统计自增方法
     * @param $beforeCountArray
     * @param $afterCountArray
     * @return int[]
     */
    public static function countInc($beforeCountArray, $afterCountArray): array
    {
        if (empty($beforeCountArray)){
            $beforeCountArray = ['low' => 0, 'high' => 0, 'odd' => 0, 'even' => 0, 'red' => 0, 'black' => 0, 'zero' => 0];
        }
        foreach ($beforeCountArray as $k => $v){
            if (in_array($k, $afterCountArray)){
                $beforeCountArray[$k] = $v + 1;
            }
        }
        return $beforeCountArray;
    }


    /**
     * 分析结果 控制端传入一个数 方法对其分析 输出结果
     * @param $resultArray
     * @return array
     */
    public static function parseResult($result): array
    {
        // 返回数组
        $returnArray = [];
        $returnArray[] = 'straight_'.$result;
        if ($result != 0) {
            if ($result >= 1 && $result <= 18) {
                $returnArray[] = 'low';
            }
            if ($result >= 19 && $result <= 36) {
                $returnArray[] = 'high';
            }
            if ($result % 2 == 0) {
                $returnArray[] = 'even';
            } else {
                $returnArray[] = 'odd';
            }
            if (in_array($result,[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])) {
                $returnArray[] = 'red';
            }
            if (in_array($result,[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35])) {
                $returnArray[] = 'black';
            }
            if (in_array($result,[1,4,7,10,13,16,19,22,25,28,31,34])) {
                $returnArray[] = 'column_1';
            }
            if (in_array($result,[2,5,8,11,14,17,20,23,26,29,32,35])) {
                $returnArray[] = 'column_2';
            }
            if (in_array($result,[3,6,9,12,15,18,21,24,27,30,33,36])) {
                $returnArray[] = 'column_3';
            }
            if ($result >= 1 && $result <= 12) {
                $returnArray[] = 'dozen_1';
            }
            if ($result >= 13 && $result <= 24) {
                $returnArray[] = 'dozen_2';
            }
            if ($result >= 25 && $result <= 36) {
                $returnArray[] = 'dozen_3';
            }
        }
        return $returnArray;
    }

    /**
     * 下注额自增方法
     * @param $beforeAmountArray
     * @param $afterAmountArray
     * @return array
     */
    public static function amountInc($beforeAmountArray, $afterAmountArray): array
    {
        $returnArray = [];
        foreach ($afterAmountArray as $k => $v){
            if (array_key_exists($k, $beforeAmountArray)){
                $returnArray[$k] = $beforeAmountArray[$k] + $v;
                unset($beforeAmountArray[$k]);
            } else {
                $returnArray[$k] = $v;
            }
        }
        return $returnArray + $beforeAmountArray;
    }
}