Jump to content

Hooker

Members
  • Posts

    193
  • Joined

  • Last visited

    Never

Everything posted by Hooker

  1. Hooker

    Pathing

    cool, well it looks good
  2. Hooker

    Pathing

    looks good, does it use a db?
  3. Hooker

    Pathing

    This is what i have so far: <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); //set start/finnish coordiantes to help calculate the G value $x_start = "2"; $y_start = "2"; $x_finnish = "10"; $y_finnish = "10"; //check if there is a "current" square, if not, set it as the start square if((!isset($x_axis_current))||(!isset($y_axis_curren))){ $x_axis_current = $x_start; $y_axis_current = $y_start; } //Check whether the current square being checked is the "finnish" square and stop if it is while(($x_axis_current != $x_finnish)&&($y_axis_current != $y_finnish)){ //Select the "open" list for the current square being processed $result = mysql_query("SELECT * FROM map WHERE (x_axis = $x_axis_current-1 OR x_axis = $x_axis_current+1 OR x_axis = $x_axis_current) AND (y_axis = $y_axis_current-1 OR y_axis = $y_axis_current+1 OR y_axis = $y_axis_current) AND CONCAT(y_axis, ',', x_axis) != $y_axis_current AND movable = '1'") or die(mysql_error()); while($row = mysql_fetch_array($result)) { //calculating the "H" value $h = ($x_finnish - $x_axis_current) + ($y_finnish - $x_axis_current) * 10; //detecting if it's a diagnal movement or not and assigning the movement cost "G" IF(($row['x_axis'] != $x_axis_current) && ($row['y_axis'] != $y_axis_current)){ $G = "14"; } else { $G = "10"; } //calculating the "F" value: $F = $G + $H; //set a default "score" if this is the first square being checked if(!isset($score)){ $score = "99999"; } //If the square being checked has an F score lower than the previous, set as the next square to move to if($F < $score){ $score = $F; //Set the next square to be used (this will probably be changed several times as it checks all available squares but by the end of the while loop it should be the square with the lowest "F" value) $x_axis_current = $row['x_axis']; $y_axis_current = $row['y_axis']; } } echo $x_axis_current.",".$y_axis_current."<br>"; } ?> i just seem to get spammed with "1,3" when i run it, im sure this is a syntax issue, any ideas?
  4. scrub that, my brain wasnt working for a sec, the solution is: SELECT * FROM map WHERE (x_axis = '2'-1 OR x_axis = '2'+1 OR x_axis = '2') AND (y_axis = '2'-1 OR y_axis = '2'+1 OR y_axis = '2') AND CONCAT(y_axis, ',', x_axis) != '2,2' AND movable = '1'
  5. Hey, Just a quick question, i'm trying to select the coordinates around a set of coordinates, my table looks like this: i have data inside for a 10x10 map, like so: i was wondering how i'd go about selecting all the records within 1 coordinate (horizontaly, verticaly and diagnoly), ie. selecting all the coordinates around "2,2" would output: thanks.
  6. Hooker

    Pathing

    the basic idea is to loop through all the ajacent squares to the current square you're in assigning them values based on the distance away from the final square (without using diagnol movements) and the difficulty to move into the next square. in the case diagnols are valued at a 14 difficulty and horizontal/verticle movements are valued at 10 so a horizontal/verticle movement will always get priority unless that square is further away from the final target square than the diagnol o.o anyway, i think i have the basics down in my above post, i just need someone a little more php-savvy to check the syntax i can give better comments on what i'm actualy trying to acheive at each point of the query if that helps.
  7. Hooker

    Pathing

    i don't use java so i could be off the mark but my very quickly thrown together code seems to be along the same tracks in alot of areas (obvious changes because of languages/the fact im using a DB aside) which is atleast encouraging for an hours playing. the only part i don't account for is the removal of squares that have already been occupied from the "available movements" list, it's a little redundent to me since i can't see the F value of those squares being any lower than a square nearer the final destination while im just using the manhattan method. ie. you're a square closer, the previous square gets +10 to its F value so even if you're moving in a diagnol and encouring the +4 penalty the difference would still be 6
  8. Hooker

    Pathing

    Okay, so say the layout for the "map" table is something like this: i'd have something along the lines of this so far: //set start/finnish coordiantes to help calculate the G value $x_start = "1"; $y_start = "1"; $x_finnish = "10"; $y_finnish = "10"; $x_axis_current = $x_start; $y_axis_current = $y_start; while(($x_axis_current != $x_finnish)&&($y_axis_current != $y_finnish)){ //set initial score. $score = "999999999"; //Select the "open" list for the current block being processed $result = mysql_query("SELECT * FROM map WHERE X_axis > $x_axis_current-1 AND X_axis < $x_axis_current+1 AND Y_axis > $y_axis_current-1 AND Y_axis < $y_axis_current+1 AND movable = '1'"); while($row = mysql_fetch_array($result)) { //calculating the "H" value $h = ($x_finnish - $x_axis_current) + ($y_finnish - $x_axis_current) * 10; //detecting if it's a diagnal movement or not and assigning the movement cost "G": IF(($row['x_axis'] != $x_axis_current) && ($row['y_axis'] != $y_axis_current)){ $G = "14"; } else { $G = "10" } //calculating the "F" value: $F = $G + $H; //If the square being checked has an F score lower than the previous, set as the next square to move to IF($F < $score){ $score = $F; $x_axis_current = $row['x_axis']; $y_axis_current = $row['y_axis']; } } } mysql_close($con); all untested + veyr messey and could be complete rubbish, like i said i don't use PHP much but apart from some syntax errors which there are all over the place presumably, in theorey it should work..
  9. Hooker

    Pathing

    //detecting if it's a diagnal movement or not and assigning the movement cost "G": If (($row['x_axis'] != $x_axis_current) && ($row['y_axis'] != $y_axis_current)){ $G = "14"; } else { $G = "10" } So calculating the "F" value: $F = $G + $H;
  10. Hooker

    Pathing

    calculating the "H" value would be something like this in php presumably.. $h = ($x_finnish - $x_axis_current) + ($y_finnish - $x_axis_current) * 10;
  11. Hooker

    Pathing

    im my usual method i've broken it down into seperate sections of code and going at it randomly, right now i'm up to this: //set start/finnish coordiantes to help calculate the G value $x_start = "1"; $y_start = "1"; $x_finnish = "10"; $y_finnish = "10"; $x_axis_current = "1"; $y_axis_current = "2"; //Select the "open" list for the current block being processed $result = mysql_query("SELECT * FROM map WHERE X_axis > $x_axis_current-1 AND X_axis < $x_axis_current+1 AND Y_axis > $y_axis_current-1 AND Y_axis < $y_axis_current+1"); while($row = mysql_fetch_array($result)) { //calculate next block to enter } mysql_close($con); as far as i can find, not alot of people have done this in php which got me intrested to start with
  12. Hooker

    Pathing

    Thanks, i'm fairly familiar with A* pathing, i'm just working out the best way to implement it.
  13. Hooker

    Pathing

    basicaly, sorry for the poor wording, its been a late night
  14. Hooker

    Pathing

    This is just a quick questions about map-pathing for game i'm considering making for my local games club so don't stress yourselves too much if its alot of trouble : Anyway, i have a map made in php that at the moment is 10x10 squares, each square has a record in mysql. I wanted to know if there was a way to generate a "path" accross the map from one point to another bearing in mind that some squares would be impassable. I could do this in C or VB fairly easily but i don't use PHP alot so any assistance is greatly appreciated. P.S - Just incase the above isn't very clear, my intention is to give people a character and allow them to move from say 1,1 to 10,9 and the path be marked out on the map.
  15. try looking into "reset query cache"
  16. http://dev.mysql.com/doc/refman/5.0/en/join.html
  17. decreased the query time from 4 minutes to 33 seconds comparing 47mill against 500k records thanks alot fenway!
  18. What are you actualy trying to do here: $query = "SELECT CONTACT(last_name, -->', ',<-- first_name) AS name, DATE_FORMAT (registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC"; $result = @mysql_query ($query); You need to close the singlequotes or remove the comma's & quotes, ie: $query = "SELECT CONTACT(last_name, first_name) AS name, DATE_FORMAT (registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC"; $result = @mysql_query ($query); If you're trying to enter extra details you would do something like: $query = "SELECT CONTACT(last_name, 'value1', 'value2', first_name) AS name, DATE_FORMAT (registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC"; $result = @mysql_query ($query);
  19. LOAD DATA LOCAL INFILE "c:\wamp\www\webapp\customer.txt" INTO TABLE "customer";
  20. Give this a try (its un-tested): $query = "SELECT * FROM customers WHERE LOWER(CONCAT_WS(' ',c_id, c_user, c_name, c_b_addr, c_b_city, c_b_state, c_b_zip, c_b_first, c_b_last, c_b_phone)) LIKE LOWER('%$trimmed%')";
  21. Something like this should do the trick (obviously changing opener1, opener2 etc to your column names): SELECT * FROM shows WHERE LOWER(CONCAT_WS(' ',opener1,opener2,opener3,opener4,opener5,opener6)) LIKE LOWER('%$search%')
  22. can you drop in a couple of echo's here: $sql = "SELECT * FROM shows ORDER BY dateofshow"; if((!isset($select))||($select == 1)){ $sql.=" DESC"; }else{ $sql.=" ASC"; } echo $sql; echo $select; $result = mysql_query($sql) or die (mysql_error());
  23. This should help (find your version of mysql in the left menu for revelvant doc's): http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
  24. <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test2", $con); //gets the variables the user selected from the form. $select= $_POST['select']; $sql = "SELECT * FROM shows ORDER BY dateofshow"; if((!isset($select))||($select == 1)){ $sql.=" DESC"; }else{ $sql.=" ASC"; } $result = mysql_query($sql) or die (mysql_error()); echo '<table width="740" border="0" align="center" cellpadding="12" cellspacing="0" class="main">'; echo '<tr class="topper"><th>Date</th><th>Headliner</th><th>Venue</th><th>Opener</th></tr>'; while($rows=mysql_fetch_array($result)){ echo "<tr><td valign=\"top \">".date('Y > M d',strtotime($rows['dateofshow']))."</td><td valign=\"top \">".$rows['headliner']."</td><td valign=\"top \">".$rows['venue']."<br />".$rows['city'].", ".$rows['state']."</td><td valign=\"top \">".$rows['opener1']."<br />".$rows['opener2']."<br />".$rows['opener3']."<br />".$rows['opener4']."<br />".$rows['opener5']."<br />".$rows['opener6']."</td></tr>"; } echo '</table><br /></center></body>'; mysql_close($con); ?>
  25. Tag this onto the end of the query: or die(mysql_error()); and you will probably see it's not displaying but returning an error, without taking a good look i'd have to say the curlies were causing it. <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test2", $con); //gets the variables the user selected from the form. $select= $_POST['select']; if(!isset($select) || $select == 1){ $order = "DESC"; }else{ $order = "ASC"; } $result = mysql_query("SELECT * FROM shows ORDER BY dateofshow $order"); echo '<table width="740" border="0" align="center" cellpadding="12" cellspacing="0" class="main">'; echo '<tr class="topper"><th>Date</th><th>Headliner</th><th>Venue</th><th>Opener</th></tr>'; while($rows=mysql_fetch_array($result)){ echo "<tr><td valign=\"top \">".date('Y > M d',strtotime($rows['dateofshow']))."</td><td valign=\"top \">".$rows['headliner']."</td><td valign=\"top \">".$rows['venue']."<br />".$rows['city'].", ".$rows['state']."</td><td valign=\"top \">".$rows['opener1']."<br />".$rows['opener2']."<br />".$rows['opener3']."<br />".$rows['opener4']."<br />".$rows['opener5']."<br />".$rows['opener6']."</td></tr>"; } echo '</table><br /></center></body>'; mysql_close($con); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.