[HN Gopher] Draggable objects
       ___________________________________________________________________
        
       Draggable objects
        
       Author : stefankuehnel
       Score  : 737 points
       Date   : 2023-09-29 12:51 UTC (10 hours ago)
        
 (HTM) web link (www.redblobgames.com)
 (TXT) w3m dump (www.redblobgames.com)
        
       | slowhadoken wrote:
       | Amit Patel is the man. I always say his last name like Matthew
       | Patel says his name in Scott Pilgrim. Side note: Sebastian Lague
       | is great too.
        
         | ChadNauseam wrote:
         | > I always say his last name like Matthew Patel says his name
         | in Scott Pilgrim
         | 
         | One of the seven evil hexes :D
        
       | PaulDavisThe1st wrote:
       | One extra detail, something I've learned from 20 years of working
       | on dragging all kinds of objects around the GUI of Ardour [0]:
       | handle _ALL_ button press and release events as drag events where
       | there is no movement. That is: press ALWAYS starts a drag that is
       | finished by the release, and the code that handles release
       | "special cases" the no-movement condition.
       | 
       | [0] https://ardour.org/
        
       | amitp wrote:
       | Thank you everyone! What a surprise to be on HN today. Happy to
       | answer questions!
        
         | Max_Mustermann wrote:
         | Hey Amit! I remember you and your articles fondly from my RotMG
         | days.
        
         | tjfjr wrote:
         | Does redblobgames.com have its own RSS/Atom feed? In its footer
         | there is a link to the feed for your other blog,
         | simblob.blogspot.com. I'd love to keep tabs on both of these
         | blogs in my feed reader.
         | 
         | Big fan of your writing, btw!
        
           | amitp wrote:
           | Thanks! The short answer is: no.
           | 
           | The longer answer is: I'm not actually sure how to solve this
           | problem. The second site, simblob.blogspot.com, is an actual
           | blog. It's time ordered. It has posts. But the main site,
           | redblobgames.com, is structured as a "living document" site,
           | not as a blog. Things are not posted in order.
           | 
           | I could try an _automated_ feed that looks for any changes on
           | pages. But I make small changes all the time. For example on
           | [1] I changed  "So far we've made step have the same" to "So
           | far we've made steps have the same". I've been fixing a lot
           | of broken links and typos this week, so there are lots of
           | pages that have changed, but not in meaningful ways. I don't
           | want those showing up on the RSS feed.
           | 
           | The second problem with an automated feed is that I have
           | pages that aren't meant for publication. I collect notes for
           | myself before I write an article, sometimes for years. For
           | example [2] is something I may never get around to
           | publishing. I don't want new pages to show up on the RSS
           | feed, because most of them aren't ready yet, and some may
           | never be.
           | 
           | So an alternative is for me to manually add entries to an RSS
           | feed when they're "meaningful". I'm trying to do this by
           | posting to the simblob.blogspot.com blog. An example is [3]
           | where I describe the changes I'm making to the mapgen4 page.
           | These wouldn't have been picked up by an automated feed
           | because the HTML didn't change, but the interactive part did,
           | so I wrote about it. Another example is [4] which is about
           | changes to the hexagon page. I'll also go into a lot more
           | details about _why_ I made those changes [5].
           | 
           | But manually writing blog posts means there will be changes
           | that won't show up in the RSS. Ideally I'd have some kind of
           | automated way to flag _meaningful_ changes to the site, but
           | until then I am trying to write meaningful changes on the
           | blog.
           | 
           | [1] https://www.redblobgames.com/pathfinding/a-star/introduct
           | ion...
           | 
           | [2] https://www.redblobgames.com/articles/probability/loot-
           | drops...
           | 
           | [3] https://simblob.blogspot.com/2023/04/improving-
           | mapgen4s-boun...
           | 
           | [4] https://simblob.blogspot.com/2023/04/explaining-hexagon-
           | layo...
           | 
           | [5] https://simblob.blogspot.com/2022/11/introduction-to-
           | hexagon...
        
         | gaolei8888 wrote:
         | Awesome work! Thanks a lot. It is fun to read these type
         | creative articles
        
         | onassar wrote:
         | Really gr8.
        
         | birracerveza wrote:
         | No, thank YOU. This is an awesome resource for learning game
         | algorithms, and it's a lot of fun to just play around with the
         | interactive explanations.
         | 
         | Definitely one of the best websites I know. Cheers!
        
         | liendolucas wrote:
         | Very neat! The way that you precisely get to the point and then
         | snippets are presented and discussed is fantastic. I wish to
         | see more of these kind of detailed explanations everywhere.
         | Code is read and understood effortlessly!
        
         | dang wrote:
         | Can you please nominate a specific URL on your site that we can
         | change the top link to? (see
         | https://news.ycombinator.com/item?id=37707904 for why)
         | 
         | What's your most interesting piece that hasn't gotten
         | sufficient attention yet? I believe HN has had many great
         | threads about the A* and hexagonal grid articles over the
         | years. Is there a comparable one that's been overlooked so far?
        
           | amitp wrote:
           | This year I've mostly been updating existing pages in small
           | ways (examples: [1] [2]). This week I've been fixing broken
           | links, which isn't a good HN submission.
           | 
           | I think the best candidate is
           | https://www.redblobgames.com/making-of/draggable/ . It's from
           | earlier this year and hasn't been posted to HN yet (I think).
           | 
           | [1] https://simblob.blogspot.com/2023/04/explaining-hexagon-
           | layo...
           | 
           | [2] https://simblob.blogspot.com/2023/04/improving-
           | mapgen4s-boun...
        
             | dang wrote:
             | I've changed to that page from
             | https://www.redblobgames.com/. Thanks!
             | 
             | Obviously, many comments on the thread predate this change,
             | but there's enough context here for readers to figure that
             | out, and hopefully we can get a more specific discussion
             | going.
        
               | sh1mmer wrote:
               | FWIW, dang, while I know guidelines are to post specific
               | things for me personally "check out this collection of
               | interactive tutorials" is actually a lot more
               | interesting/helpful than linking to a single tutorial,
               | especially when it's not clear from that tutorial it's
               | part of a collection larger collection.
               | 
               | Generally I feel like links to collections of stuff do
               | well when they are interesting and don't when they aren't
               | and that you modding to a specific example isn't actually
               | improving quality.
        
               | dang wrote:
               | I hear you and am certainly not denying the usefulness of
               | the site! it's fabulous and has been fabulous for many
               | years. It has also made many great appearances on HN over
               | the years: https://hn.algolia.com/?dateRange=all&page=0&p
               | refix=true&que....
               | 
               | But if we're to optimize HN for intellectual curiosity (h
               | ttps://hn.algolia.com/?dateRange=all&page=0&prefix=true&s
               | or...), we have to consider thread quality, and there's
               | no doubt that submissions like this generally lead to
               | generic, and therefore shallow, discussion in the way
               | that I described upthread.
               | 
               | Overall I think the best way for HN readers to discover a
               | site like this is bottom-up: to run across an example of
               | a great article and a great thread about it, and then
               | click around to discover what else is there. This is more
               | in the intended spirit of HN.
               | 
               | Edit: it's a little unorthodox for us to change the URL
               | in midstream after a submission has this many upvotes and
               | pre-existing comments, but I hope everyone understands
               | that I did so to give the site _more_ exposure and
               | appreciation, not less. The alternative would have been
               | to downweight the post as a  "list submission"
               | (https://news.ycombinator.com/item?id=37707904), and I
               | didn't want to do that.
        
         | ww520 wrote:
         | That is a fantastic discussion on dragging with Javascript.
         | Really appreciate the information.
         | 
         | I've a quick question. How do you restrict the dragging
         | movement to an axis using the built-in DOM events like
         | dragstart/etc. I had a drag & drop feature implemented using
         | the dragstart/dragenter/dragover/drop/etc events. I couldn't
         | find a quick way to restrict the dragging movement to the
         | x-axis. JQuery's drag and drop API used to support it. I'm
         | trying to use the native DOM events/api only. Any information
         | or pointers are greatly appreciated.
        
         | collinmanderson wrote:
         | Have you looked at html's built-in draggable="true" attribute
         | and drag events?
         | 
         | Are there shortcomings with the built-in feature compared to
         | your code?
         | 
         | https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement...
         | 
         | https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement...
         | 
         | https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...
        
           | amitp wrote:
           | Many of the interactions I'm working on aren't about dragging
           | elements, but instead using the drag motion to do some
           | action. I also had trouble getting the drag-and-drop API to
           | work inside SVG elements. I think it's solving a different
           | problem than what I'm trying to use it for.
        
           | penteract wrote:
           | I'm not Amit, but from the article:
           | 
           | > Note that this is not the HTML Drag and Drop API, which
           | involves dragging an element onto another element. For my
           | diagrams, I'm dragging but not dropping, and the scrubbable
           | number example shows how I'm not necessarily even moving
           | something around. So I need to read the mouse/touch events
           | directly.
           | 
           | The drag and drop API is doing a different thing that isn't
           | always appropriate - you can get it to do roughly what this
           | article is talking about by making the thing being dragged
           | invisible just after the dragging starts, but it can shrink
           | things and doesn't let you edit them as DOM nodes after the
           | dragging has started. It also lets you drag something out of
           | the browser window and try to put it into a completely
           | different window.
        
       | philipov wrote:
       | I think I might call RedBlobGames the #1 website on the internet
       | for learning game algorithms and data structures. Amit is the
       | best!
        
       | nimish wrote:
       | Classic website, one of the all-time greats.
        
       | jjkaczor wrote:
       | Am going to chime in as well - Amit is amazing and has been
       | providing his knowledge and experience since the early 90's, when
       | I first encountered him on FidoNet over BBS, then next on Usenet.
       | 
       | Regular tech blog: https://amitp.blogspot.com/ Game Dev blog:
       | https://simblob.blogspot.com/
        
       | bryceneal wrote:
       | Amit is a treasure. I referenced his articles many times when
       | making my own games. We could really use more thoughtful and
       | friendly visual learning resources like this for other subject
       | matter.
        
       | jart wrote:
       | I love this red blob!
        
       | adanto6840 wrote:
       | Likewise, Amit is phenomenal and the content (and especially its
       | presentation) is really second to none. The value he places on
       | ensuring links stay working, and that content is accurate and
       | updated -- is truly phenomenal and almost inconceivable these
       | days.
       | 
       | I've also always enjoyed every (virtual) interaction I've had
       | with him, however brief -- and appreciate that he remembers me
       | and the problems/challenges we faced in my games.
       | 
       | SimAirport and SimCasino very likely wouldn't be the same (or
       | would have taken much longer to achieve, at best) without his
       | content.
       | 
       | Just a class act; one of these days I'd love to buy Amit a beer
       | or a coffee. My invite doesn't expire, perhaps next time you're
       | in the area! :)
        
         | gowld wrote:
         | "If you're in the Silicon Valley area and want to chat in
         | person, email me at redblobgames@gmail.com. "
        
       | JLangley wrote:
       | Love this THANK YOU!
        
       | sarnowski wrote:
       | Playing around with a hex based game myself, the bookmark to the
       | Hexagonal Grid is a constant companion over the years. It was
       | updated slightly over the years with some visual cues. Amazing
       | presentation, and so great to learn.
        
       | calebm wrote:
       | Their hexagon grid page is one of the best hexagon grid resources
       | on the web that I've found.
        
         | zem wrote:
         | yeah! i clicked through the link and thought "oh, the hex grid
         | guy!"
        
       | ge96 wrote:
       | I remember when this was a big deal to me, jQuery days.
        
       | lloydatkinson wrote:
       | I've spoke to Amit a lot in the past, very knowledgable!
        
       | dang wrote:
       | It's a great site, but the home page of such a site doesn't make
       | for a great HN submission because it falls in the category of
       | "list":
       | https://hn.algolia.com/?dateRange=all&page=0&prefix=true&sor....
       | 
       | Lists don't make great HN submissions because they don't point to
       | anything specific enough. The resulting discussion tends to be
       | generic and shallow, because the only material to discuss is the
       | lowest-common-denominator, i.e. whatever the items on the list
       | have in common.
       | 
       | This thread is a nice example because the comments are only about
       | the site in general--mostly how good it is--which of course is
       | true, but not 'interesting' (in HN's sense of the word) enough to
       | devote a frontpage slot to (https://hn.algolia.com/?dateRange=all
       | &page=0&prefix=true&que...).
       | 
       | The solution is to pick the most interesting element from the
       | list and submit that instead. Maybe we should ask amitp to
       | nominate one :)
       | 
       | Edit: I did that and have changed the URL now. See
       | https://news.ycombinator.com/item?id=37708834. (I will also mark
       | the current comment off topic so it goes to the bottom of the
       | page.)
        
       | snapcaster wrote:
       | I love Amit! Went through all these articles in college and
       | learned so much about programming
        
       | LorenzoGood wrote:
       | I really loved this site when trying to implement A*
        
       | mickeyp wrote:
       | This is a great resource and a perfect example of what clear
       | explanations, code and visual aids can do to help you learn a
       | wide range of algorithms.
        
       | feoren wrote:
       | Apart from the excellent subject matter, I often pull up this
       | site during UI/UX discussions. Amit clearly has the ability to do
       | really advanced JavaScript visualizations, but he only uses it
       | _exactly_ when necessary. Most of it is a plain document like you
       | might write in Markdown, but when he uses JavaScript, it 's
       | illuminating, connected to all the other examples, and clean. Any
       | animation he uses is clearly initiated by the user, and is there
       | not because it looks cool, but because the intermediate frames
       | help the user understand what's happening. It also never moves
       | the rest of the layout around. I go back to this site any time
       | I'm pondering how to do good online documentation, interactive
       | help, tutorials, or even text-heavy presentation of results.
        
         | amitp wrote:
         | Thank you! I treat them as _documents_ , with some interactive
         | elements. I tend to avoid traditional animations because
         | they're outside the reader's control. I want the reader to be
         | able to pause, slow down, speed up, rewind, etc. One thing I'm
         | going for but haven't completely achieved is that I want the
         | diagrams to be useful even before the interaction.
         | 
         | I am collecting some of the design elements here:
         | https://www.redblobgames.com/making-of/little-things/
        
         | drng wrote:
         | This almost perfectly describes https://ciechanow.ski/ as well.
         | Worth poking through if you haven't seen it before.
        
           | netvarun wrote:
           | 100% agree! Bartosz Ciechanowski along with Amit Patel are
           | national treasures. Their expository writing coupled with
           | ChatGPT do dig into some of the more salient points has been
           | a complete game charger for my self learning.
        
           | [deleted]
        
       | NeveHanter wrote:
       | I love this website! It was the place I've understood how A* is
       | working in early 2010s when I started getting into more advanced
       | "standalone" (w/o GameMaker/TGF) gamedev.
        
       | mumintrollet wrote:
       | I remember when I got back into programming, this site was one of
       | the things that really made me excited to code + develop a deeper
       | understanding of algorithms :)
        
       | trees101 wrote:
       | I wonder if graph search algorithms such as described on this sit
       | e(https://www.redblobgames.com/pathfinding/a-star/introduction...
       | ) have applications in other strategies.
       | 
       | Consider a game like Age of Empires. In the beginning you might
       | be able to defend your village by building walls around it. For
       | an attacker, there is a high cost to go through the wall. But
       | when cannons are invented, suddenly the cost of going through the
       | wall drops.
       | 
       | Is there a way to model this? Can you draw a graph of the terrain
       | that looks different before and after the invention of cannon?
        
       | trees101 wrote:
       | Do graph search algorithms have applications for strategy?
       | https://www.redblobgames.com/pathfinding/a-star/introduction...
       | Consider a game like age of empires. The cost of attacking a
       | village goes up when a wall is built around it. But when canon
       | are invented, the cost goes down. Can we model each map (before
       | and after invention of canon) and use it to plan a strategy? Same
       | for building a port , portal or airport.
        
         | VHRanger wrote:
         | That's effectively search on the decision tree. There's a lot
         | of research on this!
         | 
         | Look into Montecarlo tree search, CFRM, AB pruning, and also
         | more recent deep learning methods.
         | 
         | It's a very exciting area of research
        
           | trees101 wrote:
           | Thank you!!! Comments like this are why I love this site.
        
         | recursivecaveat wrote:
         | I would guess it's probably not worth it because "how much do
         | cannons improve my overall position" is a tricky question, and
         | making a really intelligent and sophisticated answer is not
         | really visibly distinct to players from a stupid heuristic like
         | a sigmoid function of how many walls the player has built. It's
         | an amusing curiosity that you can build stupid walls and trick
         | the AI into researching the tech, but it's better to make those
         | walls you're paying for useful, so you can rely on that being
         | generally true.
         | 
         | I think a lot about some advice I heard from the creator of
         | Brogue. Essentially players have a tough time figuring out how
         | AIs make their decisions and often assign complex motives to
         | them when they don't exist. His example was he coded archers to
         | try to maintain a position in some range band from the player
         | as their primary motivation in a vacuum. The community would
         | assign all sorts of supposed logic to archer behavior because
         | in real-world environments with extra geometry or extra
         | situational AI routines they couldn't see behind the curtain.
         | Additionally, that most game AI exists to create a fun
         | experience for the player, we only make it try to play well in
         | service of that goal.
        
           | trees101 wrote:
           | I agree, it seems tricky to actually quantify. The hard part
           | is to create the graph in the first place, before you start
           | the graph search. There must be methods for creating
           | simplified approximations.
        
       | gcr wrote:
       | speak of the devil! i've been putting together a little board
       | game in Godot in my free time, and just finished devouring all of
       | the hexagon content this week.
       | 
       | Amit's work is awesome! Right up there with Inigo Quillez's site
       | on graphics in terms of informativeness and fascination in his
       | own domain.
        
       | g9yuayon wrote:
       | I owe my thanks to this site too. When my team was designing our
       | hexagonal system for geographical analysis back in Uber, I
       | referred to https://www.redblobgames.com/grids/hexagons/ a lot.
        
       | wildrhythms wrote:
       | This article is about dragging, and I've run into all of the
       | pitfalls and come to the same solutions that Amit talks about.
       | Excellent article!
       | 
       | One of the hardest things I have needed to code from scratch is
       | drag-to-reorder. It seem so natural from a user perspective, but
       | when you get into inconsistently sized items, having to create
       | placeholders between items, detecting edges, going down
       | rabbitholes of box-fitting algorithms... it's a fun challenge :)
        
         | aboodman wrote:
         | I have a trick for this that I love that is very general:
         | 
         | 1. When a user begins dragging, calculate the layouts for all
         | possible drop targets (or perhaps just those that are currently
         | visible). 2. For each of those layouts record the position the
         | dragged objects ends up in. 3. On each mouse movement, select
         | from those positions the one that's closest to the dragged
         | object's current position 4. Render the selected layout
         | 
         | This ends up feeling really good and works for any kind of
         | complex layout / reflow.
        
         | pupppet wrote:
         | Oof, or drag-to-reorder while supporting nesting.
        
           | alexbock wrote:
           | I've always been surprised that Apple added this
           | functionality to the iOS home screen without having a
           | solution to the reorder vs nesting UI problem. Trying to move
           | an app into a folder often results in the folder deciding to
           | fly out of the way and let the item take its place when
           | you're really trying to drop something on the folder to
           | insert it.
        
       | npinsker wrote:
       | Off-topic a bit, but I've been curious about a 2D pathfinding
       | problem for a while that this site doesn't seem to tackle despite
       | having lots of articles on the subject. Is there an algorithm out
       | there for finding "enclaves" (i.e. places where you might want to
       | place rewards, spawn the player) within a large 2D terrain grid?
       | 
       | Not super precise, but given a 2D boolean array of
       | pathable/unpathable cells, say generated by Perlin noise, find
       | locations that are only accessible via a relatively narrow "choke
       | point". Example: https://imgur.com/a/jFPXlS5
       | 
       | Standard pathfinding algorithms don't provide enough information
       | to do this, but maybe there's some kind of heuristic approach
       | that could work well.
        
         | stefan_ wrote:
         | Lots of pathfinding solutions prefer to work with connected
         | convex polygons (since inside the polygon, you can always go
         | straight to every other point inside). You could merge your
         | cells into these polygons and then filter for small ones by
         | area, I guess.
        
         | otikik wrote:
         | You are not trying to find a "path" since you don't have a
         | starting point - you only have end points. Your enclaves are
         | more defined by the shape of the walls (roughly x cells in
         | radius) than with the fact that you reach them through
         | chokepoints. After all, a chokepoint can be just a small door
         | in an otherwise big corridor, separating two big areas. And by
         | concentrating on chokepoints you will lose all the "isolated
         | islands".
         | 
         | You might be luckier treating this as a "map treatment"
         | problem. An algorithm that does things to the whole map, and
         | then reads the result.
         | 
         | For example:                 1. Start assigning a score of 0 to
         | all map cells.       2. For every cell in the map, set to 1 if
         | it's in contact with any walls       3. Then add 1 to every
         | cell of the map if it contacts a cell with a non-zero value
         | 4. Repeat the above step n times, where n is the average
         | "radius" of you enclave rooms.       5. Every cell with a score
         | of n or higher is a "candidate". For every candidate:
         | 5.a Check that none of the cells around have a bigger score. If
         | so, move on to the next candidate         5.b Check that
         | there's no "treasure" around it in a circle of radius n
         | 5.c You have found the center of an enclave. Mark it with
         | "treasure" and move on to the next cell.
        
         | Marazan wrote:
         | Brute force and ignorance approach:
         | 
         | Choose random starting point and compute distance to all other
         | points on the map. Repeat for multiple random starting points.
         | 
         | Average the distance.
         | 
         | Points with high average distance are difficult to reach.
        
         | amitp wrote:
         | Tarjan's Algorithm can be used to find choke points, although I
         | haven't tried it myself [1]. I think what I would try is
         | Breadth First Search with multiple start points to calculate
         | various metrics for the map [2] and maybe All-Pairs if you need
         | more [3]. For example, you might use Tarjan's or All-Pairs to
         | find the most commonly used corridors, and then use Breadth
         | First Search from those "central" points to find the "farthest
         | from central corridor" points.
         | 
         | [1]
         | https://old.reddit.com/r/roguelikedev/comments/dc4orn/identi...
         | 
         | [2] https://www.redblobgames.com/pathfinding/distance-to-any/
         | 
         | [3] https://www.redblobgames.com/pathfinding/all-pairs/
        
         | gabereiser wrote:
         | Find starting point in dungeon. A* to every room. Rooms with a
         | large distance (iter count) and with only one or two paths out
         | (choke points, use graph to see edges) become potentials, every
         | potential that is _far & narrow_ is flagged "enclave" with
         | rewards increasing by distance to start.
         | 
         | This is one way to approach the problem. The other way is to do
         | prefab rooms and when generating your dungeons, randomly select
         | one or two prefab enclave rooms to throw into the shuffle.
         | Shuffle the rooms and spread them out then connect hallways and
         | such. This is the approach that Enter the Gungeon took.
         | 
         | Another approach is what @otikik describes. Tracing the walls
         | buy assigning a value to the cells that can then be scored.
         | Minesweeper style.
        
       | displaynone wrote:
       | One thing missing: accessibility. how ought facilitate drag using
       | keyboard controls?
        
         | bastawhiz wrote:
         | Overwhelmingly, the answer is "you don't." Your UI should
         | provide alternatives to dragging that allow folks who can't use
         | a point/touch devices to interact with your page. Which is to
         | say, don't shoehorn keyboard support into your drag
         | implementation, add separate keyboard functionality that makes
         | sense in addition to drag functionality.
        
         | stronglikedan wrote:
         | That would be a _moveable_ object, and I reckon it would be
         | easy to implement using this as a basis.
        
       | json2d wrote:
       | [dead]
        
       | alice-i-cecile wrote:
       | These resources are exceptional: I reference the hexagon page
       | constantly!
        
       | tsumnia wrote:
       | A fantastic site. When I originally took over teaching Intro to
       | AI, I initially relied on the A* search closed/open set
       | pseudocode explanation[1]. However, when it would come time to
       | ask students to implement it, I was constantly finding students
       | absolutely confused by the approach. Once I swapped over to
       | Amit's A* explanation, the number of confused students dropped
       | significantly. Forever thankful for their walkthrough.
       | 
       | [1] https://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode
        
         | amitp wrote:
         | That's great to hear -- thank you!
        
           | tsumnia wrote:
           | No thank you! If you're ever near the NC side of the US let
           | me know, I'll gladly buy you lunch for all the help you've
           | given me.
        
         | gowld wrote:
         | What's the difference between the approaches?
        
           | tsumnia wrote:
           | Amit describes the differences here [2], but briefly:
           | 
           | - The Wiki pseduocode uses Set data structures for
           | everything. While these are covered in classes, the up-tree
           | concept isn't as heavily described as other trees
           | 
           | - Looking at it now, it looks like the pseudocode is a little
           | more beginner friendly, but "back in mah day" it was not
           | 
           | - Although, RedBlob's pseudocode for obtaining neighboring
           | nodes is clearer than "for each neighbor of current"
           | (Wikipedia pseudocode)
           | 
           | - RedBlob uses Priority Queues and Maps instead of Sets,
           | which connect better to other AI searches / recommendation
           | algorithms. Higher 'priority' recommendations move to root in
           | PQs while nodes in Sets... don't... they just sort of 'exist'
           | 
           | - The Maps make looking up node costs more intuitive than
           | lists (aka "current := the node in openSet having the lowest
           | fScore[] value")
           | 
           | [2] https://www.redblobgames.com/pathfinding/a-star/implement
           | ati...
        
           | amitp wrote:
           | 1. I use words for variable names instead of single letters
           | like the textbooks do. I use "priority" instead of "F",
           | "cost_so_far" instead of "G", "heuristic" instead of "H",
           | "cost" instead of "w", "frontier" instead of "OPEN" or "O",
           | "visited" instead of "CLOSED" or "C", "current" instead of
           | "u", "next" or "neighbor" instead of "v".
           | 
           | 2. The textbooks use an "open" and "closed" set. But in code,
           | these aren't explicitly stored in set data structures.
           | Instead, they're implicit. The cost_so_far dict(map) contains
           | as keys both the open and closed sets, and the frontier
           | (priority queue) contains the open set. So in my explanation
           | of A* I focus on these data structures (priority queue and
           | dict) instead of the open/closed sets. And when I do talk
           | about the sets, I talk about the combined open and closed
           | sets, calling it "visited" or "reached", because it's the
           | combined set that is actually in the data structures.
           | 
           | 3. The textbooks use a priority queue with reprioritization.
           | When you visit a node that has a lower cost than the
           | previously found cost, you go into the priority queue and
           | adjust the cost. In my presentation I _don 't_ use
           | reprioritization. Instead, I insert another entry into the
           | priority queue with the lower cost. This makes the priority
           | queue simpler (reprioritization is complicated). And in
           | practice, I think it's faster too.
        
       | throwaway290 wrote:
       | See also slide to unlock game
       | (https://news.ycombinator.com/item?id=36138304). I wonder if it
       | used lostpointercapture.
        
       | phkahler wrote:
       | The page reminded me of Ken Perlins' page:
       | 
       | https://cs.nyu.edu/~perlin/
       | 
       | Yes, the Perlin noise guy among many other things.
        
         | bmitc wrote:
         | I always wish there was more specification surrounding his
         | Perlin noise algorithm he has on his website. For example,
         | asking what the range of output values is does not have an easy
         | answer.
        
           | amitp wrote:
           | I agree, more should be written about Perlin Noise range. You
           | might find this useful:
           | https://digitalfreepen.com/2017/06/20/range-perlin-
           | noise.htm...
           | 
           | In addition to range I'd like to see the distribution,
           | especially with multiple octaves of noises added together. I
           | haven't found a good page about that.
        
       | evmar wrote:
       | I love how half the comments on here are about what a nice person
       | the author of the site is. I, too, have had only positive
       | interactions with Amit!
        
       | qiller wrote:
       | Great write up for all the pitfalls and gotchas that come up when
       | dealing with proper interactions
       | 
       | For something more "out of the box", I've been using interactjs
       | for quite a while for a variety of my projects
        
       | michaelwm wrote:
       | Amit was an instrumental part in the development of one of my
       | favorite video games, Realm of the Mad God. It was a masterpiece
       | of the Flash game genre, and its guild feature introduced me to
       | many lifelong friends.
        
         | kibwen wrote:
         | RotMG has a great idea that I wish more games would copy:
         | difficulty scales with elevation. If you want to take it easy,
         | stick to the coasts. If you want a challenge, strike inland
         | towards the mountains (or follow a river upstream). It's a
         | great way of intuitively expressing difficulty ranges across a
         | sprawling world map, and I remember being disappointed the
         | first time that I played Skyrim that it didn't seem to do the
         | same.
         | 
         | For posterity, here's Amit on map generation:
         | https://simblob.blogspot.com/2010/01/simple-map-generation.h...
        
           | amitp wrote:
           | BTW the newer RotMG maps are based on this http://www-cs-
           | students.stanford.edu/~amitp/game-programming/...
        
           | notsurenymore wrote:
           | Doesn't Ark kinda do this, except with elevation, it becomes
           | more difficult the more inland you travel.
        
       | Decabytes wrote:
       | This is an incredible resource. I will definitely be bookmarking
       | this website for the future
        
       ___________________________________________________________________
       (page generated 2023-09-29 23:00 UTC)