• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OOP planning for a chess engine

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python C++ Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic