Hi again,
I'm struggling with this a bit.
I don't think the implementation of my engine in C++ as it stands lends itself very well to making it compatible with a GUI. I think I understand the principle of it now, superficially at least, having studied the CPW code. I'll try to describe my program as well as possible without posting pages and pages of code
My code uses a 'Player' base class with a virtual method
, and polymorphic derived classes 'Human' and 'Eva'. Calling
invokes the search function which returns true if there is no legal move, and returns false if there is a legal move. (The move is passed back be reference.) Calling
calls code that waits for input of a move (at present from the terminal), checks if it is legal and returns it via M (by reference). Again, it returns true if there is no legal move, thus breaking the loop and printing a "end of game".
So my game loop code is essentially just a one-line loop
Code: Select all
player* Player[2];
Player[0]=new Human(white,pos);
Player[1]=new Eva(black,pos);
side stm=white;
for (Move M;Player[stm]->play(M)==false; stm=side(1-stm),M=Move()){
pos.makemove(M);
// (player::Interface)->DisplayBoard(pos);
}
printf("End of Game");
//delete stuff
In the above, Move() is just a null move, and pos is an instance of a position class that stores all the position data and bitboards and stuff, with methods to make and unmake moves etc...I think the rest should be obvious.
My first thoughts about how to implement an interface with a gui (whilst maintaining the option to run from the terminal too) was create a polymorphic interface class with derived classes for terminal, xboard and uci, with a static pointer to it in the player class. Then I can pass instructions to the interface with something like
, and similarly for input. I reconfigured my terminal interface to work like this (hence the commented out instruction in the above code)
Subsequent to that I realized that if I wanted to, for example, make my engine play black by sending an instruction from the terminal or from xboard, I'd have to make it leave Human.play(M) where it received the instruction, to switch Player[0] and Player[1] and switch Human and Eva's colours. Perhaps not terribly difficult in itself, but then considering other commands like forcing the engine to move or giving hints, it would probably get more complicated. Also, implementing pondering: I'd have to call the pondering routine from within the Human class (whilst polling for input from the Human), which kind of goes against the object orientated paradigm in my opinion -- pondering would be best called from the Eva class, since it is Eva that is doing the pondering. All that considered, I think it will all quickly become spaghettified. That all probably sounds quite confused, but I hope it made some sense.
I'm not sure that I have a specific question, but any further comments or advice would be helpful. I'm really grateful for all the help thus far

I'm starting to think I may have hung myself by trying to adhere to OOP principles. (I'm sure it's obvious by now that I am not a professional programmer

)