14 September 2009

Delve a little late

The next release of Delve, with type checker and bug fixes is gonna be maybe another week away - development is going very well and smoothly, but I've decided to create a cool program I've been thinking about for a while -

See, in a pen and paper RPG, if the players decide to completely ignore the intended quest, for some reason and hang around in a bar instead, the dungeon master (DM) must be able to improvise, either to push them on to the intended quest, or instead to facilitate their mucking around, perhaps by creating a new quest.

This is something you can never have with World of Warcraft or Fallout or any computerized RPG game - well, something you can never have without a lot of artificial intelligence research.

So I want to develop a computer aided rpg system which allows for the flexibility of pen and paper RPGs as well as the complex rules and speed of a computer system. I'm gonna call it C.A.R.P, or just carp, because it's less of a pain to write that way.

There are some computer aided rpgs around - notably OpenRPG and RPG virtual table-top, but carp will differ from them.

I feel virtual table-top is, from the DM's perspective, too text based. It covers many things with documents which would be better written as scripts. Improvisation takes place entirely within a chat window - and then the benefits of programmatic game-play is lost . We can do better than this!

For instance, the player should have a panel of buttons which correspond to 'obvious actions' - stuff like the classic "GO NORTH", "CLIMB UP THE ROPE", "SHOOT THE KOBOLDS WITH YOUR GRENADE LAUNCHER". These are obviously dependent on your location, the current item you have equipped - this is dependent on the game rules, which is dependent on the DM.

Therefore, the DM needs to be able to add widgets to the player's GUIs at his whim. The game needs a scripting system, then, which is powerful enough to give the DM this control.

Also the computer should be able to generate appropriate adversities for the players to fight at any point, this would require statistical analysis, but that's ok.

Of course, a chat window is mandatory for information.

Erlang is a good choice for development language - because it can evaluate itself as a script and can send data around networks and has really good control over its own processes.

The power of erlang is such that its easy(ish) to imagine a player using an item in the game world which would cause a whole new game window to open, containing a whole new copy of carp - but one that exists literally inside the players universe - like in the xkcd comic.

Features, with the more important features ( those I'm going to implement first ) closer to the top:

GUI
Network support - can be played over the internet
Run-time scripting so the DM can improvise when needed
Game rules and content, built using the run time scripting mentioned above
Hot-seat mode - so more than one player can share a computer
Support for a mix hot-seat and network play - so say four people can play together with only 3
Tools for statistical analysis of various things in the game - so for instance the DM can generate appropriate adversities for the players

Features carp will not have:
animation
on-screen maps (print em or draw em, so your players can write on em)
grilled chicken

Also Lizzie notes that I've sunk to new levels of geekiness.

11 September 2009

sXe analysis

Lepht got me thinking about the straight edge (also known as sXe).

I think the most interesting thing about sxers is the phenomenon that they form a community at all. It is like a monastery, where every member must abstain - and also partake in cabal approved recreation - that is the dancing you will see if you go to a hardcore gig.

But, as is asked in the faq "Why do you need a label to be poison free?". The answers presented do not satisfy me.

The first: "this label help keep us together and stay strong."

So you're weak? That interesting - so a sxer might rely on other sxers to help them fight their own cravings for drugs and drink. It worries me that a person who doesn't drink or smoke can be so terrified of ruining their life through excess that they need a support group.

The second answer satisfies me even less: "the label shows you're actually serious about what you're saying and that you're not making any exceptions"

In what way does a label show that you're serious? You could be lying and just saying you're sxe! The only way for a person to know you're serious is a close study of your behaviour over a long period of time. This answer is, to quote Dr. Sheldon Cooper, demonstrably fallacious.

The author goes on to admit that the sXe is corrupted by hypocracy, but is an ideal to be aspired to. Since others can corrupt the ideal through corrupting their own bodies, and can do this without your knowledge, how then can a person reasonably trust those who share their community? They cannot.

The commitment must be taken on word of mouth. Now I'm moving beyond the world of logical analysis, which is my tool since I have no subjects to interview, but my hypothesis would be that commitment is viewed as the cool factor of a real sXe community - a community which, through members lapsing and then getting control back, over time fades into grey like an animation reel of black then white, rather than the dichotomy of abstinence and corruption.

Government sentimentality

I protested against the Iraq war in Glasgow because I hate the pain and the fear and blood that I knew would come with it; it sickens me! But all this posturing sickens me further.

I'm so sick of the platitudes voiced by the media and our weak government that I worry that I'm turning into a right wing, highly opinionated, weirdy-beardy geezer.

Are people really shocked that the CIA torture people? Have we run out news? Perhaps people will next complain that the army kill people! Really, how are they going to get answers out of prisoners? Play the enemy limp bizkit until they bleed from the eyes? Ahh but see, they're the not the 'enemy' because this isn't a war - they're evil criminals who are facing justice. Oh pleeeeese.

On the subject of evil criminal prisoners: if people are worried about terrorism, why are they upset about the more peaceful relationship we can have with Libya, now that Megrahi has been transfered? Surely with peace, the threat they pose to us is diminished.

Of course, lots of MPs and the US also are making a big stink - hang on a minute - these people are so upset, they would rather irritate a developed foreign power, than transfer a man from a jail here to a jail there. This is the sort of idiocy which leads to war. Of course, it's okay if you're the US 'cus you can just bomb them again if you get really pissed off.

In this case, those who hold the moral high-ground and are not prepared to compromise are the dangerous ones. Don't they realize the other side think that they have the high-ground too? Will they instead fight over that ethereal hillock?

Since we're talking about hypocrisy and deliberately aggravating other nations, western policy on Iran needs a mention. In fact, I'd say it takes the biscuit. Now I really don't like the stuff their regime does. But why, when you consider other weird/aggressive countries (I'm looking at you, China, Russia, Pakistan and the good ol' U. S. of A. ) do we have such a strong stance against Iran? Why do we try to interfere with their nuclear program and lay sanctions against them and not China?

It's because they're weak. Our leaders want them to stay weak so they do not threaten us. It's the truth, but it's the scary truth no-one is ready for, and no-one wants to admit.

Who're the nasty scary countries again?

The question is: Why do these powerful men who invaded Iraq and Afghanistan shy away from the war and bloodshed and pain, and hide behind a false chivalry? Have they learned nothing from Caesar and Ghengis Khan? Khan achieved not great moral victories but lasting prosperity and safety for his people!

Also, to perform this false crusade they had to lie to their own people - about having a moral right to fight against some 'axis of evil'. I think some of the people who are now upset bit the doctrine a little hard, and did not fully comprehend the consequences of a war. To these people I recommend spending some time looking at bombs, bullets and their local hospital's casualty ward.

And about the possibility of Cameron being in charge of the next righteous crusade - now this is subjective - however well he might run things, I wouldn't trust him standing next to me with a pistol in his pocket. He's just some geezer - the sort of people I trust with guns are military types who know what they're for and understand their safe operation and maintenance.

Did you know the UK has no launch codes for its nuclear weapons? The submarine captains are in absolute control over world destruction - but no one is worried. It seems that warriors can be trusted to keep the peace - while politicians arguing amongst themselves spread deceit and death.

Have a swell day!

9 September 2009

Things wot I dun wrong, or how I learned to love compiler development

The Delve typechecker is nearly done, a patch should be pushed by the end of the week. It infers interfaces of objects instead of their concrete types, and so it acts like a strongly typed Smalltalk or Ruby, which was the plan.

Anyone who has looked at the Delve repository might have been struck by the absence of automatic unit testing available. This won't be a problem for the typechecker - I can think up loads of expressions which should typecheck, and loads which shouldn't - then I simply have to look at the results. The rest of the compiler/VM is not so simple.

For instance, how is one to automatically check that tail-call optimization is working properly? We can look at the internals of the virtual machine, but this is a bad idea - I initially debugged the virtual machine with unit tests written in the target VM language - which can take a hundred lines to do something that takes a few in the source language Delve. Since the machine is very fluid, every time I get a better idea then the machine changes. Having hundreds of lines of test code which have to change when the machine changes is too much work, especially considering I'm the only person currently hacking on Delve :)

To solve this problem, I'm gonna add unit tests for tail recursion, coroutines using continuations, mutually recursive routines which I can be sure allocate a large, fixed quantity of memory every recursion. Then I'd like to use POSIX resource management to see if the limit is exceeded.

However, this is POSIX only, and will also require statistical analysis to ensure it works correctly across many systems.

I need a better plan... :)

Also I had made a bit of a silly mistake. See, the way the Delve in the public repository works is:
String is parsed into Core
Core is VARAPPED into VarCore - a version of core without nested expressions - temporary variables overcome this.
VarCore is RESOLVED into LocalCore - like var core, but local variables are associated with a stack index - since the VM records a stack of local scopes, it's better to pre-compute which local scope is associated with each variable.
LocalCore is then compiled into VM code.

However, I realized that the RESOLUTION into local core should occur before type checking, and also since VARAPPING a legal program should result in another legal program, that type checking should occur before VARAPP.

Soo the process is now

String is parsed into Core
Core is RESOLVED into LocalCore
LocalCore is type-checked.
LocalCore is VARAPPED into VarCore
VarCore is compiled to DCode.

This is requiring much of the compiler to be changed to support different data-types - an advantage of the small codebase (only now 6.2KSLOC) is that this should only really take an hour or three. Of course, this is poor software engineering - several solutions spring to mind:

I was tempted to define an abstract form of core, AbstractCore, which would have kind * -> *. So it would be AbstractCore md, where md is associated MetaData. Compilation would proceed by transforming the metadata.

This has the disadvantage of errors like nested expression occuring in the syntax tree after the varapp phase not being caught at compile time - I would have to check they would be caught at run time.

Or I could associate each element in the tree with an integer, and just have an IntMap which maps the integer to associated MetaData. I think this would be easier to manage - since the metadata would be separated from the Tree.

This still suffers from that disadvantage.

However, if the various syntax trees are queried through a type-class, then they could be used independently. Also, this could return various elements in a type-safe manner, for instance, before the VarApp phase, there could be a type class instance for function application, which with multiple parameters would associate the application with arbitrary, possibly nested expressions. The instance used in the VarApp phase would associate the application with variables only.

This bit of randomness has turned into an idea! I think I will try this. Firstly, I'm just gonna get it working again, though, in the old and simple style - changing it to support new abstract types is going to a be a little bit more work than simply renaming a few things, which is all I have to do now.