Pi fun

So this was a lot harder than I expected it to be.

hasselttimelapse

The first iteration used a camera that only worked once and then the second photo was black.  I figured there were two solutions: reset the USB port or reboot the Pi.  Resetting the USB took more than thirty seconds, so rebooting was the “best” solution.  I set up a shell script that would run on start up, which would call a python script, which would activate the camera (I think I could have skipped a step here).  It worked pretty well.

Until 4am on the first test when my MacGyvered camera holder failed and the camera smashed.  So Plan B: can a Pi control a DSLR Camera?  Yes, turns out that’s extremely easy – at least after an hour of creating a solution to the pi failing to detect the camera.  So with my camera set up I triggered it to take photos over the period of about an hour, and this is what I came up with: an HD timelapse over looking the city.

Learning Unity: Platformer

I haven’t posted since July, because I’ve been working two jobs, learning Unity, completed a visa application and still somehow found time to work with my Pi.

So, the first thing: the first Unity project.  I decided not to go straight for a 3D project, instead I took on something more intermediate: platformer mechanics.

Here is a gif of me (red) moving around in a greybox platformer, demonstrating a few of the mechanics I’ve created.

platformerdemo

The first thing is maybe not the most obvious: collision.  This is handled by raytracing, and works both up and down, and left and right.  The collision also allows for the movement mechanics, and the jump mechanics.  There’s a wall slide mechanic, where a collision reduces gravity, which leads to a wall climber mechanic.  I also display two different types of wall jump: there’s a “big” jump and a small jump, both controlled by the player’s direction.

The other thing I’ve worked on is an extremely basic AI.  Grey is a follower, he tries to stay within a certain distance (especially when he fails to jump onto the platform with me).  Yellow is an “enemy”, and when you’re within a certain range of yellow he will chase you.  Pretty basic stuff, but I think I’ll focus on that later if I continue to move forward with it all.

I have another Unity project I’ve been working on, it’s a 3D thing that I’ve been messing around with.  At this point though I’m not happy enough with the progress I’ve made, but I might post about it later

Java Game Engine

I haven’t written much here because I’ve been working a lot on different things.  I have about three projects on the go right now as well as the thing I actually get paid to do, so it’s been busy.

Anyway, last week I decided that I don’t have enough completed projects.  I have one huge project that I don’t expect to have completed for a year or more which I was dedicating most of my time to.  Having a half written piece of code that can draw a rectangle to the screen isn’t particularly impressive though – despite the fact it’s maybe the best thing I’ve ever written.  I need something that’s visually more impressive to people who don’t want to trawl through my code.

And so here is the first result of this new line of thinking.

dt

Admittedly, I’ve used someone else’s resources because I didn’t want to spend time doing the animation (and I’m not particularly good at them either).  Other than that however, the engine has functional collision, animation, sound, and physics.  But for one or two minor issues it is a fully functional engine, written from scratch.

Now, what do I do with it?

Originally I had been focusing on my Civ-style game, which is kind of my ideal game, though I think I have to change my plan now.  I’ve had two ideas bouncing around in my head for 2D platformers for a couple of months.  The first is a totally original game which I had the inspiration from a picture I saw, which I would like to do but it would require making my own resources (although I have a plan to write even more code to create resources from drawings…).  The second would be a clone of one of my all-time favourite games: Golden Axe.  I loved the first game, which I played on my Mega Drive with my dad pretty much every day for a while, but the series never really developed after that.  Golden Axe II was very poor and Golden Axe III was an improvement, though it was never released outside of Asia and never reached the popularity of the first.  I’d like to create a sequel that the first game deserves.

Right now though, I think I’ll take some more time to think about it and work on a couple of other projects I have on my desk.  Maybe by the end of this week I’ll have two or three more completed projects to add.

Dev Log 1

Quick post to note today’s work.  I’ve been working on a video game that I’ve had bouncing around my head for a while.  So far I’ve created the basics of drawing an image on screen and map generation.  As it stands the game currently looks like this:

SS1

What we see on the screen here is a randomly generated map.  There is a tile with a poorly drawn house in it (my focus is on the game mechanics right now, the graphics will come later) to show the player’s starting position.  The blue tiles are water, some have “fish” in them to indicate resources.  The land resources are trees, iron and stone.  The background colour of the tiles denotes another resource that needs some fleshing out yet, but I kind of have an idea of how to do that.

I’m fairly content with how the tile sprites work right now, although they will need to be expanded.  I think I will try to add some character sprites next.  I also have no controls yet, it only generates this map.

Game mechanics, which is honestly my main focus of this project, are also not set yet.  I’m still working out some ideas on paper, though with some clever mathematics I think I could include things that are uncommon in strategy games.

That’s enough for now, I’ll likely update in a couple of days.

A Big Week: part 3

I didn’t get round to this part last night because I was hitting the job applications very hard, so here is part three of the last week.  Probably the one part that is just for myself since this is very much a work in progress.

It’s not secret that I love video games.  I’ve always wanted to make one, but I’ve just never gotten round to it.  Over the last week or so though, I’ve been working with one of my friends at making a game engine from scratch, with two or three ideas bouncing around in my head as to what the finished game will eventually look like.

So far what we’ve done is to draw an image on the screen, load sprites, some of the physics have been written and some animation.  We have no real plan at this stage, we’re just messing around with things, though we have spoken about setting up Kanboard and getting serious about it.

GE

So far it looks like this.  I wasn’t going to post a picture because it doesn’t really look like anything, but I’d like to reflect back on this stage in the future.  Most of the mechanics are not things you see here.  The dark blue cross is where the sprite starts.  It falls until it collides with the ground, I then move the sprite forward and jump on top of the red obstacle.  Collision and controls work, but both need to be refined.  At some point I’m going to make a plan of things I need to get done, so I’m not just adding pieces incoherently.

A Big Week: part 2

If you’re reading this and you’re not me, the chances are you were brought here by a bot.  Hopefully you did not realise, but whatever you read to convince you that this was worth checking out was generated automatically.

I deployed the third incarnation of my cover letter generator.  In the first batch of applications I’ve had a response rate at 29.4% (5 of 17)* in only a couple of days since I removed the “I am a bot” message and already two have made it to interview stage.  So it seems that recruiters don’t like me telling them they’re speaking to a bot?

How it works: first I go through and select jobs I’m interested in applying for – however, I previously wrote a bot that does that for me and I might refine that piece of code and use it again since it was incredibly useful.  I compile a list of links to job descriptions and the bot works its way through them, scraping the HTML, parsing, and reading it for a list of search terms I’m looking for.  If and how often the search terms appear is then stored, and passed to a letter writer which writes some text that will possibly be the first thing you read from me.  It’s not entirely automated in fairness, it does select from pre-written fragments.  The big advancement over the previous generation however is that I had three paragraphs and the code would select from them, now I’ve created a decision tree to write more specific paragraphs.  For example, if C++ is mentioned that will likely be the first thing you read.  If Java is also mentioned you will read this:

I have developed many applications for scientific programming using C++, both in writing simulations themselves and tools for data extraction and analysis, the latter of which I also have experience of writing in Java.

If there is no mention of Java in the listing, but Fortran is mentioned then a slightly different paragraph will be generated:

I have developed many applications for scientific programming using C++, both in writing simulations themselves and tools for data extraction and analysis. Although I did not write my own software during my Master’s project, I worked on bug fixes and code improvements using Fortran and wrote small apps to automate data analysis and calculations.

This is done for each job on the list, they are assigned a randomly generated designation that allows me to keep track of them.  They are written to a file with the cover letter and link, and then I just work my way through them.  I would prefer to have the bot do them, but that would mean writing a different form handler for every website and I’m not sure it’s worth that.  I get through them in ~4 minutes per application now though.

 

*as of 01/06/16, obviously I expect this to improve

A Big Week: part 1

The last week has been pretty messy in terms of the work I’ve been doing.  I don’t have anything particularly cool to post today, and I’m not working on anything that is messy and I need to write about to sort it out in my own mind.  That said, I do have a three very nice pieces of code that I’d like to write about.  I was going to do one post, but I’ll do three since they’re all very different and I don’t think it would be fair to lose them amongst each other.

First we’re back to MineBot!  I completely forgot to post this last time, but with MineBot “finished” I decided to make a few gifs of him in action.

gif1

In this first one we see how different he works to a human: after the initial click there are tiles a human would obviously see and MineBot misses (I think this is a possibly a parsing issue, I’ve had so many parsing issues because Microsoft use a colour gradient across the board).  However, we also see the ability of MineBot once he hits that tight area on the left, areas without blank squares are where he really excels.  MineBot loses the game this time because he decides to make a random guess and it doesn’t come off.

gif2

The reason I’ve chosen this gif is because it almost lets you see into the bot’s thinking: you can see him move down, and then pursue a “front” left, up and right along the top.  Again he falls down on the random guess.  He still has one obvious move I can see, but that would not help beyond maybe two move tiles.

So he’s “finished” in that he runs and can – with a little luck – finish a game.  I still have a few goals for this project so I will revisit it again.  I have plans to improve the guessing function and to even make a “stochastic solver”, as well as collection of the data I’d originally set out to find

Anything can be automated

Since I’m eating my lunch I figured I would write something about what I’ve done today.  MineBot is being temporarily shelved and I’ve began working on other projects, since it has become apparent that I will have to find another job.

Today I’m working on a third incarnation of a bot I wrote a while back to make the job application process easier.  I find the whole thing very tedious: I like working on problems and solving them, I don’t like writing letters, networking and advertising myself.  So, I turned a problem I don’t like into one I enjoy by writing a bot to do the whole thing for me.  JonBot 1.0 was a nice piece of code that would search a couple of websites for terms I provided, find jobs, generate a cover letter and then mail an application.  I decided to add a little note saying that this job was found and applied to by the bot, and I think that was a bad idea because I got a notably worse return rate than without: of applications done myself 64.8% were replied to and 39.4% went to interview (of 71 applications); the bot returned 4.3% replies and no interview (of 47 applications).  That is a notable drop.  I also don’t believe that it was due to the automated cover letters, because they were much more job specific than the ones I was doing myself.

There were a few holes in that bot, and changing it to handle other forms on other websites was a lot of work for not enough reward.  I made a second incarnation that would only generate cover letters, which gave a lot more range in places it could apply to.

Today, I’ve written a new bot to write multiple cover letters at same time from a list.  I’m also improving the letter generation method which is by far the hardest part of this project.  Last night I spent an hour or so writing down a few different methods and I think I’ve worked something out.  After that we’ll send out some applications and look at the numbers.  I’ll probably make a post or add it to my portfolio once it’s done too.

MineBot’s Milestone

Over the last week or so I’ve been slowly improving things, little fixes that take a while to find and write and yield very little reward for your time.  I found a mistake where I had incorrectly added a line to the calculation – I have no idea how many failed games that has cost – and since I’ve been approaching this with a “slow and safe” mentality I reworked a huge section of the code to make it much more efficient and cleaner.

The next features on my to do list are to add a function that deals with a dead end and clicks a random tile to try to move the game on again, to check if the game has been lost and restart if it has, and to add some data collection elements.  It’s not a huge amount of work and I’ll probably slow down with it and start another project while I finish this one off.  I think I might also add something for taking a snapshot so I can trace each click (and it should also make pretty cool gifs).

This morning though, we reached a huge milestone.  Things are still extremely slow as I have it pause to let me read the outputs and see what’s going on and I also have to help out a bit by clicking “random” squares when we get stuck.  With that said though, this morning this happened:

skynet_v0_1

I reset the stats after every edit, so in reality this is probably the first win in close to a thousand games.  It’s a huge moment though.  We’re not quite at the end, but we’re on the home straight.

Pokémon and the dream of bots

I was on the bus to work this morning thinking about some things that have been in my head for a while and are beginning to take some form.  The purpose of this is pretty much to just get these ideas in writing and somewhat coherent, likely so I can come back to them later.

Anyway, we start back at MineBot.  He was the answer to a question I asked myself a few months ago while writing a form handler for website in PHP.  Generally, when bots interact with websites it isn’t in the way that humans do.  We see the HTML/CSS veneer and a nice user friendly interface (at least, on well written websites…).  Bots don’t need to see that, they’re perfectly happy to wade through the ugly code to get what they want, as long as their author is happy to reverse engineer everything for them.  While doing this I asked myself if it was possible to write a bot that could visually automate some purpose, and minesweeper seemed like a good choice because of it’s visuals and mathematical nature ( I also messed around with sudoku and some variations of naughts and crosses in the past, but they weren’t as easy to parse visually as minesweeper, and too easy to make an unbeatable bot).

So how does this all relate to Pokémon?  Well, Pokémon was one of the first games I wondered if I could create a bot to play.  I’ve had the idea in my head for about three years now, ever since the original “Twitch plays Pokémon” back in 2012/2013 some time.  I always knew it would be hard to parse (I have a few solutions on paper to visually parse the game, but none of them solid).  However… if the bot could operate like the standard PHP bots I’ve written.  If I bypassed the screen altogether and manipulated the game’s memory directly, in theory, I should be able to play the game.

So, admittedly I was thinking about this on the bus and I’ve done no research whatsoever.  But my understanding is that the GameBoy had 8kB of RAM which the game ran on.  In that 8kB would be every possible configuration of the game possible.  Some of those configurations would correspond to a “win-state”, though I have no idea what that would look like right now.  That would be 2^8192 states, aka too many.  I wouldn’t need to worry about all of those though, some would be unnecessary fluff and could be excluded.  Enough to make this viable?  I don’t know for sure, but I think that’s probable since it will be “playing” the game and not simply scanning through multiple configurations until it hits one that it likes.

I need to investigate a bit more, but I think it’s possible.  I just needed to get this down so I can come back to it later and review my thoughts on the bus today.  Anyway, I guess I should get back to some work.