Developing a Checkers (Draughts) engine, how to begin?

4.2k views Asked by At

I'm a relatively inexperienced programmer, and recently I've been getting interested in making a Checkers game app for a school project. I'm not sure where I can start (or if I should even attempt) at creating this. The project I have in mind probably wouldn't involve much more than a simple AI & a multiplayer player mode.

Can anyone give some hints / guidance for me to start learning?

2

There are 2 answers

1
Penguino On BEST ANSWER

To some extent I agree with some of the comments on the question that suggest 'try something simpler first', but checkers is simple enough that you may be able to get a working program - and you will certainly learn useful things as you go.

My suggestion would be to divide the problem into sections and solve each one in turn. For example:

1) Board representation - perhaps use an 8x8 array to represent the board. You need to be able to fill a square with empty, white piece, black piece, white king, black king. A more efficient solution might be to have a look at 'bit-boards' in which the occupancy of the board is described by a set of 64-bit integers. You probably want to end up with functions that can load or save a board state, print or display the board, and determine what (if anything ) is at some position.

2) Move representation - find a way to calculate legal moves. Which pieces can move and where they can move to. You will need to take into account - moving off the edges of the board, blocked moves, jumps, multiple jumps, kings moving 'backwards' etc. You probably want to end up with functions that can calculate all legal moves for a piece, determine if a suggested move is legal, record a game as a series of moves, maybe interface with the end user so by mousing or entering text commands you can 'play' a game on your board. So even if you only get that far then you have a 'product' you can demonstrate and people can interact with.

3) Computer play - this is the harder part - You will need to learn about minimax, alpha-beta pruning, iterative deepening and all the associated guff that goes into computer game AI - some of it sounds harder than it actually is. You also need to develop a position evaluation algorithm that measures the value of a position so the computer can decide which is the 'best' move to make. This can be as simple as the naive assumption that taking an opponents piece is always better than not taking one, that making a king is better than not making one, or that a move that leaves you with more future moves is better than one that leaves you with less choices for your next move. In practice, even a very simple 'greedy' board evaluation can work quite well if you can look 2-3 moves ahead.

All in all though, it may be simpler to look at something a little less ambitious than checkers - Othello is possibly a good choice and it is not hard to write an Othello player that can thrash a human who hasn't played a lot of the game. 3D tic-tac-toe, or a small dots-and-boxes game might be suitable too. Games like these are simpler as there are no kings or boundaries to complicate things, all (well most) moves are legal and they are sufficiently 'fun' to play to be a worthwhile software demonstration.

0
user3685230 On

First let me state, the task you are talking about is a lot larger then you think it is.

How you should do it is break it down into very small manageable pieces.

The reasons are

  • Smaller steps are easier to understand
  • Getting fast feed back will help inspire you to continue and will help you fix things as they go wrong.

As you start think of the smallest step possible of something to do. Here are some ideas of parts to start:

  • Make a simple title screen- Just the title and to hit a key for it to go away.
  • make the UI for an empty checkerboard grid.

I know those sound like not much but those will probably take much ore time than you think.

then add thing like adding the checkers, keeping the the gameboard data etc.,

Don't even think about AI until you have a game that two players can play with no UI.

What you should do is think about: what is the smallest increment I can do and add that, add that and then think about what the next small piece is.

Trust me this is the best way about going about it. If you try to write everything at once it will never happen.