I'm a C ++ programmer trying to learn designing, as a start, I myself got a chess Working to create an OO design for the game. It's not just a homework attempting to develop some skills. Even in my mind it has been summarized: A "piece" class which will maintain the current state of the piece of the board. Special classes "camel" "horse" "queen" "knight" "pawn" & amp; "Elephant" which will be derived from the "Piece" class. For each of these classes, 2 members, "the number of places that are not allowed to move" and the " Get "the rules of walking" and ways to achieve that.
A base "player" class that will be extended by the classes "Blackpiece Player"; "WhitePiecePlayer". Each of these classes will have an example of another class called "Piece Manager", which will be the "Peace Manager" class that will determine the logic of moving around the pieces of the board.
A "Chisboord" class that holds the mapping of all the pieces of the board and access the set of rules with which the pieces can be transferred. It will provide an interface to authenticate a trick calculated "piece manager" and then take action by updating the mapping of its own.
Here is a general stream that I can visualize. A class called "Whitespace Players" is said to make one step, it asks its "WhitePix Manager" to make a move. "Whitepiece Manager" will reach the position of the pieces of the board using the "Board" class interface. So it will use its internal logic to calculate a step for a piece. Each piece stores its position, so he calculates the position for that piece. After this, the board can call a method of class and it can be authentic to walk and then the board uses the class interface to take this step..and so on ..
Sorry for the long story, I'm just trying to develop, I'm looking for a design and that's what I'm thinking right now, do you think it's good for a start or a suggestion about improving it (if This is correct)
some suggestions
- Your hierarchy of sections related to the piece seems appropriate (though using appropriate names for pieces of the piece, stop, and bishops probably , Camel and Elephant).
- I will not store the number of squares that allow one piece to go. You want to write code in the "rule of movement" method, if only because it can change depending on the situation. One piece can take two sections on its initial move and then a square in the later move. A king can move only one class, unless it is casting.
- Your trunk sections will require some method to obtain the list of legitimate tricks of all pieces to provide those of the engine, going to choose a trick.
- You do not need BlackPiece Player and Whitespace Player Classes. You only need to trigger two different instances of player category and make sure that the "color" attribute is.
- An intelligent class is a good idea and it must represent the position of pieces but it should not apply the arguments to evaluate the moves. To do this, there is something for the conduction engine.
As Javier is discussing, the creation of the chess program is likely to make a lot of effort on designing an efficient algorithm to choose one step. Believing that your intention is to apply OO concepts and not to discuss how to build chess engines (which often sacrifices OO purity for better performance), and assuming that you Want to make something that can play well interesting, you may want to consider implementing rather than regular chess. From the OO perspective, this is essentially a similar problem, but the end result is something that plays very well without investing hundreds of hours in mastering the chess algorithm. This is a much more enjoyable result than the chess program, which is very playable.
Comments
Post a Comment