Temple of The Roguelike Forums

Development => Programming => Topic started by: XLambda on March 06, 2012, 12:49:23 PM

Title: Java RL tutorial!
Post by: XLambda on March 06, 2012, 12:49:23 PM
Since quite a few people seem to be interested in RL development with Java, and since there is no fitting tutorial that I know of, I've started to just go ahead and write one.

If everything goes right, it should:

-> be generic and not based on a single specific library. I'll use Slash's libjcsi, which is basically a swing implementation of curses, so the basic methods should all be provided by whichever library you prefer. (I'll encapsulate it anyways, so no worries.)

-> provide basic algorithms that, while not up to most people's standards, do the job and are easy to understand.

-> not do any l33t r0gu3l1k3 h4x. Yes, there are some crazy programming things you can do to make your life easier. Do they make things easier to understand? No.

-> result in a horribly soulless, unbalanced, flavourless, boring, playable little game. The emphasis is on playable, lol.

Once I have the basic data structures laid out, others are very welcome to contribute. I might put it up at roguebasin if people like it.

I do need some help, though - I'm searching for a simple and easy to understand FOV algorithm. I usually use something like MRPAS, but that's just waaay too complicated for a tutorial.
Title: Re: Java RL tutorial!
Post by: george on March 06, 2012, 04:30:03 PM

Once I have the basic data structures laid out, others are very welcome to contribute. I might put it up at roguebasin if people like it.

I think that's a good idea, Jotaf's Python tutorial at RB has become very popular.

You might want to think about leveraging existing libraries for things like FOV. For the purposes of a make a RL tutorial it might sidetrack people too much, unless your goal is to write a FOV tutorial too.
Title: Re: Java RL tutorial!
Post by: XLambda on March 06, 2012, 05:08:52 PM

Once I have the basic data structures laid out, others are very welcome to contribute. I might put it up at roguebasin if people like it.

I think that's a good idea, Jotaf's Python tutorial at RB has become very popular.

Yeah, I'm going to put it there once the first parts are done.

You might want to think about leveraging existing libraries for things like FOV. For the purposes of a make a RL tutorial it might sidetrack people too much, unless your goal is to write a FOV tutorial too.

Yeah, that's true. I'm not too fond of using yet another library, though... I think I'll cheat and implement Rogue-style fov, since I track rooms and tunnels seperately. Or would that be too simple, seeing as most modern roguelikes use more advanced algorithms? ??? What do you people think?


EDIT: In hindsight, I might want to drop the encapsulation of the library. It feels cleaner to me, and allows people to exchange the library if they want, but it makes the key handling horribly awkward and complicated, and I think actually understanding what's going on might be more important than making the library exchangeable.  :-[
Title: Re: Java RL tutorial!
Post by: XLambda on March 08, 2012, 11:21:29 PM
Okay everyone, the two first chapters are done and the third is being worked on. As soon as it's done, I'll put them on roguebasin for everybody to look at and comment. Probably tomorrow, if things work out.

Urist McProgrammer has claimed a Writer's Workshop!
Urist McProgrammer is working furiously!

;D
Title: Re: Java RL tutorial!
Post by: XLambda on March 09, 2012, 05:59:14 PM
Okay, the first two lessons are up at roguebasin. ;D

http://roguebasin.roguelikedevelopment.org/index.php/Java_Roguelike_Tutorial

There wasn't enough time for the third, unfortunately. I'll do that after the 7drl week.

I'd appreciate some comments and constructive criticism. I tried not to do to much Java leetspeak, but you kind of have to assume that people know what a class is, or that it has a constructor. :-\
Title: Re: Java RL tutorial!
Post by: Nachtfischer on March 09, 2012, 07:08:58 PM
Just skimmed through the first two parts. Though nothing revolutionary happened until now (not that it needed to in a tutorial :P) that seems to be some pretty neat and solid stuff. Make it nice small and easy to follow steps, many tutorials really lack that property.
Title: Re: Java RL tutorial!
Post by: requerent on March 10, 2012, 12:46:06 AM
Quote
Many newbies go for IDEs like eclipse. These are tools intended for experienced developers, and their features are intended to automate frequent or annoying tasks, not to remove the necessity of knowing how to do them on your own.


Code completion, context hints and dynamic syntax checking are GREAT for new programmers or anyone using an unfamiliar library.



For the second tutorial- just a quick recommendation-- You've got a bunch of independent if statements. They really should be a switch, or at least a bunch of if-else statements- otherwise you're making a lot of wasted comparisons.

I'm not directly familiar with the CharKey constants, but here's the gist

Code: [Select]
//...
switch(csi.inKey().code)
{
case CharKey.UARROW: if(--y < 0)y++; break;
case CharKey.DARROW: if(++y > 24)y--; break;
case CharKey.LARROW: if(--x < 0)x++; break;
case CharKey.RARROW: if(++x > 79)x--; break;
case CharKey.Q: stop = true; break;
}
//...

In this case, you always have O(C) comparisons where C = 2, whereas otherwise you have O(N) comparisons- where N is the total possible number of input keys. It's so insignificant, but stuff like this is good to learn when the concepts are still simple and can make a big difference later in generation time when doing world-generation and historical simulations.

edit: stumbled across the proper keywords.
Title: Re: Java RL tutorial!
Post by: XLambda on March 10, 2012, 10:31:53 AM
Quote
Many newbies go for IDEs like eclipse. These are tools intended for experienced developers, and their features are intended to automate frequent or annoying tasks, not to remove the necessity of knowing how to do them on your own.


Code completion, context hints and dynamic syntax checking are GREAT for new programmers or anyone using an unfamiliar library.

I don't doubt that. My main sentiment here is that IDEs - besides the pure coding, for which they are undoubtably awesome - offer such a large and confusing set of features that you actually need to know what you're doing when using them.

For the second tutorial- just a quick recommendation-- You've got a bunch of independent if statements. They really should be a switch, or at least a bunch of if-else statements- otherwise you're making a lot of wasted comparisons.

I'm not directly familiar with the CharKey constants, but here's the gist

Code: [Select]
//...
switch(csi.inKey().code)
{
case CharKey.UP_ARROW: if(--y < 0)y++; break;
case CharKey.DOWN_ARROW: if(++y > 24)y--; break;
case CharKey.LEFT_ARROW: if(--x < 0)x++; break;
case CharKey.RIGHT_ARROW: if(++x > 79)x--; break;
case CharKey.Q: stop = true; break;
}
//...

In this case, you always have O(C) comparisons where C = 2, whereas otherwise you have O(N) comparisons- where N is the total possible number of input keys. It's so insignificant, but stuff like this is good to learn when the concepts are still simple and can make a big difference later in generation time when doing world-generation and historical simulations.

Yup, that I forgot. I'll change it. :)
Title: Re: Java RL tutorial!
Post by: purestrain on March 11, 2012, 03:52:02 PM
Its really boring; thats just another tutorial like any c ones, isn't it?
Title: Re: Java RL tutorial!
Post by: XLambda on March 11, 2012, 04:04:52 PM
Its really boring; thats just another tutorial like any c ones, isn't it?

I would say that Java and C/C++ are quite different languages, though the first few chapters don't really emphasize that.
Title: Re: Java RL tutorial!
Post by: requerent on March 11, 2012, 10:54:42 PM
Its really boring; thats just another tutorial like any c ones, isn't it?

I would say that Java and C/C++ are quite different languages, though the first few chapters don't really emphasize that.

Java prevents you from needing to do as much work >_>.
Title: Re: Java RL tutorial!
Post by: TheCreator on March 12, 2012, 07:34:01 AM
Java prevents you from needing to do as much work >_>.

Java only prevents you from having control over low-level operations, which may be a good thing if you are writing a coffeebreak game, or if you hate programming :).
Title: Re: Java RL tutorial!
Post by: requerent on March 12, 2012, 08:42:37 AM
Java prevents you from needing to do as much work >_>.

Java only prevents you from having control over low-level operations, which may be a good thing if you are writing a coffeebreak game, or if you hate programming :).

So all Java developers hate programming?  ::)

That's probably true. After all, the increase in productivity means you 'get' to do less of it.
Title: Re: Java RL tutorial!
Post by: XLambda on March 12, 2012, 10:55:19 AM
Could you stop the hating, please? ::) I know that you C++ folks think your language is better, and I'd be happy to argue with you as I speak both. But this is a tutorial, and a newb is not interested in whether Java is better or C++. And he sure as hell won't care about low-level programming. For tutorial purposes, Java has a few big advantages over C++, it's portable (one toolchain and one exec for all platforms), it has a huge class library and it abstracts from some of the more mind-boggling aspects of C++ (Pointers? Really, Stroustrup?).

Also, the only other tutorial at roguebasin is in Python, and I know what you C++ folks think of THAT language... ;D
Title: Re: Java RL tutorial!
Post by: kraflab on March 12, 2012, 09:02:45 PM
Could you stop the hating, please? ::) I know that you C++ folks think your language is better, and I'd be happy to argue with you as I speak both. But this is a tutorial, and a newb is not interested in whether Java is better or C++. And he sure as hell won't care about low-level programming. For tutorial purposes, Java has a few big advantages over C++, it's portable (one toolchain and one exec for all platforms), it has a huge class library and it abstracts from some of the more mind-boggling aspects of C++ (Pointers? Really, Stroustrup?).

Also, the only other tutorial at roguebasin is in Python, and I know what you C++ folks think of THAT language... ;D

This discussion makes me wonder if a better tutorial might be one that is entirely pseudocode based.  Give someone the gist of what type of problems/solutions exist for roguelike programming, and show off the basics.  Maybe provide an implementation in a few languages at the end of each section so that the viewer can decide for themselves which language looks best for them.  Of course, your tutorial is exactly what it is supposed to be: a "Java" rl tutorial.  So I think the debate over which language is better is kind of irrelevant to this thread.  Although, in terms of "newb" friendliness I would have picked a language that already has everything you need, rather than something that requires importing libraries, not that there's anything wrong with that in the global sense.
Title: Re: Java RL tutorial!
Post by: XLambda on March 12, 2012, 09:21:16 PM
Could you stop the hating, please? ::) I know that you C++ folks think your language is better, and I'd be happy to argue with you as I speak both. But this is a tutorial, and a newb is not interested in whether Java is better or C++. And he sure as hell won't care about low-level programming. For tutorial purposes, Java has a few big advantages over C++, it's portable (one toolchain and one exec for all platforms), it has a huge class library and it abstracts from some of the more mind-boggling aspects of C++ (Pointers? Really, Stroustrup?).

Also, the only other tutorial at roguebasin is in Python, and I know what you C++ folks think of THAT language... ;D

This discussion makes me wonder if a better tutorial might be one that is entirely pseudocode based.  Give someone the gist of what type of problems/solutions exist for roguelike programming, and show off the basics.  Maybe provide an implementation in a few languages at the end of each section so that the viewer can decide for themselves which language looks best for them.  Of course, your tutorial is exactly what it is supposed to be: a "Java" rl tutorial.  So I think the debate over which language is better is kind of irrelevant to this thread.  Although, in terms of "newb" friendliness I would have picked a language that already has everything you need, rather than something that requires importing libraries, not that there's anything wrong with that in the global sense.

And which language would that be? ??? Using libraries for displaying stuff and handling keys has been done ever since Rogue, I'm not aware of a language that doesn't need something like it. If you know one, please do tell me more.
Title: Re: Java RL tutorial!
Post by: kraflab on March 12, 2012, 11:00:10 PM
Could you stop the hating, please? ::) I know that you C++ folks think your language is better, and I'd be happy to argue with you as I speak both. But this is a tutorial, and a newb is not interested in whether Java is better or C++. And he sure as hell won't care about low-level programming. For tutorial purposes, Java has a few big advantages over C++, it's portable (one toolchain and one exec for all platforms), it has a huge class library and it abstracts from some of the more mind-boggling aspects of C++ (Pointers? Really, Stroustrup?).

Also, the only other tutorial at roguebasin is in Python, and I know what you C++ folks think of THAT language... ;D

This discussion makes me wonder if a better tutorial might be one that is entirely pseudocode based.  Give someone the gist of what type of problems/solutions exist for roguelike programming, and show off the basics.  Maybe provide an implementation in a few languages at the end of each section so that the viewer can decide for themselves which language looks best for them.  Of course, your tutorial is exactly what it is supposed to be: a "Java" rl tutorial.  So I think the debate over which language is better is kind of irrelevant to this thread.  Although, in terms of "newb" friendliness I would have picked a language that already has everything you need, rather than something that requires importing libraries, not that there's anything wrong with that in the global sense.

And which language would that be? ??? Using libraries for displaying stuff and handling keys has been done ever since Rogue, I'm not aware of a language that doesn't need something like it. If you know one, please do tell me more.

I use Blitzmax.  It's a really professional grade language, in terms of functionality, but it is tailored directly at making games (which is not to say that anything is over-simplified: you can still do things like function pointers, inheritance/polymorphism, pass by reference, etc).  It is cross-platform compilable from the same source code, with a bunch of graphics commands built in (i.e. you can call "drawimage image" without needing headers etc).  Of course, people still make external libraries for it, but I've never really had a need to use them.  Actually, you can even import code from other languages, such as C++.  The main downside is that it is not free, although you can use all functionality except creating an executable from the demo - so it's fine for the sake of a tutorial.  I've programmed everything from video games to monte carlo simulations in it, and I can't think of any specific functionality it does not have that other languages do.  People say that it is less efficient than c++ in general, but I've never really had any problems myself.

It's kind of like taking python's simplicity and development speed, but slapped onto a c++ style system and without the need to have python installed ;)

edit: I just remembered the one thing I wish it had: operator overloading.  But that's not really a deal breaker for me  :P