Allegro.cc - Online Community

Allegro.cc Forums » The Depot » [TINS2016] Spring

This thread is locked; no one can reply to it. rss feed Print
[TINS2016] Spring
Gassa
Member #5,298
December 2004
avatar

Spring is a simple puzzle game developed during TINS 2016 competition. The rules of the game - the ones implemented before the deadline - are as follows.

Consider a poem by a well-known author (we got poems about spring by Фёдoр Иванoвич Тютчев in Russian and Emily Elizabeth Dickinson in English). The poem is broken into four-line paragraphs. Each paragraph is then split into words, becoming a puzzle. Given the words all mixed up, put them in place to reconstruct the paragraph, and proceed to the next one.

There are four lines with slots for words. Obviously, lines may have different number of slots in them. When you place a word in the correct slot, the slot becomes highlighted. When all words are placed correctly, you can proceed to the next paragraph.

{"name":"spring.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fb83cb322f13af626786c90437bb2257.png","w":562,"h":507,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/b\/fb83cb322f13af626786c90437bb2257"}spring.png

Source (in D programming language): http://acm.math.spbu.ru/~gassa/tins/spring.zip

Windows binary with 5.2 DLLs: http://acm.math.spbu.ru/~gassa/tins/spring-binary.zip

This is perhaps my shortest attempt at speedhacking so far (~15 KB, 614 non-empty lines of code). We got only a few hours off this weekend (with two kids, finding free time is hard!), so the game does not have images, sound, or polished puzzle rules. Still, I'm glad we submitted a working entry (unlike in Speedhack 2015) which implements this year's rules to an extent. As previously, I did all the coding, and my wife helped with design and data.

Edit: repacked zipped files so that everything is in a directory.

Eric Johnson
Member #14,841
January 2013
avatar

The Windows binary worked for me using Wine in Linux.

I like the game. :D The interface is nice and clean, and I like how the text "slots" adjust to fit the size of the text placed in them. Nicely done.

I've seen a few projects using D pop up recently. I'm curious, what are the advantages to the D programming language?

GullRaDriel
Member #3,861
September 2003
avatar

Nice and running fine on Window7.

I like the hint thing, it's a cool thing. I tried all the (4 or 5) Dickinson verses.

It was fun, I had pain when it didn't even told me I finished and simply blopped the main menu :-(

Good job, good entry.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Gassa
Member #5,298
December 2004
avatar

Thanks for the comments!

It was fun, I had pain when it didn't even told me I finished and simply blopped the main menu :-(

Hmm, the last "Next" button should be in fact a "Finish" button. However, I agree that it's not anywhere near to being a gratification for completing the game :) . The competition deadline was approaching... well, you know the rest.

I've seen a few projects using D pop up recently. I'm curious, what are the advantages to the D programming language?

I'll share my take at it. For me, D does not have any one "killer feature". Instead, it has the small niceties I value in other languages, baked into the single language.

  • I like being productive when all I care about is to make things work, the sooner, the better (rich standard library).

  • I like it when the language is reasonably safe so I can write code with just few bugs (type system, general safe-by-default attitude), and then have means to find the rest (stack traces, easy debug output).

  • I like it when the language compiles to native code so that speed at the bottlenecks is on par with what I can possibly do (e.g. using C).

  • I like coding in a simple text editor (so e.g. Java is too verbose for me).

  • When a program gets larger and evolves, I often become frustrated by the amount of restructuring and boilerplate I have to do. In this regard, D was the least disturbing experience compared to the few other languages I used to this extent (Pascal, C, C++, Python).

Sure, there are also some difficulties, like low popularity (only few people around me try D), instability (the language is still evolving, the specification is not set in stone), occasional compiler bugs (no massive manpower backing language development) - but since you asked about advantages, I won't get into details now :P .

Eric Johnson
Member #14,841
January 2013
avatar

Thanks for the reply, Gassa. D seems pretty interesting. I think I'll look into it for myself, though I highly doubt anything could persuade me away from C++.

Bruce Perry
Member #270
April 2000

Gassa said:

I like it when the language compiles to native code so that speed at the bottlenecks is on par with what I can possibly do (e.g. using C).

While I agree with your points in general, I find this one interesting, because do you know that DMD doesn't generate very fast code at all? Did you use one of the other compilers? I tried one or both of the others a while ago (a year or more?) and hit some problems (possibly exceptions didn't work?). Presumably they're always improving though, and I noticed the download page on the D website encourages the other compilers more than it used to.

So, as for your game - I found the idea nice at first, if a bit daunting. When I realised that you don't have to think about the poems at all since you can just keep trying stuff until it lights up, I was pleased I had an easy way out but also a bit sad that the mechanic allowed me to ignore the poem entirely. Not sure how I'd fix that myself. I do recognise you had very limited time, and it's nicely done considering :)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Gassa
Member #5,298
December 2004
avatar

So, as for your game - I found the idea nice at first, if a bit daunting. When I realised that you don't have to think about the poems at all since you can just keep trying stuff until it lights up, I was pleased I had an easy way out but also a bit sad that the mechanic allowed me to ignore the poem entirely. Not sure how I'd fix that myself. I do recognise you had very limited time, and it's nicely done considering :)

Yeah, the mechanic is not the most thought through. I can think of a few amendments though. In fact, I already made a (more playable) rhyme puzzle before, but since it wasn't public by the time of the competition, I could not have used any of the code. On the bright side, we did everything (puzzle rules and code) from scratch, and I can now merge successful parts of one approach into another.

On to the language discussion which is admittedly a bit off-topic - do tell if I have to move it to another sub-forum!

Bruce Perry said:

While I agree with your points in general, I find this one interesting, because do you know that DMD doesn't generate very fast code at all? Did you use one of the other compilers? I tried one or both of the others a while ago (a year or more?) and hit some problems (possibly exceptions didn't work?). Presumably they're always improving though, and I noticed the download page on the D website encourages the other compilers more than it used to.

It is true that DMD's optimizer is weaker than GDC's or LDC's. Most of the time however it's good enough for me.

Here's some context. A good portion of the code I write is related to various algorithmic programming contests. In these, contestants have to write fast enough solutions to a number of algorithmic problems in a limited time frame. Sometimes I'm on the contestants' side, other times, on the judges' and organizers' side. The problem solutions are usually rather small programs (most are up to a few hundred lines) but still push known algorithms and data structures to their limits. The performance bottleneck is usually carefully written procedural code doing some number crunching. Historically, the languages most used in the contests nowadays are C++ and Java.

In this setting, most solutions compiled by DMD are close in speed to their direct translation to C++ compiled by Visual Studio or GCC. In the majority of cases, for similar solutions, the timing is C++ < D < Java, with D being close to C++. However, I've seen all six possible permutations :) . The spread between languages varies from problem to problem: sometimes it's less than one per cent, other times, tens of per cent. In the few bad cases where DMD produced slow binaries, manual optimization usually helped. When I cared to check GDC and LDC a few times, they produced binaries with speed similar to a C++ translation.

The point is, in this setting, it is very clear that the choice of algorithms and data structures matters much more than the choice of a (compiled) language or compiler. So, I'd rather have the comfort of writing in D and get things done and debugged faster. After that, I can take the time to squeeze the remaining few per cent of performance if need be - or move on if it's already good enough, which is usually the case.

Chris Katko
Member #1,881
January 2002
avatar

How's your luck with debugging?

I'm learning D on-and-off and every time I do something wrong, I'm greeting by a SEGFAULT and a stack trace completely full of garbage collection.

Like one I mentioned in a previous thread, I dared to use a string concate inside a destructor/finalizer (which invokes the Garbage Collector and crashes). It was a nightmare coming from C++. All I was doing was trying to output a message when a class was deleted.

I feel like debugging in D is many steps backwards compared to Clang with C++ (which is downright beautiful.) (It seems like) I rarely get the right line number, and the stack trace is always clobbered.

So how do you go about debugging successfully? I know that once I stop making "insane mistakes"... mistakes that someone who understood the language would never make, I'll probably be better off.

I also wish there was more tool chain support. Like the plethora of static and dynamic analyzers for C++ and other more popular languages. At least Valgrind (should) still work for dynamic code coverage, and I found D-Scanner for static which I might start hacking to add my own custom code-checks.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Bruce Perry
Member #270
April 2000

I remember your thread. I haven't encountered the destructor GC problem myself.

Generally, debugging is pretty stable for me. I can step, view variables and whatever I need to do. One thing worth noting is that exceptions don't include the line where they happened, only the lines from the calling methods. In a 'throw' statement, I think the line where it happened is generated at compile time, but if you have an array bounds error or a non-matching final switch or something, then you will be missing that information. It's a bit surprising and disappointing, although I can't say I'm familiar with what C++ offers in these cases.

Gassa, it sounds as if DMD is better than I thought it was...?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Gassa
Member #5,298
December 2004
avatar

I feel like debugging in D is many steps backwards compared to Clang with C++ (which is downright beautiful.) (It seems like) I rarely get the right line number, and the stack trace is always clobbered.

So how do you go about debugging successfully?

Hmm, what OS and architecture are you on? I'm on Windows and usually do 32-bit builds, sometimes 64-bit. All I do is throw a simple -g switch into a debug build. The line number of the bottom function, like main, is usually corrupted, but since I'm most interested in the top of the stack anyway, this is rarely a problem.

The only thing for which I don't get a meaningful stack trace is stack overflow (oh the irony), but the fact makes it easy to distinguish as well.

Regrading clang for C++, I have to try it to compare. GCC (which I use) does not show any stack at all, and even with a switch like _GLIBCXX_DEBUG, I only get to know that, for example, an out-of-array-bounds happened somewhere, but not the exact location.

Also, debug output in D is super easy compared to C++, with debug writeln (x); doing the right thing for many types out of the box.

Chris Katko said:

I also wish there was more tool chain support.

Some tools for analysis, like profiler (-profile) and code coverage (-cov), are built into the compiler. But sure, there are tons more tools for C++.

Gassa, it sounds as if DMD is better than I thought it was...?

Your mileage may vary. For instance, if you depend on a library which relies on LDC or GDC optimizations (heavy use of ranges everywhere is an example), you will definitely get the slowdown compiling with DMD. As I've said, my measurements are for short standalone number crunching programs.

Also note that not only LDC and GDC are improving, but DMD as well ;) ...

Chris Katko
Member #1,881
January 2002
avatar

I've been trying LDC and GDC on Ubuntu 64-bit.

Whenever I get a crash, if I bring it up in gdb and get the back trace, I often get nothing. Which means I'm stuck resorting to debug writefln lines instead of going straight to the error site.

I think peppering asserts / contract-programming everywhere will help keep problems from leaving their sites reducing my tracking time. But it's still frustrating compared to Visual Studio's debugger, or even C++.

As for Clang, it's almost the same as GCC/etc. But the error messages are much prettier, clearer, and color-coded. From what I recall, because GCC runs an optimization pass before it flags errors, it's much easier for GCC to get confused, miss the real error, or at least resort to a more generic error. Clang will also offer suggestions ("You wrote 'boundry', did you mean the variable 'boundary'?") which immediately helps you realize what the error is--a typo. I don't think GCC does that, but maybe it does or newer versions do.

https://woboq.com/blog/moc-with-clang/mocng-error.png

http://ximalas.info/wp-content/uploads/2012/05/clang-colorful-and-informative-diagnostic.png

Also Clang is super-insanely fast. GCC may produce better optimization on final builds (by a small fraction), but Clang compiles a super-template-heavy project (ChaiScript) I was using in less than half the time. It was miraculous. 12-seconds vs 5-seconds can mean the difference between losing your train-of-thought or not while solving a problem. It also makes a big difference when writing code on my Netbook (which I often do now) which has a mere 2nd/3rd-gen Atom processor.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Gassa
Member #5,298
December 2004
avatar

I've been trying LDC and GDC on Ubuntu 64-bit.

Whenever I get a crash, if I bring it up in gdb and get the back trace, I often get nothing. Which means I'm stuck resorting to debug writefln lines instead of going straight to the error site.

Heh. So the difference is that I much prefer debug output and inserting a bit of assert contracts to interactive debugging. But we're not going to start a holywar over the Right Means of Debugging, right? ;)

Chris Katko said:

Also Clang is super-insanely fast. GCC may produce better optimization on final builds (by a small fraction), but Clang compiles a super-template-heavy project (ChaiScript) I was using in less than half the time. It was miraculous. 12-seconds vs 5-seconds can mean the difference between losing your train-of-thought or not while solving a problem. It also makes a big difference when writing code on my Netbook (which I often do now) which has a mere 2nd/3rd-gen Atom processor.

DMD is the fast compiler for D (but producing slower binaries, as discussed above). Did you try DMD on your system? The site http://d-apt.sourceforge.net/ may be worth a visit. Or not; I don't use Linux much, and didn't try the D APT repository myself (or GDB on Linux binaries generated by DMD, for that matter).

Mark Oates
Member #1,146
March 2001
avatar

>bump< so it doesn't lock too soon.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Gassa
Member #5,298
December 2004
avatar

Exported from personal Subversion repository to GitHub (if only to prevent a thread lock): https://github.com/GassaFM/Spring.

A bit of story on my TINS experience to make this post interesting.

On Friday, we just discussed the rules and thought about making a rhyme puzzle, only the designs were either not likely playable or didn't have pathfinding, so we thought about making a simple but completely separate part for pathfinding.

We spent like the whole Saturday with our two kids, busy with real-life stuff.

On Sunday, I went to implement some interface primitives, and ended up with a few GUI classes for the bright future, a working menu screen to test them... and nothing more since real life kicked in as it tends to.

So on Monday morning I was sitting at my PC thinking that it's over for us. Eventually, I found some ways to boost my morale, amarillion's post among them (thanks!!!). As it states, Anybody can write hangman in 2 hours. Well, a rhyme puzzle is not too far away. So I just dropped the idea of following the grand plan of our entry to any degree, and proceeded with the strategy of "just put in the next tiny thing that would work; repeat". Indeed, the GUI design was not yet too horrible and was extended with a few hacks, so two or three hours later, our entry finally resembled a playable game.

In the end, I didn't find a suitable English verse with literal "snow" in it (the Russian version has two occurrences of the word), and about pathfinding, I can only do a suspicious hand-wave, but the other rules are fine.

Go to: