Thursday, 25 April 2013

Programming a copyrighted dice game 1

My most recent missive was about the torment of learning, or at least of not learning when attempting to. It was borne entirely of frustration because I'm trying to learn quite a few things at the minute, and getting stuck on any of them feels like time wasted.

One of the things I'm trying to learn at the moment is c++. It's not the easiest thing to stick at when it's going badly, but is so rewarding (as if I'm honest, is any form of programming) when it's going well. I am quite a sharer though, in that I like to talk about what I'm up to, but with this I find that I only get 5 or 6 words into what I'm trying to say before a glassy look appears in the eyes of whoever I'm talking to.  As a result I thought I'd share it here.

Firstly I haven't started from scratch; I've made some rudimentary flash games before and as a result knew all about the basic programming concepts. So having learnt the syntax specific to c++ I decided to test my knowledge by trying to code a simple game. In this case Yahtzee.

The target is firstly to create a console version of the game. This means that the game will be entirely rendered in text and as a result absolutely dreadful to look at. It will however have all of the functionality of the real game, enabling the user to 'throw' 5 dice, hold those that they would like to keep for the following throw, throw any unheld dice, repeat and then score appropriately. If that goes well, I can then look to install a graphics library and make something that looks a little less 1980's.

So far it's going OK, I've had a lot of success this evening writing some functions to test the users input and throw the dice. I haven't though really made any sort of game out of it, and I'm frankly dreading the scoring bit.

I'm a little bit unsure if I want to keep this as a progress log, or if I should also throw in a tutorial as I go. For now I'll just talk through the class that represents the in game dice, and if (laughs to self) there's any demand I'll add more code snippets through my write-ups.


1 class dice{                                  //represents the dice of the game
2     bool held;                               //is the player holding this die?
3     int pips;                                  //what is the score on this die?
4 public:
5     void throwd(){                                             //Throws the dice object
6         pips = rand() % 6 + 1;
7     }
8     int getPips(){return pips;}
9     bool getHeld(){return held;}
10    void setHeld(bool dec){held = dec;}             //Tells this die if it is going to be thrown
11 };                                                                     //again


So on a line by line basis:
Line 1 - Tells us that we are creating a new reusable object (class) called 'dice' and that everything between the '{' on this line and the '};' on line 11 is the definition for the object.
Line 2 - Creates a new variable called 'held'. Every instance of this class that we create will have its own copy of this variable. The 'bool' tells us that the variable is of type 'Boolean', that is it can only have one of two values; true and false.
Line 3 - Creates a new variable called 'pips' which is of the integer type, that is it can only hold whole numbers.
Line 4 - It's a little awkward to describe the 'public' keyword to an audience that may not know programming. In short it says: 'let other objects see everything from here onwards'.
Line 5 - This is a function (or method) definition (as are lines 8, 9 and 10). It defines something that can be done to any instance of the dice class we create. The void means that we should not substitute the function call for anything when we use it later in the program. The function ends with the '}' on line 7.
Line 6 - This is the body of the function defined in line 5. It sets the variable 'pips' to a random number between 1 and 6. Remember this is a reusable class, so 'calling' this function will only effect the 'pips' variable  in the instance the call took place. This will make more sense when seeing the call on a later date.

Line 8 - The classic 'getter' function. We can use this later to see what the value of 'pips' is for an instance of this class. The reason we need a function is because the variable 'pips' is defined before the 'public' keyword.  The 'int' means that when we put this in the code later on, we can treat it as an integer.
Line 9 - Very similar to line 8, except we are expecting a Boolean value back this time.
Line 10 - This is the inverse to a 'getter' in that we are using it to set the variable 'held' from outside the class. Notice that the brackets aren't empty this time, but have 'bool dec' inside. This means that when we write the function in the code later, we have to include either true or false inside the brackets. This tells the class what to set 'held' to.

Seems that language tutorials (even very basic ones like that) take a lot longer to write than I thought! I shall at the very least keep this going as a progress log, and maybe post little code snippets up every now and again. If you have any questions please let me know.

Thanks for reading.


Monday, 1 April 2013

The plateau

I love learning. Always have. Not just the facts and figures bit or the book smarts, but skills, physical abilities, so many things that it's possible to do I like to try. See if I'm good at them. If I'm not I try and get good, if I am I try and get better.

I'm a bit like a magpie though. A new idea crosses my mind and it's like a shiny trinket to be chased to the detriment of whatever I'm currently improving at.

I can accept this. When I'm into something for a while I normally come back to it. What really bugs me though is what I call a plateau. This is when despite all my best efforts an improvement seems elusive. Like trying desperately to stakeboard up a steep slope, all the effort seems to be for nothing.

It may be no more than an illusion, and I've no idea why I'm committing it here, it just bugged me today and I hope expressing it will rationalise it a little. I probably expect results too quickly, but here is the magpie issue. If I get bored I worry I'll drop what I'm doing, but I don't want to. How do people keep the motivation going when success seems a distant dot on the horizon?

Friday, 7 September 2012

Adventures in breakcore

Hello again. I've decided to re-relaunch this blog after deciding that I like talking about things, but can't get anyone to listen to me. Nor can I get them to listen to any music I like, which means that you, lucky reader, can discover new music with me.

So, having listened to a range of different genres of dance music over the years I have settled (as the title may suggest) on something dubbed breakcore. If you've never heard of it, you are in the company of many. Imagine your run of the mill drum and bass, speed it up a little, chop the beat up into tiny pieces and then liberally sprinkle it, well, everywhere.

Key artists in the early breakcore era included aphex twin and Venetian snares, and the genre was gaining a toehold in the clubbing world (this despite the fact that the time signatures vary so much it takes practice to dance to). Until dubstep came along and all the ravers got too mashed on ketamine to deal with the intensity.

So I was left alone with my headphones, bopping to tunes no-one liked, and that DJs had lost the will to spin. So it has remained until very recently, and in the majority of that time my knowledge of the genre has been rooted in free online mixes, with limited tracklistings.

Recently though I decided to try and learn a little more about breakcore, not quite with the fervour of a teenager that's just been told rock music would piss off his parents, but an effort nonetheless. I have since been prowling youtube, soundcloud, bandcamp* and a number of forums to try and get myself up to date.

All this effort though, and still those I know look at me like a bewildered child any time I try and share this knowledge with them. So I return to my blog with this 'adventures in breakcore' series knowing I can at least inform one small dark corner of the net.

I was planning to review Gizm0de's 'snack on this' as part of this article, but frankly I've wittered on so long already you wouldn't know there was a review here! I'll post it separately soon.

*I really cannot recommend bandcamp highly enough. I'm on the consumer side so cannot comment on selling, but the full length previews and ability to buy direct from the artist make it a must IMO.

Tuesday, 5 July 2011

M&M World - A world of M&Ms

I was walking around London today when I saw this...
 











It's on the corner of Leicester Square and Wardour St. just opposite the KFC and the McDonalds. On spotting it I sighed, as clearly here was just one more notch for rampant consumerism at a time when it's getting harder for the average man to put bread on the table. 'But that's the way of the world these days' I thought. In these straightened times it's nigh on impossible to build anything, particulalrly in the high rent areas around Soho, without big buisness backing.


So I decided to go in, I mean this is a prime retail/leisure location, what had the M&Ms brand put their name to in order to entice passing tourists? It might be a cinema, what with the red and yellow M&Ms now presenting those silly adverts in theatres nationwide. Or maybe some kind of games arcade, with an M&M store inside when you need a chocalatey break. Indeed, I just got the feeling while standing outside that there would be 4 distinct levels, each with their own fun activity...












Oh yes Ladies and Gents, I got that impression because that's what I was promised. So what was inside?


It was a shop. A giant bloody shop selling loads of M&M merchandise. Only a small corner of one of the floors was even devoted to the selling of the snack itself. There were M&M lunchboxes, M&M t-shirts, M&M hats, M&M bibs and much more besides.
Who on earth concocted this idea? What blithering loon thought that there was enough demand for clothing and accessories with a coloured circle with an 'M' in the middle that they would build a giant shrine to the things? I'll tell you one thing, I had no fun at all. I walked round, gagged at the thought of the depths Westminster's planning committee had sunk to, and left, past lots of joyous people all getting their photo taken with a statue of the 'yellow one'.

Tuesday, 17 May 2011

Re-launch

Ok. So I've decided I'm going to do this again.

Hello and welcome back for those of you that have missed me in the almost a year I've not posted (where does the time go?). The plan is to try and post a couple of missives a week in order to get me back in front of the computer and writing again. Because I have this terrible habit of thinking I don't have anything important to blog about, I'm not going to limit my writings to things that actually matter. Instead, I plan to just sit down and force myself to write about whatever comes into my head.

This SEO defying approach may well lead to a distinct lack of intrest, but I guess the point is that I should be doing these sorts of things for me. Improve my writing skill, whether it be politics, football, life or any other nonsense. What won't happen on here from now on is any post about video games, as I'll reserve those for Common Ground Games.

Just occurred to me that the last post on here was in reference to the recent AV debacle. Well what a clusterfuck that was. It does seem that if the reformists can't design a coherent plan for themselves, what chance have they got of convincing others? It all got a little bit Judean People's Front for me. Depressing.

Right, that'll do for now. Like I say, hello again, hope you are well. See you all soon.

Tuesday, 27 July 2010

AV campaign poster

Over at Lib Dem voice there is currently a competition running to source a poster to promote the Alternative Vote campaign, for next years referendum. 

Here is my offering:

If you came here via the comments page on LDV, please take your time, have a look around the blog, and if you are feeling really adventurous, maybe leave a comment or two. Cheers.

looking for work

I'm not sure any semi-regular experience comes close in the horrible stakes to job-hunting. It's so ridiculously soul destroying and demoralising that it leaves you unconvinced as to your ability to do any job at all. And I say this as someone who has only received one rejection letter to date.

Let me start from the top:
I found out last week that the company I work for is in severe dire straits. This was confirmed for me on Wednesday when it was suggested that instead of my usual work, it may be best to prepare a CV.
This was duly completed and the job hunt began, if not hastily, earnestly. The problem was (and indeed remains) that not only am I not particularly clear what I want to do, but my career to date has not really been targeted enough to give me a proper fall back.
The obvious contender for a holding role is to do some design work, admittedly that's far from obvious looking at this blog, but it has been the key thread through my career to date. Thing is, these days everyone wants to see a portfolio. I'm not organised enough to keep a portfolio. I had trouble enough remembering where the my work was on the server. Finding work I did 3 or more years and 2 computers ago is like looking for a needle in a haystack. When someone forgot to provide the needle.

I can do other things of course. I mean I can write, or at least I hope I can. If you've made it this far then at least I can write a bit anyway. But once again employers want to see a strong portfolio of work. That tends not to mean a hideously untargetted blog and the occasional note on rwdmag.com. Besides, the few jobs I have seen that do exist have balls and all to do with what i know.
'Do you have a passion for luxury hubcaps?' Does anyone?

To save repeating myself down the list of skills that I have in some measure, it's essentially the same story. I can do the job but either don't have a portfolio handy, or haven't been doing it professionally for anything like long enough.

Luckily I do have a way of amusing myself even in these irritating times. On seeing one job that I considered I had a chance for, I replied, 'are you looking for the ultimate all-rounder? Well look no further!'

Yes I know what you're thinking, that's either breathtakingly arrogant, mind numbingly stupid, or both. Frankly I'm not sure I care, after another day in our rotting corpse of an office, I needed some entertainment, I was tired of typing up the same empty platitudes and maybe, just maybe someone arrogant and stupid is just what they were looking for.