function ft_up($socket, $lvl, $current) { if (isset($GLOBALS['last_call']) && $GLOBALS['last_call']) { $movement = array(1 => array("avance"), 2 => array("avance", "gauche", "avance"), 3 => array("gauche", "avance"), 4 => array("gauche", "avance", "gauche", "avance"), 5 => array("droite", "droite", "avance"), 6 => array("droite", "avance", "droite", "avance"), 7 => array("droite", "avance"), 8 => array("avance", "droite", "avance")); while ($GLOBALS['last_call'] != 42) { ft_exec_travel($movement[$GLOBALS['last_call']], $socket); $current = ft_see($socket); ft_search($socket, $current, $lvl, "nourriture"); if ($GLOBALS['t_last_call'] > time() + 310 * $GLOBALS["time"]) { ft_call($socket, $current, $lvl); } } while ($GLOBALS['last_call'] == 42) { socket_write($socket, "broadcast " . $GLOBALS['inventaire']["team"] . "\n"); echo "broadcast " . $GLOBALS['inventaire']["team"] . "\n"; get_next_line_socket($socket, "broadcast"); if ($GLOBALS['inventaire']["nourriture"] > 20) { socket_write($socket, "pose nourriture\n"); echo "pose nourriture\n"; get_next_line_socket($socket, "pose"); } $current = ft_see($socket); $lvl = ft_incantation($socket, $lvl, $current, FALSE); } } else { ft_call($socket, $current, $lvl); } }
function ft_move($socket, $current) { $default_view = ft_create_dv(); $i = 0; $destination = array(); foreach ($current as $case) { $destination[$i] = 0; foreach ($case as $data) { if (isset($GLOBALS['stack'][$data]) && $GLOBALS['stack'][$data] > $GLOBALS['inventaire'][$data]) { $destination[$i]++; } } $i++; } if (max($destination) == 0) { socket_write($socket, "avance\n"); echo "avance\n"; get_next_line_socket($socket, "avance"); return; } $dest = array_search(max($destination), $destination); $travel = array(); foreach ($default_view as $y => $value) { foreach ($value as $x => $case) { if ($case == $dest) { $travel = ft_create_travel($x, $y); if (isset($travel[0])) { ft_exec_travel($travel, $socket); } return; } } } }