diff options
author | emkael <emkael@tlen.pl> | 2014-07-03 02:26:04 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-07-03 02:26:04 +0200 |
commit | c4ae750bfe98c44188bf1fc52d3955e085b1e391 (patch) | |
tree | 1fc88d422c19e6d5e0e32d055ca54853730c5b1c /how.php |
initial commit
Diffstat (limited to 'how.php')
-rw-r--r-- | how.php | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,48 @@ +<?php + +$file = preg_split('/\*-+/', file_get_contents('howell.dat')); +$movements = []; +for ($i = 0; $i < count($file); $i++) { + if ($i%2) { + $matches = []; + preg_match_all('/(\d+)/', $file[$i], $matches); + $sets = array_fill(0, $rounds, 0); + $positions = []; + $table = 1; + $set = 0; + for ($j = 0; $j < count($matches[1]); $j++) { + if ((int)$matches[1][$j]) { + $sets[$set++] = $table++; + $positions[] = (int)($matches[1][$j++]); + $positions[] = (int)($matches[1][$j]); + } + else { + $sets[$set++] = 0; + } + } + $movement = []; + $lines = ['N','E']; + for ($j = $rounds; $j >= 1; $j--) { + $pos = array_search($j, $positions); + $movement[] = ceil(($pos+1)/2).$lines[$pos%2]; + } + $movements[$id] = [ + 'tables' => $tables, + 'rounds' => $rounds, + 'sets' => $sets, + 'movement' => $movement, + 'positions' => $positions + ]; + } + else { + $matches = []; + preg_match('/.*(-\d+).*RUNDY.*?(\d+).*STOLIKI.*/s', $file[$i], $matches); + $id = $matches[2].$matches[1]; + $tables = (int)($matches[2]); + $rounds = -(int)($matches[1]); + } +} + +file_put_contents('movements.json', json_encode($movements)); + +?>
\ No newline at end of file |