Draughts Game Complete

I’m happy to say that I have finished adding all of the small touches to Draughts and it’s ready for public consumption. According to the deadline I set I am a bit overtime which is slightly disappointing. I think the biggest contributing factor was a lack of planning. By the time I finished implementing the baseline functionality, the game states or the game engine weren’t implemented. Despite being a tad late I feel that I’ve learnt a lot about some new tools such as Valgrind and bit about how game engines work.

I’d like to thank Roald Strauss for the music. I discovered his music at Indie Game Music which is an excellent resource for finding game music.

I have only provided the source code for Draughts since I didn’t want to have to deal with request about any compatibility issues. You can however compile the source code yourself and play. The game requires the SDL, SDL_image, SDL_ttf, SDL_mixer libraries. Here is a great tutorial about compiling SDL applications for your system.

Download Draughts Source Code

http://nexfinity.net/portfolio_files/draughts/draughts.tar.gz

Everything provided in this zip file except for the background music is under the CC-GNU-GPL license. The background music is owned by Roald Strauss and he’s permission has been granted for use in this game.

If you would like to leave feedback then you can enter a comment below or drop me an email. I have a few ideas floating around for what I want to do next, probably something more ambitious with SDL since I enjoyed using it. For now my brother has a few web related things for me to do which I should get to. Hope you enjoy playing.

Draughts AI – My Approach

I am happy to say that I have finished programming my Draughts game. If you have been following my Twitter then you may have noticed that there is one thing holding me back from releasing it, memory leaks. I personally expected to have a few since I haven’t had a great deal of experience writing more sophisticated applications in C/C++. I got around to checking these leaks the day before I was heading back to University for the semester so I haven’t been able to address all of them yet but plan to soon. For the mean time I would like to discuss the AI that I have used in this game.

One of the fundamental concepts behind AI is the Turing Test as discussed in Alan Turing’s 1950 paper “Computing Machinery and Intelligence“.

A human judge engages in a natural language conversation with one human and one machine, each of which tries to appear human. All participants are placed in isolated locations. If the judge cannot reliably tell the machine from the human, the machine is said to have passed the test. In order to test the machine’s intelligence rather than its ability to render words into audio, the conversation is limited to a text-only channel such as a computer keyboard and screen.

With this in mind I decided to brainstorm several things that would cause my game to fail this Turing Test. The first notable thing is moving a piece into a position in which the opponent can jump that piece when there are other more advantageous positions on the board. The second is if the computer player doesn’t take the obvious jumps and double jumps. To put these into play I decided to assign a priority to all of the possible moves that a computer opponent could take. Any moves which resulted in capturing an opponents piece would would receive an increase in priority and any moves that resulted in being captured by the human player resulted in a decrease in priority. The computer would then take a random move out of the list of moves with the highest priority.

The system described above is the crux of the AI. Overall effect works really well towards the start of the game but sort of falls apart as the pieces become scattered across the board since the AI moves pieces at random. I’d like to think that the aggressiveness of the computer early on makes its flaws less apparent towards the end but this not always the case.

Thanks for reading. Hopefully towards the end of this week you should be seeing the source code of Draughts here. For now enjoy some of these screen shots.

Draughts Progress

So far I’ve been working on the Draughts project for several hours over the last week and I am happy with the progress that has been made. I am right on target to meet both deadlines that I have set. One thing that I have underestimated is the amount of planning that was required. Initially the overall game structure was planned out. This included things such as the data structures used, object orientated models and code structure. There are two things that I didn’t plan for and I want to talk about them today.

The first issue I found is how the player should move their pieces. I wanted to make this process as intuitive as possible, so intuitive that the user wouldn’t need the controls explained to them. I came up with two strategies to solve this issue.

Drop and Drag

The drop and drag method involved the player clicking on the piece and then dragging it to the location they desired. My first thought was that this approach was rather intuitive since it mirrors the movements that someone would take in real life. I then thought back to my experience with other games that required you to move pieces such as Puzzle Quest and Bookworm Adventures. Both of these games don’t make you drag pieces across the screen and there is a good reason for it. After a while it becomes a tedious process. Other issues arise such as collision detection between pieces and squares as demonstrated below. Technically it also ads to the code complexity and processing oomf that is required.

Refresh 5 times twice?

Refresh five times or twice?

Click and Select

This method is the one I used in my version of Draughts. It is simple to program and simpler for the user. You simply click on the piece that you want to move and then click where you want to move it. One of the greatest benefits compared to the previous approach is that you are required to update the screen less often. You only need to refresh the screen once the player has made a choice and then refresh the squares that are modified in that choice which tends to be two squares. The square where the piece existed and the square where the piece moves to. Whereas with the drop and drag approach you have to update the screen every time you incrementally move the mouse, in order to create the result of the piece following the cursor. What makes this worse though is that you also have to refresh the squares that the piece moves over.

The second issue that I came across was how to handle the multiple jumps in draughts. Initially I wanted to show all of the possible moves a player could make in one turn and highlight the respective squares. This became impossible when you think about trying to represent it on the screen. What struck me though was that by showing all of the possible moves to a player was that I was showing them too much. So I decided to limit the scope of what was shown. This was restricted to a domain of one jump. Since most players would naturally recognise one jump moves I decided that there was no real advantage of showing them the potential moves. To handle multiple jumps I decided to break the moves up into single jumps in which subsequent jumps are still highlighted and forced the player into not being allowed to revert their previous jump. I also allowed the player to choose to not undertake a subsequent jump if they choose not to.

Double meaning

Double meaning

By the time you read this I should have finished the base functionality. I was intending on posting my current progress online but I am requesting permission to use some music and haven’t received that yet so I will hold off until I finish it. Will be done soon.

Draughts Project

As I mentioned in my last blog post the first project that I plan to share is a draughts game. The aim of this project is to give myself some practice with SDL and an idea at the sort of time frame I can produce small games in. Below is a rundown of the current specifications and milestones of the project.

Draughts Game

Programming Language: C++

Libraries: SDL, SDL_image, SDL_ttf

Baseline Functionality:

  • Human Controlled Game of Draughts for two players
  • Piece Movement and capture
  • Piece advancement
  • Graphics Blitting
  • Background Music and Sound Effects
  • Simplistic Game Configuration

Advanced Functionality:

  • AI based Opponent
  • In Game Configuration
  • Game Menus and Restarts
  • Move Count
  • Match Timer

Time Frame: Baseline Functionality 10 days – 21st February

Advanced Functionality 15 days – 26th February

Over the development period I will post some details about how things pan out. Hopefully I can finish everything well before the expected time frame.

Back in the Saddle

After several months away I have decided to get back in the saddle and get back to updating this blog. I’m sorry for disappearing for a while but I’m back now. Over the last few months I’ve been playing around with a few things which I plan to quickly run through today.

Firstly I have switched over to the Dvorak key bindings on my keyboard. Dvorak is just different layout for the keys on the keyboard such that you don’t need to stretch as far to hit the commonly used keys. As a result typing related injuries are greatly reduced and in some cases people improve their typing speeds. Before using Dvorak I didn’t consider myself a good QWERTY typist so I also used this opportunity to teach myself to correctly touch type. I used a combination of the fabulous GNU Typist and ABCD: A Basic Course in Dvorak. Another change that I have made to my typing is a change in keyboard. I have switched over to the Microsoft Ergonomic Destop 4000 as recommended by the users at Stack Overflow. It’s great keyboard once you have adjusted to the greater split between your hands and the slightly curved keys, highly recommended. You really only notice how good this keyboard is once you switch back to a standard keyboard. I think the same applies to the Dvorak key bindings.

ms_ergo_desktop_4000

Secondly I have been playing around with a few different libraries in C and C++. The first of which is NCurses which is a library that is used to create TUI’s in the terminal. NCurses works by treating the terminal as a grid and allows the creation of Windows, forms and menus. It’s a lot of fun to play around with. I found this site particularly useful for learning the ins and outs of NCurses. If you enjoy playing around with NCurses then I suggest you try the Curses Development Kit. I started programming a platformer game with the terminal but I the jumping didn’t go as smoothly as I would have liked so I abandoned that project. In the future I’d like to work with NCurses for another project.

Another library that I have been playing around with is SimpleDirect Media Layer(SDL). The SDL library allows you to integrate audio, images, pixel manipulation, keyboard handling and much, much more into your programs. It is commonly used to created 2D games but also has the functionality to work with OpenGL. Learning SDL has been very enjoyable and exciting. I have been through all of the excellent tutorials by LazyFoo and intend to implement a draughts game which I will cover later. The SDL Documentation is also very good and highly recommended.

SDL

Probably one of the biggest changes to occur in the last few months is the fact that my family is now on Naked ADSL. Previously we were on dial up since the distance between our house and the telephone exchange was too far and hence the signal degeneration was too high. But with Naked ADSL, in particular Internodes Naked ADSL Extereme we were able to just get Naked ADSL despite the fact that our line attenuation is still very high. With Internodes Naked ADSL Extreme, the ADSL signal is pushed further since Agiles’ DSLAMs don’t have to worry about handling the PSTN side of things. The switch to Naked ADSL has been great and Internode has been very responsive to any problems we have had. I’ve been enjoying a lot of unmetered content from Steam and Games.on.net.

Internode Loge

With the switch to Naked ADSL also came the switch to Ubuntu Linux. I had been using Ubuntu on my Acer Aspire One netbook for several months and have been really enjoying using it. I did try to setup before on my desktop but things were too tedious and not always functional with Linmodems. Currently I use Ubuntu as my primary partition and I switch to Windows Vista for gaming.

I’ve also been doing alot of gaming over the break, possibly too much. Notable titles that I have been playing are Farcry 2, GTA 4, Metal Gear 1-2, Metal Gear Solid 1-2, Wario Shake Dimension and Mega Man Powered Up. I am currently playing GTA4 and some Pixel Junk Eden on the side. As usual there is a mountain of games to play which is never a bad thing.

4803-gta-iv-screenshot

That pretty much concludes what I have been doing over the last few months. I almost forget my twin brother returned from Shanghai, you can read about that at PrimeScape or read his games blog at DanielPrimed.com. As you may have noticed there are some small tweaks to the site. The most notable one is the Current Projects Box on the side. Within the next few days I will post up the details about that. Stay tuned.