Author: Russell Reagan
Date: 23:07:10 07/22/02
Go up one level in this thread
>I agree. You're going way overboard if you have per-piece versions of all those >functions. Keep it simple. How do you propose that I do that? If I do something like: if (move.type() == PROMOTION) then I might as well be doing: if (move.type == PROMOTION) and just forget the encapsulation thing altogether. My goal is to create each part of my program so that I can make changes to it without those changes affecting anything else in the program. If I have stuff like the previous example littered all over my program (or more likely accessing the position data structure everywhere in the program) and then I decide I'd like to change a thing or two about how I represent a game of chess, I might as well start over (which is what I've done many times, which is why I'm doing this). There are plenty of other benefits like being able to verify things in debug mode, optimizing in one place and it trickles down to everywhere that it's used in the program. Imagine if I implemented my castling rights as a value using 4-bits and did bitwise operations on those 4 bits to set or clear certain castling rights, and my program was littered with things like: if (move.type == ROOK_MOVE) { if (move.from == A1) castlingRights &= ~WHITE_QUEENSIDE; } If I want to change how the castling rights are represented in memory, I've got to go change that everywhere in the program. If I have a CastlingRights class I can just do: castlingRights.clearWhiteQueenside(); and then I can change how it works internally, and the rest of my program will never know the difference (except for the speed increase). Basically I go back and forth between how to do something all the time, so I'm making interfaces for everything so I can change how it works internally without having to rewrite half my program each time I want to even test using a new method. If you understand OOP better than me (which I'm sure many do) and you could provide me some better examples of how I should be doing this to acheive my goal of encapsulation, then please let me know, because I often think I'm going overboard too :) Russell
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.