Tuesday, 17 December 2013

My code - "You only get one pixel" bot

One of the interesting experiments at the Ludum Dare Game Competition 28th iteration was Folis''s You only get one pixel. It's a simple 100x100 canvas in which each "player" contributes one pixel to form an image.

However, seeing that the only thing keeping me from spamming it was an stupid cookie, I couldn't resist but to write a bot. I choose of course C++ and Allegro, to the dismay of iostream, who ironically thought I should use Perl to this task. Unfortunately I have no knowledge of Perl.

Below is the form code inside You only get one pixel's code:

<form action="scripts/draw.php" method="post">
<label for="color">Color:</label> <input class="color" name="color" readonly="readonly" type="text" /><br />
<label for="col">Coord (x, y):</label> <input class="col" name="col" readonly="readonly" type="text" /> <input class="row" name="row" readonly="readonly" type="text" /><br />
<input class="submit" type="submit" value="Draw!" />
</form>

It's was a matter of creating a program to translate the pixels in a bitmap image to a series of curl commands that would use this form to write the pixels in the page.

I had some problems with my program generating white pixels which aren't visible in most browser's backgrounds and also with the non-intuitive coordinate system that starts at 1,1 instead of 0,0.

Here's my final code:

#include <allegro.h>
#include <cstdlib>
#include <iostream>

int main(int argc, char **argv)
{
 allegro_init();
 set_color_depth(32);
 if(argc < 2) return 1;
 BITMAP *bmp = load_bitmap(argv[1], 0);
 for(int x = 0; x < 100; x++)
 {
  for(int y = 0; y < 100; y++)
  {
   if(getpixel(bmp, x, y) == 0xFF0000)
   {
    std::cout
    << "curl -d \"color=FFFFFF&col="
    << (x + 1)
    << "&row="
    << (y + 1)
    << "\" http://www.pixelspade.at/games/you-only-get-one-pixel/scripts/draw.php\n";
   }
   if(getpixel(bmp, x, y) == 0)
   {
    std::cout
    << "curl -d \"color=000000&col="
    << (x + 1)
    << "&row="
    << (y + 1)
    << "\" http://www.pixelspade.at/games/you-only-get-one-pixel/scripts/draw.php\n";
   }
  }
 }
 return 0;
}

Below you can see the results of my beloved bot, where lies clearly spelled "drnick", my nickname in the Ludum Dare community, along with some earlier efforts by iostream.




Update: Folis
and iostream added security features to the game's code. I in turn updated my code to use proxylists and randomized user agents, defeating their security measures. However I did this as an mere exercise and will abstain from using it or publishing the code.

The spamming incident was reported by Folis on his Twitter.

Monday, 16 December 2013

My games - You only get one digit! (Ludum Dare 28)

This weekend (days 14-15th December) saw the 28th iteration of the Ludum Dare 48h game development competition. Even though I had long anticipated this event, I must say that unfortunately I was very disappointed.

I was planning to make a platform game with the usual suspects, Allegro and C++. However, when the theme turned out to be "You only get one", I was left without any decent ideas and decided instead to make a quick-&-dirty arithmetical game in HTML and Javascript. Instead of the rushed 48 hours I only took 3 to create this game.

The point of this game is to correct an equation by inserting only one digit. There's not much into it. Play the game here.



I know the game has already been criticized because of the difficulty level. It's a little unbalanced because "difficulty" only means deeper expressions, i.e. more parentheses inside of parentheses. Sometimes "Easy" can, indeed, be harder than "Hard". However, this is left for the player to click "Start" until he finds a interesting equation.

On the other hand, it was praised for the idea of using typical HTML elements like buttons and text boxes to create a game. This was actually more out of laziness than of originality.

On Ludum Dare 28 itself: I am now somewhat disappointed with the Ludum Dare community. I believe that a 48h competition should be more about originality than quality. Originality lends well to quick development, as good ideas often appear when one's in a hurry. Quality on the other hand is only a matter of time.

In this fashion, it's theme should promote the creation of interesting game mechanics.

However, this year's theme, "You only get one", merely promotes generic games tangentially related to the theme. It can only really work as a plot element. I tried to include it as game mechanic, and the result is a boring mathematics game.

This kind of theme is the result of too much meddling by the newbie portions of the Flash-Game Maker crowd. Often bad programmers, their focus is on content rather than gameplay.

It could have been a rather good theme instead, if my suggestion were to be followed: "Fireman (bonus: Only you can prevent forestal fires)". Many interesting game mechanics could arise, in water or fire, or even a firetruck driving game like Ghostbusters for the NES.

In spite of this, I did had a rather interesting chat with the chaps at Ludum Dare's irc channel. Very nice people gather there, it's fun to have someone to talk with about my enterprises of nerdistical, programmingastic lore. I usually answer there by the name of "drnick" in honor of one of the most sympathetic of all TV doctors.