Last active
October 27, 2022 15:54
-
-
Save katsube/a4cc7a216f570bfbf97e76511540b781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// オセロ盤のデータを入れる配列 | |
$OTHELLO_BOARD = [ | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 2, 0, 0], | |
[0, 0, 0, 1, 2, 1, 0, 0], | |
[0, 0, 1, 1, 2, 0, 0, 0], | |
[0, 0, 0, 0, 2, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0] | |
]; | |
// 表示用データに変換する | |
// ★ここを回答する(その1)★ | |
// 表示する | |
// ★ここを回答する(その2)★ | |
/** | |
* 表示用データに変換する | |
* | |
* 0 ... 空白 | |
* 1 ... 黒(o) | |
* 2 ... 白(x) | |
*/ | |
function convertDisplayData($board, $blank=' ', $white='o', $black='x'){ | |
$newboard = [ ]; | |
for($i=0; $i<count($board); $i++){ | |
$newboard[$i] = [ ]; | |
for($j=0; $j<count($board[$i]); $j++){ | |
switch($board[$i][$j]){ | |
case 0: | |
$newboard[$i][$j] = $blank; | |
break; | |
case 1: | |
$newboard[$i][$j] = $white; | |
break; | |
case 2: | |
$newboard[$i][$j] = $black; | |
break; | |
} | |
} | |
} | |
return( $newboard ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment