Henk wrote:Smallest change first. Looks like bug has gone. But my engine has more of these non thread safe static variables. Ok position factory should be singleton too.
public static Field GetField(IBoardSquares chessBoard, ulong bitCoord)
{
int i = BitBoardIndex.Instance.Index(bitCoord);
var field = chessBoard[i];
return field;
}
public class ChessBoard: IBoardSquares
{
..
public Field GetField( ulong bitCoord)
{
int i = BitBoardIndex.Instance.Index(bitCoord);
var field = this[i];
Debug.Assert(field.RowNr >= FIRSTROW);
Debug.Assert(field.ColNr >= FIRSTCOLUMN);
Debug.Assert(field.RowNr <= LASTROW);
Debug.Assert(field.ColNr <= LASTCOLUMN);
return field;
}
..
Very good. Looks much better now!
Making the "position factory" a singleton would give it a state, which you probably don't want to do. I think it is sufficient for a factory to have static methods.
mar wrote:Forget about "design patterns", use common sense
you really don't need 20 "factories", 50 "managers" and 200 "singletons" to accomplish something that's actually very simple
"design patterns" are nothing but weird names (seemingly cool) for common (or less common) ideas
invented by people who want to sell you their books
We are talking about one factory and one singleton, actually. I have no doubt that it can be discussed whether they are useful. But there should also be no doubt that once you use them, you should do it correctly. Also nobody forces you to use design patterns but that does't mean yet that using them is bad in general.