bug in head

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PowerDiver
    Prophet
    • Mar 2008
    • 2820

    #16
    If you modify it to return the rounded distance as I suggested upthread, won't it return the same values as it used to for small cases, thus solving whatever problems your change introduced?

    Comment

    • nppangband
      NPPAngband Maintainer
      • Dec 2008
      • 926

      #17
      I am at work (East Coast, USA), so I didn't compile and check this code, but I think the problem is the above and below. Unless the exact distance is an whole number square root (1, 4, 9, etc...), sometimes it is going to round up the distance, and sometimes it is going to round down. It just depends on whether above or below gets to less than 1 of the unrounded distance first. For the case where a diaganol distance of 1 and dsq = 2, above gets there first, and it returns an undesired result.

      I think you need to start from the below the distance and work your way up, checking each number one at a time until you get above dsq. I am assuming efficiency is important, and you will rarely be calculating distances greater than 25, so something like this:


      /*
      * Calculate distance between two points.
      */
      int distance(int y1, int x1, int y2, int x2)
      {
      int dist = 0;
      int dsq = abs(y2 - y1) + abs(x2 - x1);

      /* For efficiency, help narrow in on the distance in increments of 5 */
      if (dsq >= 400) dist = 20;
      else if (dsq >= 225) dist = 15;
      else if (dsq >= 100) dist = 10;
      else if (dsq >= 25) dist = 5;

      while (TRUE)
      {
      /*figure out if the next increment is greater than dsq*/
      int dist_plus_squared = (dist +1) * (dist +1);

      /*We have the distance, rounded down. We are done.*/
      if (dist_plus_squared > dsq) return (dist);

      /*try again*/
      dist++;
      }

      }

      That function returns a distance of 1 for all 8 directions around a player, and as the distance increases should return a relatively round circle for each distance.

      Hope that helps.
      NPPAngband current home page: http://nppangband.bitshepherd.net/
      Source code repository:
      https://github.com/nppangband/NPPAngband_QT
      Downloads:
      https://app.box.com/s/1x7k65ghsmc31usmj329pb8415n1ux57

      Comment

      • d_m
        Angband Devteam member
        • Aug 2008
        • 1517

        #18
        For what it's worth, I modified the function to make sure it returned 1 for distance(0, 0, 1, 1) and still had the bug. I probably should have mentioned that. I can post the modified function along with a table of distances when I get a chance.

        EDIT: I should ask... are you able to use your distance function in V and have it work? If so then obviously it's my mistake, but I would guess it still won't work. When I get home from work I will give it a try.
        Last edited by d_m; July 7, 2010, 15:27.
        linux->xterm->screen->pmacs

        Comment

        • PowerDiver
          Prophet
          • Mar 2008
          • 2820

          #19
          Originally posted by d_m
          EDIT: I should ask... are you able to use your distance function in V and have it work? If so then obviously it's my mistake, but I would guess it still won't work. When I get home from work I will give it a try.
          I didn't try it. It just seems so obvious that if the function returns the same values everything should act the same.

          That incredibly strange radius 3 light not covering a distance of \sqrt{2} probably means that something is getting doubled somewhere in addition to rounding up, so I don't think fixing just one value is likely to be enough. I remember checking that rounding works the same as the old distance in every point in the radius 3 ball, but I might have made a mistake.

          Comment

          • nppangband
            NPPAngband Maintainer
            • Dec 2008
            • 926

            #20
            Originally posted by d_m
            For what it's worth, I modified the function to make sure it returned 1 for distance(0, 0, 1, 1) and still had the bug. I probably should have mentioned that. I can post the modified function along with a table of distances when I get a chance.

            EDIT: I should ask... are you able to use your distance function in V and have it work? If so then obviously it's my mistake, but I would guess it still won't work. When I get home from work I will give it a try.
            No, I am also at work so I can't test it either. I can't imagine the problem is being inside update_view, since that function is called so often any flaws would have been found long ago. I trust update view is called after the tunneling is completed and every time the player moves, so that can't be it.

            I have a similar function in NPP that I think is used in update_view, all of the line-of-sight code and all of the project functions, but it is a bool that doesn't return the actual square root. It just uses pythagorean theorum to determine if the distance from one square to another is above or below a set distance.

            How are you using that function?
            NPPAngband current home page: http://nppangband.bitshepherd.net/
            Source code repository:
            https://github.com/nppangband/NPPAngband_QT
            Downloads:
            https://app.box.com/s/1x7k65ghsmc31usmj329pb8415n1ux57

            Comment

            • PowerDiver
              Prophet
              • Mar 2008
              • 2820

              #21
              Originally posted by d_m
              You'll need to modify VINFO_MAX_GRIDS and VINFO_MAX_SLOPES by setting them to a high value and then reading the error messages (but you probably know this already).
              I couldn't figure out how to get those to work. If I increase one, I have to increase the other. I fiddle around, and then I get an error that something is too small. I guess I'll have to try again when feeling more in tune with numerology.

              Comment

              • d_m
                Angband Devteam member
                • Aug 2008
                • 1517

                #22
                Originally posted by PowerDiver
                I couldn't figure out how to get those to work. If I increase one, I have to increase the other. I fiddle around, and then I get an error that something is too small. I guess I'll have to try again when feeling more in tune with numerology.
                You can find the "correct" values by setting both of them to something too high (e.g. 1000) and then when you see a value in the error (e.g. 267 < 1000) use 267. You'll probably also have to set VINFO_BITS_3 to something like 0xFFFFFFFF.

                When I tried the suggested distance function though I think it ended up producing "too many" grids and/or slopes because I got a segfault.
                linux->xterm->screen->pmacs

                Comment

                • PowerDiver
                  Prophet
                  • Mar 2008
                  • 2820

                  #23
                  Originally posted by d_m
                  You can find the "correct" values by setting both of them to something too high (e.g. 1000) and then when you see a value in the error (e.g. 267 < 1000) use 267. You'll probably also have to set VINFO_BITS_3 to something like 0xFFFFFFFF.

                  When I tried the suggested distance function though I think it ended up producing "too many" grids and/or slopes because I got a segfault.
                  OK -- I thought something else was going on with VINFO_BITS_3. When I changed that I got it to compile and run. I didn't find a treasure room, but I did run into a situation where the diagonal grid was unknown until I bumped into it, despite wielding a radius 2 light source.

                  I even tossed in asserts to guarantee that my distance function returned the same values when dx <= 2 and dy <= 2, so somehow the visibility of the adjacent diagonal is getting screwed up by some change to a distance larger than 2. BTW my change suggested upthread doesn't work on distance 0, have to special case that.

                  Comment

                  • fizzix
                    Prophet
                    • Aug 2009
                    • 3025

                    #24
                    Found a couple small bugs.

                    Let's say you have something autoinscribed but change the inscription. Let's say you have -light autoinscribed @z1 but during the game you change the rod's inscription it to @z1 !k or something without changing the autoinscription. If you have full inventory and you pick up a rod of light it enters your pack but doesn't stack because of the different inscriptions. It then forces out whatever is last.

                    I got a message that 'Ariel crushes a xxxxx'. I could not see Ariel, she was not visible, and obviously was not detected by telepathy. I should have got a 'something crushes a xxxxx'

                    There needs to be quality squelch options for dragon armor. You need to have a 'squelch all non-artifact dragon armor' option. Admittedly, this has bothered me for a long time.

                    Comment

                    • PowerDiver
                      Prophet
                      • Mar 2008
                      • 2820

                      #25
                      Originally posted by fizzix
                      There needs to be quality squelch options for dragon armor. You need to have a 'squelch all non-artifact dragon armor' option. Admittedly, this has bothered me for a long time.
                      There was some talk of allowing dragon armors to have egos. I don't think it is worth worrying about fixing squelching until that is taken care of, since squelch code will have to change when DSMs have egos.

                      If you don't mind abuse, squelch all DSMs through the menu. Artifacts are never squelched. You will see all artifact DSMs and no other DSMs. The abuse is that you can tell immediately whether they are artifacts at a distance.

                      Comment

                      • fizzix
                        Prophet
                        • Aug 2009
                        • 3025

                        #26
                        Originally posted by PowerDiver
                        There was some talk of allowing dragon armors to have egos. I don't think it is worth worrying about fixing squelching until that is taken care of, since squelch code will have to change when DSMs have egos.

                        If you don't mind abuse, squelch all DSMs through the menu. Artifacts are never squelched. You will see all artifact DSMs and no other DSMs. The abuse is that you can tell immediately whether they are artifacts at a distance.
                        I mind the abuse, that's why I won't do that.

                        Comment

                        • PowerDiver
                          Prophet
                          • Mar 2008
                          • 2820

                          #27
                          Originally posted by fizzix
                          I mind the abuse, that's why I won't do that.
                          If you play with the standard artifacts, you can squelch all but multihued and power and balance. I mind the abuse a little bit myself, but it is such a low probability event I just squelch each DSM flavor after picking one up if I don't want it, and ignore the abuse. I have not yet found artifact DSM after squelching the flavor so for me the abuse remains only theoretical so far.

                          Comment

                          • fizzix
                            Prophet
                            • Aug 2009
                            • 3025

                            #28
                            Originally posted by PowerDiver
                            If you play with the standard artifacts, you can squelch all but multihued and power and balance. I mind the abuse a little bit myself, but it is such a low probability event I just squelch each DSM flavor after picking one up if I don't want it, and ignore the abuse. I have not yet found artifact DSM after squelching the flavor so for me the abuse remains only theoretical so far.
                            The problem is much more tied in with randarts. It's also one of the reason I like playing with randarts. With standards you can do stuff like, "i've already found caspanion so I can ignore all other augmented chain mail" That's always bothered me from a game play perspective.

                            Comment

                            Working...
                            😀
                            😂
                            🥰
                            😘
                            🤢
                            😎
                            😞
                            😡
                            👍
                            👎