Ejemplo n.º 1
0
 function scanRows()
 {
     for ($y = 0; $y < $this->rows; $y++) {
         print "---[ start:results ]---\n";
         print_r(findWinner($this->layout[$y], $y, 'x', 'o'));
         print "---[ end:results ]---\n";
     }
 }
Ejemplo n.º 2
0
/**
*Controls card game
* @param array $players list of 
*
* @return void
*/
function playCardGame($players, $num_cards)
{
    //Create assoc. array for players and their scores w/ empty array for their hands
    $playersList = [];
    foreach ($players as $player) {
        $playersList[$player] = array('score' => 0, 'hand' => array());
    }
    //create a deck
    $new_deck = getDeck();
    //Initiate round counter
    $round = 1;
    //Play rounds while there are enough cards in deck to do so
    while (count($players) * $num_cards <= count($new_deck)) {
        gameRound($playersList, $num_cards, $new_deck, $round);
        $round++;
    }
    //Figure out who won and print to screen
    $winner = findWinner($playersList);
    echo "<h3>The Winner is: " . $winner . "</h3>";
}
Ejemplo n.º 3
0
 function scanDiagonalsGravelyForWin()
 {
     $a_tmp_column = array();
     $a_winning_set = array();
     $start_rows = $this->rows - matchLength();
     $end_rows = $this->rows - 1;
     $start_cols = 0;
     $end_cols = $this->columns - 1;
     $max_cols = matchLength() - 1;
     $y = $start_cols;
     $x = $start_rows;
     $i_max = $this->rows * $this->columns;
     $outer_x = $x;
     $outer_y = $y;
     $a_coords = array();
     $i = 0;
     $j = 0;
     while ($outer_y <= matchLength()) {
         while ($x <= $end_rows && $x >= 0 && $outer_y <= $max_cols && $y <= $end_cols) {
             if ($j == 0) {
                 $s_start = "start_y = {$y} start_x = {$x}<br/>\n";
                 $i_start_x = $x;
                 $i_start_y = $y;
             }
             $s_end = "end_y = {$y} end_x = {$x}<br/>\n";
             $i_end_x = $x;
             $i_end_y = $y;
             $a_tmp_column[] = $this->layout[$x][$y];
             $a_coords[] = "{$x}:{$y}";
             $y++;
             $x++;
             $j++;
         }
         $j = 0;
         $a_winning_set = findWinner($a_tmp_column, $i, $this->x, $this->o, 'gravely');
         // find first value filled in a_tmp_column
         if (is_array($a_winning_set)) {
             // TODO: should I use i_pad to increment? hell ya
             $p_limit = count($a_tmp_column);
             for ($p = 0; $p < $p_limit; $p++) {
                 if (strlen($a_tmp_column[$p]) > 1) {
                     $i_pad = $p;
                     break;
                 }
             }
             $i_diff_x = $i_end_x - $i_start_x;
             $i_diff_y = $i_end_y - $i_start_y;
             $i_need_x = $i_diff_x - matchLength();
             $i_need_y = $i_diff_y - matchLength();
             if ($i_need_x >= 0) {
                 $i_start_x += $i_pad;
             }
             if ($i_need_y >= 0) {
                 $i_start_y += $i_pad;
             }
             if (isset($a_winning_set['x'])) {
                 $a_winning_set['x'][0] = $i_start_y;
                 $a_winning_set['x'][1] = $i_start_x;
             }
             if (isset($a_winning_set['o'])) {
                 $a_winning_set['o'][0] = $i_start_y;
                 $a_winning_set['o'][1] = $i_start_x;
             }
             $this->isGameOver = TRUE;
             $a_winning_set['how'] = 'gravely';
             $this->a_winning_spot = $a_winning_set;
         }
         $a_coords = array();
         // clear everything out again
         if (count($a_tmp_column) > 0) {
             $i++;
         }
         $a_tmp_column = array();
         if ($outer_x >= 0) {
             $outer_x--;
         } else {
             $outer_x = 0;
             $outer_y++;
         }
         $x = $outer_x;
         $y = $outer_y;
     }
 }