[SH15] The Human CPU Experiment
Bruce Perry

The Human CPU Experiment

Do you take your computer for granted? Have you ever wondered what it must be
like to be your computer? Now you can try it. (Some programming experience may
be required to get the most out of this game.)

Title screen

{"name":"11130-1","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/f\/3f318a9e6da261c5293d8b0840bb3789.png","w":1031,"h":762,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/f\/3f318a9e6da261c5293d8b0840bb3789"}11130-1

Gameplay :o

{"name":"11129-1","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/8\/18ffed44d16212016d0825522627dcf3.png","w":1031,"h":762,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/8\/18ffed44d16212016d0825522627dcf3"}11129-1

Don't let that daunt you. Give it a go.

{"name":"11094-1","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac7d4c5fa3f819c149494126ce6346a6.png","w":1040,"h":806,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac7d4c5fa3f819c149494126ce6346a6"}11094-1

Links

Download - Blog

Bruce Pascoe

Hey, this is pretty creative! :D

GullRaDriel

Well done, Bruce !

I liked the way it go all pesky when wrong ^^

I played it 4 times in a row.

I don't want to spoil those who're gonna play it, but it's worth the try !

Mathematics would have been more pleasant to learn fo me if I had learned them in your entry ;-)

amarillion

Hiscore: 9A6F: I beat HAL 9000!

I really like the steadily increasing difficulty of it. Towards the end it gets really creative doing boolean operations on base 4 numbers with two calculations on the stack. And for the CHR$/ASC conversions, that's just guessing for me.

For the hiscore table. The only one I don't recognize is MCP - are you really referring to Microsoft Certfied Professional?

edit: looking at the source code, I'm taken by the use of unicode in variable names:

From hyperparticles.d:
version = usePoincaréBall;

:D

GullRaDriel

Master Control Program, you punk.

amarillion

Duh of course :-X

Bruce Perry

Indeed! I had to remove an é from my SpeedHack blog because it didn't render correctly :-X

Glad you like it :)

GullRaDriel

M. Poincaré was French. The accent made his name so it is never spoken like 'Point car' (point voiture). A comical French to English translation could have been UseSquarePointBall ;-p

Bruce Perry

I just got E4D9, which makes me feel beating Data is just about achievable on a good day with some practice.

When I was tired from staying up all night, I couldn't get close. The tiredness was a bit of a problem given I was trying to balance the scoring so that beating all the robots was a good balance of challenging but achievable. I think I must have got it about right though, at least for us lot. :)

Elias

I can't figure out the "computer says NO" ones :P

Peter Hull

"Computer says no" is from a TV program called Little Britain (but maybe that's not what you meant?)

I was interested to see that Ben and Siegelord wrote their entries in D and Rust respectively and I'd love to hear about how you found that, compared to C/C++.

amarillion

When computer says no
no, you have to respond no for exactly as many times, using the correct form (no n0 No etc.)... except when it's prefixed with sudo...

devo_au

Text based math game with old monochrome feel. Had 2 gos. First until it started asking me mod questions, then I ran out of time. Second, I ignored the mod, then the hex, then the Binary ??? and I noticed your particle engine kicked in. Well done mate, very good effort.

Bruce Perry

Thanks :)

As always, D is a breath of fresh air. Basic conveniences like GC built into the language, not to mention random acts of syntactic sugar all over the place (like $ inside [] to refer to the length of the current array). I do of course have one or two reservations about it as a serious language: difficulty avoiding the GC if you need to, and a slight case of 'only one compiler really works so far'. That's DMD, and while it excels on executable size, it isn't the best for generated code speed. Then again, these things are always improving. There's also Visual D which helps a lot with the editing process, although one or two things could be slightly nicer with very little effort (like autocomplete looking at substrings anywhere instead of only matching the beginning). One other thought is that you do have to know D's semantics, and if you aren't entirely clear, it's possible to shoot yourself a bit (e.g. 'foreach' loops if you don't know to use 'ref' at the right times). A language like C# might be marginally better in that regard because the spec is smaller. But compared to C/C++ in terms of language usability - no contest. (Of course C/C++ have widespread support and tooling on their side though, despite STILL requiring header files - really, in this day and age? Why wasn't it C++11's PRIMARY focus to get rid of those monumental wastes of time?)

I'm also looking forward to hearing SiegeLord's Rust review :)

Edgar Reynaldo

Crashes right away with an access violation.
{"name":"609556","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/6\/f67be5faf2f19b27ecc958abe7eb5bc5.png","w":294,"h":165,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/6\/f67be5faf2f19b27ecc958abe7eb5bc5"}609556

I don't have a working D compiler installed so I can't really test it further. gdb fails to recognize it as an executable file format it knows.

Bruce Pascoe

@Bruce Perry
I don't mind headers so much in C, I view them as a necessary evil of the compiler/linker dichotomy, but they are THE primary reason I hate using C++. Want to write a library in C++? Good luck hiding your dependencies from the outside world because all your private members have to go in the public header! (I realize the pimpl idiom solves this, but it should be built into the language.)

The biggest problem with C++, I think, is that it strives for backward compatibility with C at all costs. It would benefit greatly from breaking that shackle, I think.

SiegeLord

Now I feel bad about making my computer do all this math stuff :-[.

I'm also looking forward to hearing SiegeLord's Rust review :)

Not going to highjack this thread... I'll make some comments on my own thread ;).

Mark Oates

{"name":"609559","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/0\/401ffc07da9b7ccacd21a33432b1964d.png","w":1919,"h":1079,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/0\/401ffc07da9b7ccacd21a33432b1964d"}609559
it's gametime 8-)

[edit] nerd credit is also obliged to the fact that Data is the boss of this high score table. #completelyagree

Bruce Pascoe

I think that's considered cheating... ;)

SiegeLord

It's called a lookup table, nothing wrong with that ;).

Bruce Perry

Edgar, sorry to see that. You did extract it from the zip before running it, I assume? Shame there's no stacktrace - there normally would be, under the dashes. If you do have time, you might be able to install Visual Studio 2013 Community Edition (it's free) and attach it as a debugger and find out more. You might even not need D, although you will probably have to start it with the debugger attached (somehow) rather than running it and attaching later.

Mark, how did you do with your cheats in place? Did you get to some questions you weren't prepared for? :)

Edgar Reynaldo

gdb says its not an executable file format. And I can't install VS2013 because it needs like SP3 and .NET 4.5 or something.

I tried running it through VS2010 and this is all it gives me - there's no debugging info.

Quote:

Unhandled exception at 0x00000000 in HumanCPU.exe: 0xC0000005: Access violation reading location 0x00000000.

Bruce Pascoe

That's a null dereference. Something failed to load properly. I wonder if it's that XP XInput initialization bug that was recently fixed...

Bruce Perry

Will it not even show you a stack trace?

Edgar Reynaldo

No, that's all I could get.

GullRaDriel

up, up, up ?
then print the number of byte it tried to malloc ?

Edit: you didn't ran it through the debugger ?

Bruce Perry

Gull, are you mixing it up with Elias's entry where we found out that a calloc failed?

Edgar seems to be the stalwart SpeedHack crasher this year :-/ I would suggest some asm-level debugging, but it's obviously up to Edgar how much insanity he's willing to take :)

GullRaDriel

Yeah, you're right about the mixing up Bruce ^^

Edgar Reynaldo

Bruce - if you can help me get a working D compiler set up I can try to build it myself, but I have zero experience with D so you'd have to guide me through it. Also, how should I debug it without Visual D? Or does Visual D support MSVC 2010? That's the latest version I can install on my Vista laptop.

Bruce Perry

OK, first thing I should say is, I'm in Germany with a laptop that doesn't have any of this set up. I'm flying home tomorrow evening, and I'm wondering if there's a PDB sitting at home that I could share with you first before we start trying to set up an environment. I'll be able to check for that on Saturday (or maybe Friday last thing).

If you do want to start setting stuff up, then:

Get D from http://dlang.org/download.html - it has an installer. I installed it in C:\D, and ended up with a compiler in C:\D\dmd2\bin (which is worth adding to the path). If you get a choice, don't bother with D v1 - just take D v2.

DAllegro5 is best git-cloned from https://github.com/SiegeLord/DAllegro5 . You will need the 5.1 branch, since I used 5.1 features (ALLEGRO_PROGRAMMABLE_PIPELINE). You will then need to go into DAllegro5/allegro5/base.d and tweak the version to match whichever version of Allegro you have. After that SiegeLord has instructions for building DAllegro5 (see https://github.com/SiegeLord/DAllegro5/tree/5.1), but I had dashes in my path and found them a bit temperamental and had to tweak them. It also needs tweaking if you have monolith DLLs since the names don't match up.

As for Visual D, I believe it does support MSVC 2010, but you will need a version of MSVC 2010 that supports plugins. In terms of free versions, I think there is an 'express' edition which WON'T work, and there is a 'shell' edition which WILL work (it allows plugins but comes without C/C++ or any other language support built in).

I think I included the Visual D project files in the zip, but I used global settings (not project settings) to specify where DAllegro5's .d files and .lib files can be found. You'll need to do the same. For the .d files, you need to specify an 'import' directory - it's a bit like an include directory. You may need to get rid of DAllegro5's example.d file (although it's possible I only had a problem with this when I had my own copy of it in my project).

It's a lot, I know :-/

[EDIT + BUMP]
I just got a score of E3C5. Data isn't safe for ever :)

Edgar, I've attached a Debug executable. Any luck with that one?

Edgar Reynaldo

This is the only output. gdb still doesn't recognize it as an executable, and MSVC 2010 can't open it.

Quote:

c:\ctwoplus\progcode\allegro5\SpeedHack2015entries\HumanCPU>HumanCPUdebug.exe
object.Error@(0): Access Violation
----------------
Press Enter to close

c:\ctwoplus\progcode\allegro5\SpeedHack2015entries\HumanCPU>

GullRaDriel

Maybe your antivirus is blocking it ?

Bruce Perry

Come to think of it, I think this may be an outstanding issue with D that I've hit before: no stack traces on access violations. I remember having to step through it with the debugger to find out where the bug was. Obviously that's not presenting itself as an option for you at the moment.

Try the attachment. I opened it with VS 2010 Shell and built it from scratch. You will probably need to install Visual D (which is really easy), but you hopefully won't need anything else D-related. Once you've done that, open up main.d and set a breakpoint on the very first non-import line: "int main(string[] argv) {". Set another breakpoint on "return main2();" because the stupid thing won't single-step properly into al_run_allegro. Then run it, single-stepping as you go, and see how far it gets, I guess? Another thing you can try is the Disassembly window; for me, it intersperses it with source code so you can make sense of it pretty easily, and it helps you sidestep those cases where single-step doesn't work properly.

Edgar Reynaldo

I can't install Visual D properly because I'm using an Express Edition of 2010. It won't integrate with VS in the installation.

Edit

Try the attachment. I opened it with VS 2010 Shell and built it from scratch.

Where did you get the VS 2010 Shell from?

Bruce Perry

It was a download once upon a time. Looks as if MS have discontinued it :(

I found my copy of the download. Give it a try. [EDIT: finally finished uploading!]

Peter Hull

Got it running on Mac, not without a few issues in D to do with int <-> ulong conversions and also a problem with the shaders. (more detail tomorrow, I'm off to bed now)
Nice one!
Pete
{"name":"609587","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1ef09206c7d404250dfbef873746651.png","w":819,"h":640,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1ef09206c7d404250dfbef873746651"}609587

Onewing

Excellent entry, love the way it deforms and raises concern per every wrong answer. Definitely the most intense of the 2015 entries. Would've love some way to skip questions (perhaps a collectible item if you can answer within a second or something)...but computers don't skip questions. :D

Peter Hull

These are the only diffs I had to make for it to run on OS X.

#SelectExpand
1diff --git a/game.d b/game.d 2index eb06529..779e66c 100644 3--- a/game.d 4+++ b/game.d 5@@ -21,7 +21,7 @@ Ready 6 Set 7 Go!!! 8 `; 9-int introPos; 10+ulong introPos; 11 int introDelay; 12 char[] currentAnswer; 13 bool inputActive; 14diff --git a/questions.d b/questions.d 15index 9247646..b6dc447 100644 16--- a/questions.d 17+++ b/questions.d 18@@ -153,9 +153,9 @@ bool answerIsRight(const(char)[] answer) { 19 } 20 21 int questionRange() { 22- int r = 1 + questionCount / newQuestionTypeEvery; 23+ ulong r = 1 + questionCount / newQuestionTypeEvery; 24 if (r > questionGenerators.length) r = questionGenerators.length; 25- return r; 26+ return cast(int) r; 27 } 28 29 auto questionGenerators = [ 30diff --git a/shaders.d b/shaders.d 31index 2a049c9..b364e5e 100644 32--- a/shaders.d 33+++ b/shaders.d 34@@ -26,9 +26,8 @@ uniform bool ` ~ ALLEGRO_SHADER_VAR_USE_TEX ~ `; 35 varying vec4 varying_color; 36 varying vec2 varying_texcoord; 37 void main() { 38- ivec2 ts = textureSize(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, 0); 39- float yf = fract(varying_texcoord.y * ts.y) - 0.5; 40- float brightness = 1.5 - abs(yf)*2; 41+ float yf = fract(varying_texcoord.y * 55.0); 42+ float brightness = yf * (1.0 - yf) * 4.0; 43 if (` ~ ALLEGRO_SHADER_VAR_USE_TEX ~ `) 44 gl_FragColor = varying_color * texture2D(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, varying_texcoord) * brightness; 45 else

It looks like .length is a ulong on my platform, not an int, so I put in some casts.
On the shader, AFAICS textureSize isn't supported. I know absolutely nothing about GLSL, googled a bit and it seemed to be that OSX gives you OpenGL 2.x by default unless you ask for a "core profile". Maybe someone who understands OpenGL can make sense of that. Also it seemed to complain about multiplying ints by floats, in "varying_texcoord.y * ts.y" and also "abs(...) * 2".

Cheers,
Pete

Bruce Perry

Thanks for getting it working on the Mac :)

Does abs not exist? I'd have expected you could just change it to "abs(yf)*2.0"? I started with the same quadratic formula you have there, but it didn't give a consistent brightness as I scaled the resolution, which is why I took the linear approach with 'abs'.

Your screenshot looks a bit wonky in another way too: different rows of characters get their scanlines done differently. I'm going to guess that the texture actually has powers of two for dimensions (why textureSize is so important); you could probably fix it on your system by writing 64 instead of 55, but I wouldn't trust it as a general fix.

So in summary, you could try this code if you want:

-  ivec2 ts = textureSize(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, 0);
-  float yf = fract(varying_texcoord.y * ts.y) - 0.5;
-  float brightness = 1.5 - abs(yf)*2;
+  float yf = fract(varying_texcoord.y * 64.0) - 0.5;
+  float brightness = 1.5 - abs(yf)*2.0;

I can't say I've ever heard of a 'core profile' - perhaps it's an Apple thing?

Onewing said:

Excellent entry, love the way it deforms and raises concern per every wrong answer. Definitely the most intense of the 2015 entries. Would've love some way to skip questions (perhaps a collectible item if you can answer within a second or something)...but computers don't skip questions. :D

You can sort of skip questions, because when you get one wrong, it increases a variable called 'severity', and when you get one right, it decreases it again. As long as you get some right after the one you got wrong, nothing is lost (except that difficulty has still progressed a bit and you missed out on the points for that question). :)

Peter Hull

I tried a lot of different things to get it to work (as has been mentioned, debugging D seems ... challenging) so the screen shot doesn't necessarily correspond to the code (see below for what it does look like). I thought the quadratic looked better to my eyes. You're right, abs does exist, I will change it.
609609

Bruce Perry

The 9000 isn't a perfect test because all those glyphs came from the same row of the png, but the scanlines do seem to match up with the pixels, so it's probably correct with whatever you have now (55 or 64) :)

By the way, in case you wondered, the slight saturation effect (where it goes too bright to represent and the green gets clamped while the red and blue don't) is deliberate. It makes it look a little more interesting than if everything is perfectly one colour.

Edgar Reynaldo

Bruce - no success yet, but perhaps progress.

I'm trying to compile Allegro 5.1.11 to use with DAllegro5 so I can compile your human cpu project, but it barfs on trying to make an MSVC 2010 project. What version of Allegro does your program need to compile? I can get binaries for 5.0.10 if that works. Okay I have the 5.0.10 binaries in a folder called c:\msvc\, but I haven't the faintest idea how to configure a VS project to link to allegro, and I don't know how to get the DAllegro5 example to build either.

Bruce Perry

Sorry I haven't replied for so long. Only just had a chance to look here!

It does unfortunately need 5.1.x.

I wonder if this zip will help? It includes a built version of Allegro 5.1.x, and built versions of all the D libs corresponding to Allegro's DLLs. I also included my txt file with lots of instructions, most of which you won't need to follow, but it includes a bit of stuff about how to configure the IDE (you can ignore the Derelict bits since I didn't use that for this game). If you want to use the prebuilt stuff in here, you may be best obtaining D v2.066.0, since the more versions newer you go, the more likely those libs are to be incompatible. (I apologise - the zip is still uploading. Give it half an hour maybe. I just checked and it's 404ing until it's ready, so you won't get a broken file.)

Thread #615497. Printed from Allegro.cc