Pourquoi je reçois le message “missing argument” sur mon Boggle solveur?

StackOverflow https://stackoverflow.com/questions/8983455

  •  13-11-2019
  •  | 
  •  

Question

Il y a quelques années, ici, quelqu'un avait posté quelques code PHP sur un Boggle solveur ils ont fait avec PHP.

Comment trouver la liste des mots possibles à partir d'une lettre de la matrice [Boggle Solveur]

J'ai essayé de le faire fonctionner, mais je reçois une erreur "Warning:Argument manquant 7 pour find_words()" que je connais déjà sa parce qu'il semblait oublier de passer une variable dans la fonction.J'ai essayé de le faire fonctionner mais je ne peux pas semblent le comprendre, une autre personne peut le faire?Aucune chance que quelqu'un a quelque chose d'un peu plus sophistiqué?Peut-être quelque chose qui peut suivre le chemin des mots?De toute façon si quelqu'un pourrait contribuer ce serait génial.

$boggle = "fxie
       amlo
       ewbx
       astu";

$alphabet = str_split(str_replace(array("\n", " ", "\r"), "", strtolower($boggle)));
$rows = array_map('trim', explode("\n", $boggle));
$dictionary = file("C:/dict.txt");
$prefixes = array(''=>'');
$words = array();
$regex = '/[' . implode('', $alphabet) . ']{3,}$/S';
foreach($dictionary as $k=>$value) {
$value = trim(strtolower($value));
$length = strlen($value);
if(preg_match($regex, $value)) {
    for($x = 0; $x < $length; $x++) {
        $letter = substr($value, 0, $x+1);
        if($letter == $value) {
            $words[$value] = 1;
        } else {
            $prefixes[$letter] = 1;
        }
    }
}
}

$graph = array();
$chardict = array();
$positions = array();
$c = count($rows);
for($i = 0; $i < $c; $i++) {
$l = strlen($rows[$i]);
for($j = 0; $j < $l; $j++) {
    $chardict[$i.','.$j] = $rows[$i][$j];
    $children = array();
    $pos = array(-1,0,1);
    foreach($pos as $z) {
        $xCoord = $z + $i;
        if($xCoord < 0 || $xCoord >= count($rows)) {
            continue;
        }
        $len = strlen($rows[0]);
        foreach($pos as $w) {
            $yCoord = $j + $w;
            if(($yCoord < 0 || $yCoord >= $len) || ($z == 0 && $w == 0)) {
                continue;
            }
            $children[] = array($xCoord, $yCoord);
        }
    }
    $graph['None'][] = array($i, $j);
    $graph[$i.','.$j] = $children;
}
}

function to_word($chardict, $prefix) {
$word = array();
foreach($prefix as $v) {
    $word[] = $chardict[$v[0].','.$v[1]];
}
return implode("", $word);
}

function find_words($graph, $chardict, $position, $prefix, $prefixes, &$results, $words) {
$word = to_word($chardict, $prefix);
if(!isset($prefixes[$word])) return false;

if(isset($words[$word])) {
    $results[] = $word;
}

foreach($graph[$position] as $child) {
    if(!in_array($child, $prefix)) {
        $newprefix = $prefix;
        $newprefix[] = $child;
        find_words($graph, $chardict, $child[0].','.$child[1], $newprefix, $prefixes,         $results, $words);
    }
}
}

$solution = array();
find_words($graph, $chardict, 'None', array(), $prefixes, $solution);
print_r($solution);
Était-ce utile?

La solution

Essayez de remplacer le find_words appel au fond, avec:

find_words($graph, $chardict, 'None', array(), $prefixes, $solution, $words);

Il a juste oublié de passer dans un argument, le code ressemble...acceptable.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top