Bay 12 Games Forum

Please login or register.

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

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

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #390 on: January 11, 2012, 01:48:13 am »

Posting to follow. It's been a while since we've had a good programming thread (or maybe I've been lurking too little...)
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #391 on: January 11, 2012, 05:56:17 am »

Posting to watch.
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #392 on: January 11, 2012, 09:24:50 am »

Once again, a lot of my confusion here comes from not knowing what exists in a particular language and what is just an academic term for a system that arises from your code.  It's kind of hard to talk about things like that, because in some languages, words like "object" or "list" or "construct" or "dictionary" are a tangible component with its own syntax, and in other languages they're not.

Best way to think about it is that there are specific concepts. These concepts are pretty much universal, but some languages don't implement them natively and some languages and libraries like to change the names of the concepts. A duck is always a duck, doesn't matter if you want to call it a canard or a ふせり. Once you get used to this, it becomes less of a problem and more of an annoyance ;D
« Last Edit: January 11, 2012, 09:44:35 am by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #393 on: January 11, 2012, 01:10:39 pm »

If it walks like a duck and talks like a duck it should have a duck interface ;)

Once again, a lot of my confusion here comes from not knowing what exists in a particular language and what is just an academic term for a system that arises from your code.
Okay, I now get what you mean: Linked Lists Are Not Things. They are not integers or objects.

One of the early things you learn in an oop language is to make you own linked list, and then you learn to forget about making your own because people smarter than you have made one for you already, and that (here it comes) implementation of a linked list is useable as if it's an object. This also goes for vectors, maps, etc. In some languages even for strings. It's like you said: a construct. BUT most languages have already an implementation of that construct in their standard library. Some have more, for instance Java has a "List" interface, with two implementations, ArrayList and LinkedList. Both act exactly the same, so they are completely interchangeable, except that one is faster at searching and the other is faster at adding/deleting, so which one to use is up to you at that moment. Nothing is stopping you from writing your own unique implementation, though.

tl;dr: So, in short, (for Java and the C's at least) the library has stuff (like maps and lists), that are merely pieces of code written by our betters[1], they do not "belong to the language".

[1]Well, except for the guy who made the standard list implementation for haxe. He was on crack.
« Last Edit: January 11, 2012, 04:42:45 pm by Siquo »
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))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #394 on: January 11, 2012, 03:03:00 pm »

Well, for ruby there's http://ruby-doc.org/
For C++ there is http://www.cplusplus.com/reference/

Though that doesn't include syntax level stuff like the ternary operator.

I imagine other languages have something similar.
Well, there's MSDN for C# and visual basic (and several other .net languages), Oracle's documentation page for Java, the Common Lisp Hyperspecs for Common Lisp and clojure's main site for clojure.


Edit: God-flipping-hell. I just lost 3/4ths of the next chapter of my lisp tutorial. I spent hours on that! Anyway, this means a slight delay in when you'll recieve it.
« Last Edit: January 11, 2012, 05:05:33 pm by Virex »
Logged

nitnatsnoc

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

Thanks to everyone writing the wonderful tutorials. I've re-submerged myself in the learning of programming. I failed out of CompSci in University (not so much due to lack of understanding, as lack of interest in going to a class with a prof. that just didn't care at all).

Stargrasper, I'm very much looking forward to your continuing tutorials. I know you are going through all the basics first, and I'll be devouring those, but I'm hoping for some GUI basics as well some time, as I never learned those at all in school (2 years of CompSci, and we never went past the command line).
Logged

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #396 on: January 11, 2012, 07:22:38 pm »

Thanks to everyone writing the wonderful tutorials. I've re-submerged myself in the learning of programming. I failed out of CompSci in University (not so much due to lack of understanding, as lack of interest in going to a class with a prof. that just didn't care at all).

Stargrasper, I'm very much looking forward to your continuing tutorials. I know you are going through all the basics first, and I'll be devouring those, but I'm hoping for some GUI basics as well some time, as I never learned those at all in school (2 years of CompSci, and we never went past the command line).

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.

Edit: God-flipping-hell. I just lost 3/4ths of the next chapter of my lisp tutorial. I spent hours on that! Anyway, this means a slight delay in when you'll recieve it.

That sucks.  At least it was only a chapter.  Hopefully that only cost you a few hours.  I usually write these in gedit or notepad++ before posting them here (and finally being able to see and correct all the BBCode and HTML that I screwed up).  I don't save often enough.  In fact, none of my tutorials are saved locally.  I should do something about that...

Sorry man.  Good luck.  Also, I feel like you've been reading too much UserFriendly.
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #397 on: January 11, 2012, 08:45:25 pm »


It's not quite as functionally useful as I originally wanted (for the first door on every chamber to be facing the center of the map), but this might actually be better in the end.  My plan for drawing corridors between the doorways is to search the map, making a list of every door-type space and it's coordinates > randomly shuffle the list > for each door, check which side of it has a non-room, and start a corridor there > semi-randomly walk the corridor one tile at a time towards another randomly chosen door, crawl around any chamber wall it comes to.

The only "error" checking method I can think of, to make sure every room can be walked to every other room, is after the corridor cycle is completed, check to see if there are corridor spaces crossing every sectional-dividing line on the map, but it'll be difficult to make sure it doesn't turn into an infinite-loop scenario.  But first, I'll change my buffers a bit, and put some error checking into the walk-around method so the program won't crash if something tries to walk off the map.

Hmm.  I'm not sure of the best way to make my List of Doors and Their Locations.  Some "List" standard object perhaps?  Since it needs to keep track of two bytes as connected to a point in a list.
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.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #398 on: January 11, 2012, 08:51:36 pm »

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.
Logged

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #399 on: January 11, 2012, 08:55:44 pm »

To hold your doors, it might be easier to create a class that holds two objects together and make a list of those things.  For example, a Pair, similar to this implementation for Java from the Apache Commons and create a list containing these objects.  Java example because I don't know what it would look like it C#.
Code: [Select]
List<Pair<Door, Coordinate>> doors;
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #400 on: January 11, 2012, 08:59:16 pm »

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.
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.

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #401 on: January 11, 2012, 09:02:08 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?
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #402 on: January 11, 2012, 09:05:51 pm »

Well, your original idea is not going to work anyway, because it's not a guarantee that all rooms are connected. A coridor could pass through a cell without connecting to the room in that cell.
You'll need to store what's a room in some way though, or at least what's a door as you're making doors in rooms and starting the coridors at the doors. So you'll just have to keep track of what door connects to what other doors, either via a room or via a coridor. That gives you n undirected (and hopefully cyclic) graph, which you can check for connectivity with a flood fill (pick a door. set it to visited. Repeat for all door adjacent to this door that have not been visited. Recur. When done, all doors that have not been visited are not connected to the first door.)
Logged

kaenneth

  • Bay Watcher
  • Catching fish
    • View Profile
    • Terrible Web Site
Re: if self.isCoder(): post() #Programming Thread
« Reply #403 on: January 11, 2012, 09:06:40 pm »

You don't really need to ensure every room is connected, just that that there is a path from the entry to the potential goals (exit to next level, quest item, etc) and if you want, tag a tile in the center of each room as a 'goal' would ensure a path exists to the room.
Logged
Quote from: Karnewarrior
Jeeze. Any time I want to be sigged I may as well just post in this thread.
Quote from: Darvi
That is an application of trigonometry that never occurred to me.
Quote from: PTTG??
I'm getting cake.
Don't tell anyone that you can see their shadows. If they hear you telling anyone, if you let them know that you know of them, they will get you.

Stargrasper

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

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.
Logged
Pages: 1 ... 25 26 [27] 28 29 ... 796