AI 구현

This commit is contained in:
2020-04-13 02:45:24 +09:00
parent 598f12a90a
commit 3fd747febf
3 changed files with 327 additions and 1101 deletions
+22 -1
View File
@@ -284,6 +284,14 @@ class Util extends \utilphp\util
return $result;
}
public static function convertArrayToSetLike($arr){
$result = [];
foreach($arr as $datum){
$result[$datum] = $datum;
}
return $result;
}
public static function convertPairArrayToDict($arr){
$result = [];
foreach($arr as [$key, $val]){
@@ -308,7 +316,7 @@ class Util extends \utilphp\util
return $result;
}
public static function squeezeFromArray(array $dict, string $key){
public static function squeezeFromArray(array $dict, $key){
$result = [];
foreach($dict as $dictKey=>$value){
$result[$dictKey] = $value[$key];
@@ -586,6 +594,19 @@ class Util extends \utilphp\util
return $result;
}
public static function getKeyOfMaxValue(array $array){
$max = null;
$result = null;
foreach ($array as $key => $value) {
if ($max === null || $value > $max) {
$result = $key;
$max = $value;
}
}
return $result;
}
/**
* 배열의 아무거나 고름. Python의 random.choice()
*