comprobardiagonal

    0

    0

    izian db

    $i = $fila; $j = $col; $vermell = 0; $groc = 0;

    while ($i - 1 >= 0 && $j - 1 >= 0) { $i--; $j--;}

    while ( $vermell < 4 && $groc < 4 && $i <= count($_SESSION["tauler"])-1 && $j <= count($_SESSION["tauler"][0])-1 ) {

    if ($_SESSION["tauler"][$i][$j]==1) { $vermell++; $groc = 0;} elseif ($_SESSION["tauler"][$i][$j]==2) { $groc++; $vermell = 0;}

    $i++; $j++; }

    if ($vermell==4 || $groc==4) { echo "ganaste"; return true;} else { return false;

    Shortcut: comprobardiagonal

    $i = $fila;
    $j = $col;
    $vermell = 0;
    $groc = 0;
    
    while ($i - 1 >= 0 && $j - 1 >= 0) {
      $i--;
      $j--;
    }
    
    while (
      $vermell < 4 && $groc < 4 &&
      $i <= count($_SESSION["tauler"]) - 1 && $j <= count($_SESSION["tauler"][0]) - 1
    ) {
    
      if ($_SESSION["tauler"][$i][$j] == 1) {
        $vermell++;
        $groc = 0;
      } elseif ($_SESSION["tauler"][$i][$j] == 2) {
        $groc++;
        $vermell = 0;
      }
    
      $i++;
      $j++;
    }
    
    
    if ($vermell == 4 || $groc == 4) {
    
      return true;
    } else {
    
    
    
      $i = $fila;
      $j = $col;
      $vermell = 0;
      $groc = 0;
    
      while ($i - 1 >= 0  && $j + 1 <= count($_SESSION["tauler"][0]) - 1) {
        $i--;
        $j++;
      }
    
    
      while (
        $vermell < 4 && $groc < 4 &&
        $i <= count($_SESSION["tauler"]) - 1  && $j >= 0
      ) {
    
        if ($_SESSION["tauler"][$i][$j] == 1) {
          $vermell++;
          $groc = 0;
        } elseif ($_SESSION["tauler"][$i][$j] == 2) {
          $groc++;
          $vermell = 0;
        }
    
        $i++;
        $j--;
      }
    
    
      if ($vermell == 4 || $groc == 4) {
        echo "ganaste";
        return true;
      } else {
    
        return false;
      }
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.