My Way to PHP: Day 24 of 75

So, I published yesterday’s post and another old one I had lying around.


I just finished the cookbook. Today, I’m probably not going to do much because I get my wisdom teeth extracted. So that’s good. I still want to read the best practices book and watch some talks on Symfony and then I’m finally gonna start my project. Yeah!


Updates Goals:

  • Learn Symfony2
  • Learn a bit more about MySQL
  • Write at least one web app using Symfony2 and its core components (templating, testing, forms, validation, security)
  • Watch one video per day on average

Progress status

Done

  • Read Symfony The Cookbook for Symfony [done]

In Progress

  • Watch one video per day on average [53 of 75]

AI: Bejeweled

After WordGame I took a few week break and sat down to automate a Bejeweled clone. Again I took a HTML/JS version of the game because interjection JS is pretty easy. I liked the version by alkaruno.

Making AI possible

I actually didn’t change much. I only changed a bit of the cosmetic because I was writing it and starting at the screen for a while I changed the graphics to just simple colors and the background to white – so that it was less heavy. Then I injected my ai.js and it ran.

The Algorithm

Here’s the general idea: We try out all the moves and find the move which maximizes our additional points.

I just adopted the scoring function used by the game. Therefore, we have perfect knowledge about the score of our action. Next I found all possible moves. In case you never played a game like this. You can switch bricks. But a switch is only legal if it causes a line (horizontal or vertical) of 3 bricks to connect.

So, we see what happens if we swap positions. I recorded the swaps in a map / object. Then I calculated the resulting points and compared it to the current best move, so far.

You can see that the moves is optimal for each round, however it doesn’t have to be optimal in the long run. New bricks will be added randomly and these could change the outcome.

And that’s the algorithm basically.

Then I injected it into the game and added buttons for starting and stopping the AI. Also I created a slider which adjusted the time the AI stops before making a move. You can see in the video that if I make the delay between moves too low the game bugs out and square won’t get filled up.

Video

I recorded this video like usually with recordit.

My Way to PHP: Day 23 of 75

Day 23, still reading, still 50 pages.


The AppKernel class and Frontcontroller are surprisingly simple (at least the dev facing ones).

That’s pretty cool. Symfony comes with a SessionHandler which allows storing sessions in databases!

It looks so far pretty good designed. I just read the chapter about adding own commands and it just works like the rest.

Jesus, there’s even an EventDispatcher component.


Updates Goals:

  • Learn Symfony2
  • Learn a bit more about MySQL
  • Write at least one web app using Symfony2 and its core components (templating, testing, forms, validation, security)
  • Watch one video per day on average

Progress status

In Progress

  • Read Symfony The Cookbook for Symfony [367 of 446 pages]
  • Watch one video per day on average [53 of 75]

My Way to PHP: Day 22 of 75

Day 22! Just published yesterday’s notes and another backlog post. Today, I’m going to start with the cookbook. Like always 50 pages is my goal.

What’s funny / interesting is that I see that I’m soon starting with an other project but I’m a lot more excited to write the business logic / domain layer than doing much with Symfony itself. Nonetheless, I wanted to learn it!


Assetic for Asset management. Pretty neat, you can integrate all kinds of tools from minifying to optimizing pictures.


Installing 3th party bundles:

  1. Add to composer
  2. Add to AppKernel
  3. Do some configuration (optional)

Pretty cool and easy!


Growing a Language by Guy Steele

The first 10 minutes seems strange but they are important. A great format for this kind of talk!


Updates Goals:

  • Learn Symfony2
  • Learn a bit more about MySQL
  • Write at least one web app using Symfony2 and its core components (templating, testing, forms, validation, security)
  • Watch one video per day on average

Progress status

In Progress

  • Read Symfony The Cookbook for Symfony [68 of 446 pages]
  • Watch one video per day on average [53 of 75]