/** * decode_board() - Convert between coded GET parameter and $board_array * encode_board() */ function decode_board($board_coded) { $ret = new_board(); $length = strlen($board_coded); for ($i = 0; $i < $length; $i += 2) { $piece = substr($board_coded, $i, 1); $code = substr($board_coded, $i + 1, 1); $p = strpos(LOCATION_CODES, $code); $col = $p % 8; $row = ($p - $col) / 8; $ret[$row][$col] = $piece; } return $ret; }
/** * hot_fields() */ function hot_fields($board_array, $current_player) { $ret = array(); $hot_array = new_board(); $movable_opponents = find_movable_pieces($board_array, !$current_player); foreach ($movable_opponents as $from_field) { $possible_moves = possible_move_list($board_array, !$current_player, $from_field); foreach ($possible_moves as $to_field) { list($row, $col) = field_to_rowcol($to_field); $hot_array[$row][$col] = 'not empty'; } } for ($row = 0; $row < 8; $row++) { for ($col = 0; $col < 8; $col++) { if ($hot_array[$row][$col] == 'not empty') { $ret[] = rowcol_to_field($row, $col); } } } return $ret; }