Beispiel #1
0
Datei: ga.php Projekt: vench/esee
function makeChain($points, $x, $y, $chain = null)
{
    static $see = [];
    if (isset($see[$x][$y])) {
        return $chain;
    }
    $see[$x][$y] = 1;
    if (isset($points[$y][$x]) && $points[$y][$x] == 1) {
        if (is_null($chain)) {
            $chain = new Chain();
        }
        $chain->addPoint($x, $y);
        makeChain($points, $x + 1, $y, $chain);
        makeChain($points, $x + 1, $y + 1, $chain);
        makeChain($points, $x, $y + 1, $chain);
        makeChain($points, $x - 1, $y, $chain);
        makeChain($points, $x - 1, $y - 1, $chain);
        makeChain($points, $x, $y - 1, $chain);
        makeChain($points, $x + 1, $y - 1, $chain);
        makeChain($points, $x - 1, $y + 1, $chain);
    }
    return $chain;
}
Beispiel #2
0
function makeChain(&$points, $x, $y, &$chain = null)
{
    static $see = [];
    if (isset($see[$y][$x])) {
        return $chain;
    }
    /*
    	if(getValue($points,$x,$y) == 1 && ( 
    		getValue($points,$x + 1,$y) == 0 ||
    		getValue($points,$x,$y + 1) == 0 ||
    		getValue($points,$x - 1,$y) == 0 ||
    		getValue($points,$x,$y - 1) == 0 ||
    		getValue($points,$x + 1,$y + 1) == 0 ||
    		getValue($points,$x - 1,$y - 1) == 0 ||
    		getValue($points,$x - 1,$y + 1) == 0 ||
    		getValue($points,$x + 1,$y - 1) == 0
    	)) {
    
    		if(is_null($chain)) {
    			$chain = [];
    		}
    		$chain[$y][$x] = 1;
    
    		
    		
    		makeChain($points, $x + 1, $y, $chain);	
    		makeChain($points, $x - 1, $y, $chain);
    		makeChain($points, $x, $y + 1, $chain);
    		makeChain($points, $x, $y - 1, $chain);
    		makeChain($points, $x + 1, $y + 1, $chain);
    		makeChain($points, $x - 1, $y - 1, $chain);
    		makeChain($points, $x + 1, $y - 1, $chain);
    		makeChain($points, $x - 1, $y + 1, $chain);
    	}*/
    if (getValue($points, $x, $y) == 1 && (getValue($points, $x + 1, $y) == 0 || getValue($points, $x, $y + 1) == 0 || getValue($points, $x - 1, $y) == 0 || getValue($points, $x, $y - 1) == 0 || getValue($points, $x + 1, $y + 1) == 0 || getValue($points, $x - 1, $y - 1) == 0 || getValue($points, $x - 1, $y + 1) == 0 || getValue($points, $x + 1, $y - 1) == 0)) {
        //echo $x . ' ' .$y . ' x' . "\n";
        if (is_null($chain)) {
            $chain = [];
        }
        $chain[$y][$x] = 1;
        $see[$y][$x] = 1;
        //$lx = $x; $ly = $y;
        if (inChain($x, $y, $x + 1, $y, $points)) {
            makeChain($points, $x + 1, $y, $chain);
        } else {
            //$see[$y][$x + 1] = 1;
        }
        if (inChain($x, $y, $x, $y + 1, $points)) {
            makeChain($points, $x, $y + 1, $chain);
        } else {
            ///$see[$y + 1][$x] = 1;
        }
        if (inChain($x, $y, $x - 1, $y, $points)) {
            makeChain($points, $x - 1, $y, $chain);
        } else {
            //$see[$y][$x-1] = 1;
        }
        if (inChain($x, $y, $x, $y - 1, $points)) {
            makeChain($points, $x, $y - 1, $chain);
        } else {
            //$see[$y-1][$x] = 1;
        }
        if (inChain($x, $y, $x + 1, $y + 1, $points)) {
            makeChain($points, $x + 1, $y + 1, $chain);
        } else {
            //$see[$y +1][$x+1] = 1;
        }
        if (inChain($x, $y, $x - 1, $y - 1, $points)) {
            makeChain($points, $x - 1, $y - 1, $chain);
        } else {
            //$see[$y-1][$x-1] = 1;
        }
        if (inChain($x, $y, $x + 1, $y - 1, $points)) {
            makeChain($points, $x - 1, $y - 1, $chain);
        } else {
            //$see[$y-1][$x+1] = 1;
        }
        if (inChain($x, $y, $x - 1, $y + 1, $points)) {
            makeChain($points, $x - 1, $y - 1, $chain);
        } else {
            //$see[$y+1][$x-1] = 1;
        }
        /*/*
        		makeChain($points, $x + 1, $y, $chain);	
        		makeChain($points, $x - 1, $y, $chain);
        		makeChain($points, $x, $y + 1, $chain);
        		makeChain($points, $x, $y - 1, $chain);
        		makeChain($points, $x + 1, $y + 1, $chain);
        		makeChain($points, $x - 1, $y - 1, $chain);
        		makeChain($points, $x + 1, $y - 1, $chain);
        		makeChain($points, $x - 1, $y + 1, $chain);*/
    }
    //$see[$y][$x] = 1;
    return $chain;
}