Subscribe via RSS Become a friend on Facebook Follow me on Twitter

Cymons Games

Ruler

June 6th, 2008

You are ruler over a small country. Your management over a single resource will determine the rise or fall of your nation. For such a short and simple game, there’s a surprising amount of challenge to be found. And just when you think you have a grip on the way the game works and act of god can destroy everything you planted that year. Hope you kept your stores stocked. If you can get your kingdom to a point where they can support themselves your people will grant you an early retirement.

Ruler is written by Stephen Parkes based on a BASIC game for the ZX81 written by A. Greenhalgh of Darwen, Lanacshire and published in Sinclair User March 1983.

14 Responses to “Ruler”

  1. David Brady

    I like this concept and I would like to help except I don’t speak C. I want to learn, so I downloaded CodeBlocks and I was very impressed. One question about it, can I write and compile C programs without creating projects for each one? I want to save each of the examples I type in from my ‘Teach yourself C’ book but I don’t want a project for each example. After I get a little experience, I plan to convert a lot of old basic games to C. I have several books and several PDF’s of books that should make good type ins when I get them converted. Keep up the good work.

    David.


  2. sparkes

    I’m not sure how to set up code::blocks to create multiple executable targets. That’s the sort of thing that is easy when using a makefile but not so easy in an ide.

    If I was you I’d just set up a project for each little program it’s only going to add a couple of files and it will make maintainance much easier for you in the long run.


  3. Joe

    Actually, in code::blocks you can simply make a blank file, save it (.c or .cpp), and compile without a project. The problem with this is the compiler makes certian assumptions which can occasionally come around and bite you. You can always edit those assumptions but on a blank file it prompt you to do so the way it does when you make a project.

    But for single file projects just compiling the blank file without a project is often good enough.

    Truth is I do this alot, tho I’m planning on going back and recompiling EVERY program that goes on the site in a project in the near future. I’ve noticed that C::B sometimes assumes C++ for C which makes some significantly larger exes, as well as some other little oddities I want control over.

    Good question, and something I’ve been looking to address. Thanks.


  4. Nige

    You’re trying to teach people how to code in C and you put ‘goto’ in a program? That’s *terrible*.


  5. Joe

    Trying to teach? You see any tutorials around here? There’s enough of those on the net to choke a donkey. No, I’m just showing cool programs that will hopefully inspire you to program. If you learn something, well, all the better.

    Heh, just kidding.

    As for the gotos, I never use them. But this program was submitted by someone else, Sparkes above. Consequently it was not my code to re-write (tho I did make some minor tweeks).

    Now did you quote the “terrible” because you realize that gotos aren’t actually that bad? I mean, they’re dangerous and very abusable, but in reality assembly does a lot of gotos. They’re bad because they can break encapsulation and flow, but in this case they’re kinda use “properly”, if there is a right way to use them.


  6. sparkes

    The goto makes the algothim easier to understand so explain to me what makes that ‘terrible’?


  7. Joe

    I’m sure there’s a source somewhere I can site, but in short goto allows for the sort of unchecked mucking about with the code that makes the people who write the language standards so nervous that it is common to “recommend” against using goto, and there are those in certain camps who avoid it with a religious zeal. That is to say they not only state their position as a fact but will also publicly belittle anyone who does not see things the way they do.

    Here’s the problems with goto:

    o You can jump from one function into another function.
    o This means you could get a return call without a function call, say jumping from main to a sub function.
    o This also means you could end up calling variables that haven’t been declared.
    o On a smaller level you can jump from one bracket level to another, a point that is generally handled well by most compilers but there is no standard way to handle that problem (as far as I know).

    In short, it makes people nervous. But don’t let it bother you. You used it properly, as I said.


  8. Gustav Bertram

    The whole crusade against goto began after Edsger W. Dijkstra submitted an article to the ACM called “Go To Statement Considered Harmful”.

    Personally I’ve never actually seen a goto statement used in a C program before. In this case, removing goto is trivial.

    You can put everything after “input:” inside a neverending while loop. Then, simply place everything after the “sow+eat>food” block, inside an else block. Remove all gotos and labels.

    See? It doesn’t even need any structure changes.


  9. sparkes

    True Gustav and under the hood it would work exactly the same way.

    Dijkstra stated many times before his death that most people screaming about goto’s had never read his essay or understood its context; it’s very helpful sometimes to be able to have such fine control over program flow. There are many algorithms that can be made much more efficient by their use.

    At the time I wrote this I did it as a break in coding Z80 machine code so I wrote it similarly to code at that low level. So it made sense to use a jmp rather than a call because I didn’t want to fill the stack. Interestingly translating my algorithm and yours to asm the most obvious way would end up looking exactly the same way and a decent optimising compiler would compile your while loop to a jump back to the top as well. The goto is acting like a hint to the compiler as to an efficient route :)


  10. sparkes

    s/their/there in the second paragraph :)


  11. Gustav Bertram

    If you’re an assembly coder, then it makes sense that you’d use goto. You’re used to it.

    I *have* read Dijkstra’s article, and it’s quite clear that he thinks goto should only be used for exceptions like exiting nested inner loops. Using goto as a looping construct is still bad form.


  12. Gustav Bertram

    At least, in C it is.


  13. Bradford

    I just noticed that the expression that calculates the population isn’t simplified. It’s “people = (eat/people)*(people/2)+eat” which is the same as “people = 1.5*eat”. So the population DOESN’T depend on the previous year’s population, only on the food you eat. For some reason, when I run the game, it alternates between “people = eat” and “people = 1.5*eat” though..

    The strategy to win the game then is just to only feed the people 10 every year until you get nearly 2000 food, then feed them about 1000 food in one year.


  14. Joe

    Well, that line was taken from the original BASIC game. Actually it’s corrected from the original game because in the original it’s based on the amount of food in store, not the amount you feed them, that information isn’t used for anything. But you’re right, it’s wacked.

    I think the idea was to take the ratio of food per person and apply it back to the people, so if there was half as much food as there were people that would affect the number of people negatively, but if there was more food per person that would affect it positively. But it’s clear that this is not the way to do it.

    So what would you suggest to fix it?


Leave a Reply

Cymons Games. All programs provided without guarantee or warranty. Maintained by Joseph Larson.
If you have any questions or notice something is wrong please contact me. Powered by WordPress.