Skip to content
Snippets Groups Projects
Commit c4b62167 authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Start implementing how crosses are saved in database

parent a2446176
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -93,6 +93,51 @@ function unpack_scores($blob) {
return array_map(function($c) { return unpack('C', $c)[1]; }, str_split($blob));
}
function pack_crosses($crosses) {
$blob = '';
$byte = 0;
$i = 7;
foreach ($crosses as $bit) {
$byte |= intval($bit) << $i;
if ($i == 0) {
$blob .= chr($byte);
$byte = 0;
$i = 7;
} else {
$i--;
}
}
if ($i != 7)
$blob .= pack('C', $byte);
return $blob;
}
function unpack_crosses($bitmap, $limit=0) {
$crosses = array();
foreach($bitmap as $c) {
for ($i = 7; $i >= 0; $i--) {
$crosses[] = intval(!!(ord($c) & (1 << $i)));
if (count($crosses) == $limit)
return $crosses;
}
}
return $crosses;
}
function show_crosses($bitmap) {
foreach($bitmap as $c) {
for ($i = 7; $i >= 0; $i--)
echo intval(!!(ord($c) & (1 << $i)));
echo ' ';
}
echo "\n";
}
//show_crosses("\x0b\xff\x00\x08");
show_crosses(pack_crosses(array(1, 0, 1, 0, 0, 0, 0, 0)));
exit;
function match_arrows($row) {
return sprintf('%d &times; %d', $row->turns, $row->arrows);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment