prefix = $prefix;
$this->round = $round;
$this->board = $board;
$this->deals_by_tables = array();
if(!file_exists($this->get_filename())) {
throw new Exception('file not found: ' . $this->get_filename());
}
}
function get_filename() {
return $this->prefix . $this->round . 'b-' . $this->board . '.html';
}
function set_deal($table, $deal) {
$this->deals_by_tables[$table] = $deal;
}
function output() {
$content = file_get_contents($this->get_filename());
$modified = 0;
$dom = str_get_html($content);
$header_td1 = $dom->find("/html/body/table/tr/td[class=\"bdcc12\"]", 0);
$header_tr = $header_td1->parent;
$tr = @$header_tr->next_sibling();
while($tr) {
$td = $tr->find('td/a', 0);
$table = trim($td->innertext);
$table = str_replace(' ', '', $table);
$table = (int)$table;
if($table && array_key_exists($table, $this->deals_by_tables)) {
$contract1 = trim(str_replace(' ', '', $tr->find('td[class="bdc"]', 0)->innertext));
$score1 = trim(str_replace(' ', '', end($tr->find('td'))->innertext));
$contract2 = trim(str_replace(' ', '', $tr->next_sibling()->find('td[class="bdc"]', 0)->innertext));
$score2 = trim(str_replace(' ', '', end($tr->next_sibling()->find('td'))->innertext));
$deal = $this->deals_by_tables[$table];
$insert = "Stół $table – Rozdanie {$deal->deal_num}
";
// if is played on both tables of a match
// note that the contract field for arbitral scores starts with 'A' (e.g. 'ARB' or 'AAA')
if(($score1 !== '' || strpos($contract1, 'A') === 0)
&& ($score2 !== '' || strpos($contract2, 'A') === 0)) {
$insert .= $deal->html();
$modified = 1;
} else {
$insert .= '
...
'; } $tr->outertext = '
'.$suits[0].'
'.$suits[1].'
'.$suits[2].'
'.$suits[3];
return $str;
}
function format_ability($ability_num) {
$ability = $this->ability[$ability_num];
$ab = array($ability[0], $ability[2], $ability[3], $ability[4], $ability[5], $ability[6]);
foreach($ab as $k=>$v) {
switch($v) {
case 'A': $ab[$k] = '10'; break;
case 'B': $ab[$k] = '11'; break;
case 'C': $ab[$k] = '12'; break;
case 'D': $ab[$k] = '13'; break;
}
}
return "
$4 $5, $6', $minimax);
return $minimax;
}
}
function load_deals_for_tables($prefix, $round, $board_in_teamy) {
$deals_by_tables = array();
$prefix = preg_quote($prefix);
$filename_regex = "/$prefix-r$round-t(\d+)-b(\d+).pbn/";
foreach(scandir('.') as $filename) {
if(preg_match($filename_regex, $filename, $match)) {
$file_table = $match[1];
$file_start_board = $match[2];
// 1 in teamy -> 1 in pbn; 24 in teamy -> 1 in pbn; 25 in teamy -> 1 in pbn
$num_in_pbn = $board_in_teamy - $file_start_board + 1;
try {
$deal = new Deal($filename, $num_in_pbn);
$deals_by_tables[$file_table] = $deal;
} catch (NoSuchDealNumber $e) {
// ignore if the deal does not exist in the file
}
}
}
return $deals_by_tables;
}