function rand_cols() { $auto_indexs = pick_rand_more(0, $this->num_cols - 1, $this->num_cols); foreach ($this->grid as &$line) { sort_by_indexs($line, $auto_indexs); } }
function rand_array_items(&$array, $opt = false) { $auto_index = pick_rand_more(0, count($array) - 1, count($array)); $copy = array(); foreach ($auto_index as $v) { $l = _drw($array)->eq($v, KEYS_VALS); //out1($v.'=>'.$l); if ($opt == true) { $copy[$l[0]] = $l[1]; } else { $copy[] = $l[1]; } } $array = $copy; }
/** * Hiển thị trò chơi * @param $opt1 * @param $opt2 */ public function show_game($opt1 = true, $opt2 = 'miss_items') { $view = '<table class="table" id="sudoku" border="1px solid gray" cellspadding=0 cellspacing=0 class="hwdoku-view">'; $items_hidden = ''; for ($i = 0; $i < $this->size; $i++) { $hide = pick_rand_more(0, $this->size - 1, pick_rand_number(1, $this->size - 1)); $tr = '<tr >'; for ($j = 0; $j < $this->size; $j++) { if (in_array($j, $hide)) { $items_hidden .= $i . '-' . $j . ','; $str = '<input onclick="hw_game.focus_item(this)" onBlur="hw_game._input_item_event(this)" class="hwdoku-hide" pos="' . $i . '-' . $j . '" value=""/>'; //$this->grid[$i][$j] } else { $str = $this->grid[$i][$j]; } $tr .= '<td width="50">' . $str . '</td>'; } $tr .= '</tr>'; $view .= $tr; } $view .= '</table>'; if ($opt1 == true) { echo $view; } $game1 = new HQ_Sudoku($this->size); $game1->grid = $this->grid; $game1->remove_item(explode(',', $items_hidden)); return $opt2 == 'miss_items' ? substr($items_hidden, 0, strlen($items_hidden) - 1) : $game1->grid; }