chess bitrepresentation - OO question

This is a discussion on chess bitrepresentation - OO question within the C++ Programming forums, part of the General Programming Boards category; Hello I want to create a chess game. I am at the stage of looking for the best data structures ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    115

    chess bitrepresentation - OO question

    Hello

    I want to create a chess game. I am at the stage of looking for the best data structures for my board.

    Board representation (chess) - Wikipedia, the free encyclopedia

    In the given link they talk about different representations for a chess board.

    They talk a lot about bitrepresentation. My question is they represent the pieces of the game
    by bits but the OO way is to create a class parent class Piece with derived classes King, Queen, etc... .
    How do you keep this OO structure and use these bitmaps? Or am I seeing this wrong?

    Thank you

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    Thank you for your link, but I think I didn't explain my question enough.

    When you create a 8x8 array as a board you can put on every cell a piece. That piece is a member of the class Piece. From this class there are other classed derived from like King, Queen, etc... where you put all information about those pieces in. This was my first taught.

    But when you use a bitboard you can't work like this? Or am I wrong?

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    It is well known amoung implementors of chess AI that in order to get it running at a decent speed, having the most efficient representation of boards possible, is critical.
    As such it is necessary to forego the usual happy world of OOP, objects, heirarchies, and highly-readable-code, at least in terms of the bitboard level. That doesn't mean it's effectively obfuscated, it just means that you do your OOP at a higher level.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    You can still do OO with bitboard representation. The board class uses an internal bitfield to represent the board. But when you place a piece on the board, the place piece function takes a Piece class. The Piece class could, for example, contain information about what numerical value would represent that piece, and the board could use that and set and appropriate bits.
    When using the get piece function, the board could simply create a Piece object, fill it out and return it.
    Yes, it may not ideal and it might not be the best solution, but it works. The only thing you have to do is find a clever way to "hide" or encapsulate the bitboard implementation into some usable interface.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  2. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 04:52 PM
  3. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 05:24 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21