Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 26 27 [28] 29 30 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887980 times)

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #405 on: January 11, 2012, 09:13:01 pm »

If it draws the rooms individually can't you just assign the coords to a list or something and then compare the floofill algorithm's results to that?

Probably, yeah, I just haven't put a lot of thought into it.  I'm mostly hoping that drawing enough overlapping paths between doors will solve the problem, and even if not, that's a later thing.  I just want to be able to walk between rooms.

My checklist is something like (1)Corridors (2)Interacting with the terrain (3)Other entities moving around (4)Interacting with them (5)Making a "turn" system that differentiates between actions that complete and don't complete.

None of them are particularly necessary to be done before the others, but I feel like making fully-ish-working maps first.  I don't know why.

Second...to flood-fill check...temporarily create a 2d array of the same dimensions as the map.  Start checking coordinates on the map until you find a true (a room) in the map array. and mark that as true in the check array.  Check all surrounding cells in the map array and if true, mark as true in the check array.  Repeat for all trues found.  When you can't find any more trues in the map, compare the two arrays.  If they aren't the same, that is, you have trues in the map array that aren't in the check array, you're missing rooms.  Long and arduous error check, but potentially worth doing.  There's other ways of doing this that are probably better, but this was the first process that came to mind.

Thanks for the help, but that actually just gave me another idea.  It's not particularly fast I guess, but it's not impossible.  I'll just have the map-array scanned from side-to-side and top-to-bottom.  If it runs into a row or column that doesn't contain any walkable tiles (with catch to skip over the borders, like checking if it runs into walkable locations after it finds a row with none), it'll know there's stuff somewhere in the map that can't be walked to from somewhere else in the map, and can keep adding new hallways until it does.  Cycle-consuming maybe, but it only has to happen once per map.
« Last Edit: January 11, 2012, 09:15:02 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #406 on: January 11, 2012, 09:18:33 pm »

Second...to flood-fill check...temporarily create a 2d array of the same dimensions as the map.  Start checking coordinates on the map until you find a true (a room) in the map array. and mark that as true in the check array.  Check all surrounding cells in the map array and if true, mark as true in the check array.  Repeat for all trues found.  When you can't find any more trues in the map, compare the two arrays.  If they aren't the same, that is, you have trues in the map array that aren't in the check array, you're missing rooms.  Long and arduous error check, but potentially worth doing.  There's other ways of doing this that are probably better, but this was the first process that came to mind.

Thanks for the help, but that actually just gave me another idea.  It's not particularly fast I guess, but it's not impossible.  I'll just have the map-array scanned from side-to-side and top-to-bottom.  If it runs into a row or column that doesn't contain any walkable tiles (after skipping over all tiles between the edges and the first thing it comes to), it'll know there's stuff somewhere in the map that can't be walked to from somewhere else in the map, and can keep adding new hallways until it does.  Cycle-consuming maybe, but it only has to happen once per map.

You came up with a simple and good idea.  Your way should work fine and is a lot easier to code than mine.  It is less efficient than mine, though, because your idea has to check every cell of the map twice.  There are better ways of doing this than what I suggested, but my way (and yours as well) make it so that you don't have to rewrite any existing code.  Just keep in mind what you're doing and make it work.  You can make it work well later.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #407 on: January 12, 2012, 03:33:09 am »

well like I said, it does actually need to be two pieces of data in itself - the X and Y coordinates in the map array - and then whatever way they're kept track of as a list, so I can shuffle it.  I just need to look around in C# documentation for something that would fit, and I could certainly brute-force it with another array or something.

why don't you just use a floodfill algorithm to check if everything is connected? Start at one room and if it doesn't connect to all the rooms you've got a disconnection.

Because I don't have any idea how to tell it where a room is and isn't.  The rooms aren't objects or anything in themselves, the entire map is just a 2D array of bytes that get interpreted as tiles by other parts of the terrain.  It doesn't store room-locations at any particular point, because it draws each room individually.

I can picture ways to make that work, so that it would at least know what areas of the array to find room-relevant tiles in, but I don't know the first thing about flood-filling anyway.

First part...you could look into the C# documentation for a class that fits what you need.  But if you know exactly what you need, it might be faster to just define your own class that does what you need.  Make a tuple class that contains a Door, an X-coord, and a y-coord.  Make a list of these tuples.

Second...to flood-fill check...temporarily create a 2d array of the same dimensions as the map.  Start checking coordinates on the map until you find a true (a room) in the map array. and mark that as true in the check array.  Check all surrounding cells in the map array and if true, mark as true in the check array.  Repeat for all trues found.  When you can't find any more trues in the map, compare the two arrays.  If they aren't the same, that is, you have trues in the map array that aren't in the check array, you're missing rooms.  Long and arduous error check, but potentially worth doing.  There's other ways of doing this that are probably better, but this was the first process that came to mind.
That is the hard way. If you got 2 doors in a room, they are connected via that room. If you've made a corridor between two doors they are also connected. Since every door is part of a room (if there are doors between corridors, use only room doors for this check), a disconnected door is a disconnected room. Now, the doors form an undirected graph, see attached picture. All we need to do is take 1 door and walk the whole graph. If there's a door that is disconnected, then we've got a disconnected room.
Spoiler: Illustration (click to show/hide)
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #408 on: January 12, 2012, 08:16:03 am »

Why wouldn't a Door have its own Location? That eliminates the need for a tuple.

Aqizzars way will also not work, because if you have 6 rooms like this:
Code: [Select]
R--R  R
|     |
R  R--R
You have no connection, but your search won't find it. You should make rooms into objects with location, width, height, and then map them onto the map. This makes collision detection and letting corridors go around rooms a lot easier, as well, eventually.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

nitnatsnoc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #409 on: January 12, 2012, 10:48:24 am »


I'll get to it...I was intending the next tutorial two days ago, but life has been happening.  Did you see my tentative roadmap?  It's highly volatile, it could change at the drop of a hat, but it gives a preview of how I'm likely to handle the near-term future of the tutorials.

Yes, I will probably cover GUIs eventually.  Especially if someone is explicitly asking me to.  At the very least, you need to understand classes.  Understanding datastructures would help as well.  If you think you have a grasp on these, I can write a more advanced topical lesson on it sooner.

If you're coding a GUI directly in Java, you're probably using AWT, Swing, SWT, or some combination thereof.  Plus Java is capable of using external GUI libraries.  I haven't decided how to cover that yet.  The fact is, however, that in the real world, you don't code many GUIs in Java.  There are certainly exceptions, but you often interface Java applications with a web interface or some other external system.  There are a few different ways of handling that as well.

I saw the road map and I'm perfectly happy with it. I need to relearn all the fundamentals anyway. I mentioned GUI only because I don't know what else to call it, and maybe I should be saying something else. If you say real world development doesn't use much Java GUI then what would I use? For the moment, my short term goals (beyond that of learning basic Java) is the production of some simple (I hope) tools to replicate some of the tasks I do in my normal day anyway (I'm a System Administrator). As much as the long term goal of making a game might be more appealing, I know it's far to long term to keep me focused or interested.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #410 on: January 12, 2012, 03:05:10 pm »

In other news, C++11 is awesome.

Code: [Select]
for(auto child : getChildren()){ }And we get constructor chaining, generated inherited constructors...
It's almost as if the syntax grew a generation.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #411 on: January 12, 2012, 03:30:26 pm »

I saw the road map and I'm perfectly happy with it. I need to relearn all the fundamentals anyway. I mentioned GUI only because I don't know what else to call it, and maybe I should be saying something else. If you say real world development doesn't use much Java GUI then what would I use? For the moment, my short term goals (beyond that of learning basic Java) is the production of some simple (I hope) tools to replicate some of the tasks I do in my normal day anyway (I'm a System Administrator). As much as the long term goal of making a game might be more appealing, I know it's far to long term to keep me focused or interested.

In the real world, sometimes you have a GUI directly from Java.  More often you have a non-graphical UI so you can use it on the command line or you have an independant GUI that just interfaces the Java application and grabs data to display from there.  Businesses like using Java to write internal-use applications.  As such, they don't necessarily have to be pretty since nobody outside the corporation is supposed to see them.  Or the Java code get run server-side and output data gets displayed with HTML and JSPs or PHP or something.  I'll write a tutorial on coding AWT/Swing/SWT eventually.  If you want, I can write some on JSPs and other methods of interfacing with Java apps on a server at some point.

I'll probably write the next tutorial this afternoon.  I like to go into a lot of conceptual detail, so these take awhile to write.

What tools are you trying to replicate?  Some of these may be more effective and potentially easier to replicate in C++.  Incidentally, if you're a sysop, you probably want your tools to run with a CLI anyway, so a GUI may not matter to you.

In other news, C++11 is awesome.

Code: [Select]
for(auto child : getChildren()){ }And we get constructor chaining, generated inherited constructors...
It's almost as if the syntax grew a generation.

I read the specs for C++11 a while back.  It seems really impressive.  I'm definitely looking forward to using it.  Are you reading specs or actually playing with it?  Does that mean g++ has implemented C++11?
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #412 on: January 12, 2012, 03:30:35 pm »

Aqizzars way will also not work...
You have no connection, but your search won't find it. You should make rooms into objects with location, width, height, and then map them onto the map. This makes collision detection and letting corridors go around rooms a lot easier, as well, eventually.

Yeah, that seems pretty obvious now.  I'm still committed to the Rooms-As-Objects rewrite, because I don't see the point really, but I can think of how to make it work.  Likewise, it's becoming increasingly obvious to me that my shortcut plan to just make the map an array of bytes, and then interpret those elsewhere, is going to be a huge pain in the ass later on, especially when I get to visibility.  The tiles really should be objects, because I'm already finding myself writing methods to interpret their byte of data in five different ways, and having the tiles themselves keep track of all this would be much much easier.

I don't why I'm so reticent to rewrite any of this code for that matter.  My "roguelike" is not some artistic vision, it's a learning experiment first and only.  I should be doing this the full-blown way.


I think the tile rewrite will be my next project, since rewriting the room generation will be a lot easier after that than before it.  I still want to tackle my current project first, and at least make sure that I know how to random-walk a connection from one point to another around objects.  My pseudo code calls for do-while loops inside if-ladders inside do-while loops inside if-ladders inside a do-while loop which is all contained in a function to be called by a for-loop in another function which is itself called by another function which is called by the map-generator function.

Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #413 on: January 12, 2012, 03:44:28 pm »

It also allows for you to use polymorphism to handle different sorts of rooms, thus making things like a treasure room guarded by Dagon, or an alter with Cthulhu priests priests standing around insanely easy to implement.


I'm just going to assume the Lovecraft Mythos is canon in your game from now on...

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #414 on: January 12, 2012, 03:44:58 pm »

I need to stop looking at things like Aqizzar's code at 2AM.  I should have seen that fallacy in it.  My way was the hard way, but it should work.  It's based on a wavefront planner I've used to program robots when the field is known.  Aqizzar, you might be able to simplify your code by using Wishful Thinking.

http://dsoguy.blogspot.com/2007/01/programming-by-wishful-thinking.html

I'll write a tutorial on this eventually.

For now, I suggest not re-writing your code.  In the real world, you're given code and you have to work with what that idiot in India wrote because you can't change it.  You don't get to do things intelligently; you have to find work arounds for the prior design decisions.  Finding these work arounds is just as much a learning experience, if not a better one, than re-writing the code intelligently.

That aside, if you correct every design mistake you ever make as you find them, the project will never get done.  Regardless of what it looks like, a major goal of every project should be to get it out the door.
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #415 on: January 12, 2012, 03:58:09 pm »

For now, I suggest not re-writing your code.  In the real world, you're given code and you have to work with what that idiot in India wrote because you can't change it.  You don't get to do things intelligently; you have to find work arounds for the prior design decisions.  Finding these work arounds is just as much a learning experience, if not a better one, than re-writing the code intelligently.

That aside, if you correct every design mistake you ever make as you find them, the project will never get done.  Regardless of what it looks like, a major goal of every project should be to get it out the door.

Yeah, but I'm not building on work from some guy in India, I'm writing my own code.  And as long as I have the freedom to, I'd rather at least teach myself good coding practices.  I think my CompSci101 brute force instincts, combined with some experience doing things the right way, should prepare me to kludge a fix to any problem someone else's code presents.

I do think it would be fascinating to compare different people's roguelike codes, just to see how many alien ways a few people can approach the exact same requirements.

And all that being said, I'm writing a new MapTile class right now, which will save me loads of work and headache and duplication of effort in the future, and then I'll make a RoomObject class.  This shouldn't take more than a hour or two of grunt work.

I'm just going to assume the Lovecraft Mythos is canon in your game from now on...

You're not gonna believe what really will be canon in this practice game.  I know I've never seen a roguelike go where I'm going.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #417 on: January 12, 2012, 04:04:52 pm »

...

Is it the MSPA roguelike?

That's Project #3, you'll have to wait for it.

No, just to forestall anything stupid, I'm actually going to gear it towards a roguelike-ish interpretation of Super Mario Bros 2.  Why?  Because it was my favorite, it had a really cool design style, and more than anything, years ago when I made DIY plug-in games, I would recreate Shyguys for placeholder enemies.  I really like them for some reason.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #418 on: January 12, 2012, 04:05:22 pm »

you have to work with what that idiot in India wrote
LOL for truth :)

Yes, g++ 4.3 and up does c++11 IF you specify that in a commandline option (-std=c++0x, which is because they thought they'd be done with it sooner ;) ), I'm playing with it now. Hmm, the multithreading isn't available for windows yet, it seems... Too bad.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #419 on: January 12, 2012, 04:05:57 pm »

No, just to forestall anything stupid, I'm actually going to gear it towards a roguelike-ish interpretation of Super Mario Bros 2.  Why?  Because it was my favorite, it had a really cool design style, and more than anything, years ago when I made DIY plug-in games, I would recreate Shyguys for placeholder enemies.  I really like them for some reason.

That is awesome.  :)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout
Pages: 1 ... 26 27 [28] 29 30 ... 796