• Post Reply Bookmark Topic Watch Topic
  • New Topic

OOP planning for a chess engine

 
Steve Stephenson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've wanted to design a chess engine using object oriented ideas as an exercise. Currently my chess engine is written mostly procedurally and I'm having a hard time thinking about a chess engine in terms of objects (the process of deciding which move to make next doesn't seem to be based on the idea of 'real life objects' as many examples are) currently what I've had in mind for a design was:

in order to decide on a move, the engine will need a position, its legal moves and be able to make moves to analyse future permutations. So

- the position has a collection of legal moves and a score based on the position

- the AI 'brain' gets access to a position and is able to make theoretical moves on its position

- the computer player which has a position as well as a 'brain' which decides the best move

Am I going along the right tracks? How would one design something similar to a chess engine, in general, in an object oriented way?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35744
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
Player could be an object. As can moves.

What about the board and pieces? Those could be good objects.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might give you the opportunity to rewrite it a more interesting way. If every piece is an object and it has fields like position on the board and some kind of strength value based on other pieces and positions on the board you could make the move that would give your side the best net strength gain on a move when all the other strengths are readjusted from the move. There might be some really good chess theory you could implement that way. A lot of procedurally written AI is really pretty locked in and predictable, like 1 to 1 correspondence.
 
salvin francis
Bartender
Posts: 1407
18
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit : Just realised, Guillermo Ishi already mentioned "strength value" in his comment, this is same as my ranking system below

I would add a sort of ranking system to each of the pieces.
The way I see is
Pawn is 1 point,
Camel : 3 points
Horse : 5 points
Elephant/Castle : 6 points (some people say this is equivalent to horse)
Queen : 10 points
King : 100 points.

This gives the system a fair idea about its current status and which piece can be sacrificed.

As far as move is concerned, I see the fly weight design pattern here, where instead of a dedicated class for every piece, you could have a single "ChessPiece" class.
methods can be like:



MVC structure would help here where the controller is the game engine.
 
Winston Gutkowski
Bartender
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Stephenson wrote:I've wanted to design a chess engine using object oriented ideas as an exercise.

Ooof. That's quite a task. How much Java have you done?

Most chess engines are developed by teams of people - generally including at least one expert in the game - and good ones often take years to develop (or get as "good" as they're going to be, given whatever constraints you decide on).

Not that I want to put you off; it's a fascinating exercise. Just be sure that you're ready for it.

Winston
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most interesting chess program would be one that improves its game from losing and winning games. You might want to start with some simpler game of skill than chess. Maybe chess with fewer pieces or different rules A long time ago I knew a dept head at a school of education at a university and he said he'd created a program that learned in a way similar to a human but that it ran out of memory too quickly to be able to do much. He was using an Apple II. He knew all about how humans learn, and was a fair programmer.

Some AI helps --
http://www.dmoz.org/Computers/Artificial_Intelligence/Machine_Learning/Software/
 
salvin francis
Bartender
Posts: 1407
18
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be interested in researching on neural networks. The "sally" link in my signature is very loosely based on that.
 
Winston Gutkowski
Bartender
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:You might be interested in researching on neural networks.

@Steve: Alternatively (at least to begin with), write a program that simply controls, or referees, a chess game between two humans - ie, it prevents invalid moves and keeps track of moves made, pieces taken, time taken to move, etc.

There's plenty of scope for OO design in that alone and, if you write it well, you'll probably have a great platform to build from to add logic that actually plays the game.

Winston
 
Les Morgan
Rancher
Posts: 717
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a similar project long ago:

My board was an object (board object).

The board object consisted of tile objects (white tile and black tile extended tile to give each tile for the board).

My pieces were objects (player object).

Each specific piece extended the Player Object to allow specifics for each piece: movement, weight, color, graphic, etc.

I made a separate game engine object to interact with the board object/tile/player objects to play the game.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!