2009-08-16 Claudio M. Camacho * src/game/manager.cpp: Clean up some unnecessary code in GameManager. [8493ca2c651c] [tip] * doc/TODO, src/ai/adaptive, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp, src/definitions, src/game/board/board.cpp, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/main.cpp: Fix regression in threefold and 50-moves-rule. This regression was introduced as the repetition detection code was moved into the Board class. Now this issue was reported by Tito Houzy and it has been fixed in this commit. Also bump to 0.3.99.4. [b5fee89fe4c9] 2009-08-15 Claudio M. Camacho * doc/TODO, src/game/board/action.cpp: Fix 'back' when a null move is present. [50744c208326] * doc/TODO: Update TODO. [15814df0ec3c] * doc/TODO, src/application/manager.cpp, src/main.cpp: Reckon Ctrl+D and stop the application. Also update the TODO with the things left for v0.4. [05668832486e] * doc/README, src/main.cpp: New versioning schema. Add a new versioning schema, detailed in doc/README. Also added Tito Houzy and C2H5OH as main collaborators in doc/README. [5526adb5011b] * doc/TODO, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/application/test.cpp, src/game/board/piece.cpp, src/main.cpp: Fix 'test moves' when a game is finished (since no valid moves). [06851cd55f78] 2009-08-05 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/classic, src/ai/classic.cpp, src/definitions: Fix cache issue with iterative depth search. Now, the new search method is working, since this patch fixes some caching issues that used to happen in the previous revision. Therefore, there is now a nice new method in adaptive.cpp, different from what it was in v0.3.2, and it works correctly. This method makes the AI engine fast. However, the performance of undoMove() is still quite bad, and I hope that some new patches I am preparing will make the engine about 2 to 3 times faster than what it is now. By the way, the new thinking method (iterative depth search) is only available in Adaptive, since Classic does not know about move ordering. Further, Classic is just an already-deprecated tool which will serve a purpose of comparison between the two engines, but nothing more. So, in the future, Classic should be deleted (after its purpose is accomplished) and Adaptive shall be the only one engine in Chess0. [aca56f33b5e9] * src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp, src/definitions: Initial rework of AI thinking style. Added time limit on Unix. First, v0.4 is suffering a radical change in the AI thinking methodology. Previously, the engine would just perform a search up to the specified depth. With this commit, a big revamp starts, and with it, Chess0 will now search at each depth, until it reaches the terminal depth. That means that the engine will first search at depth 1, then at depth 2, and so forth until reaching the maximum depth (controlled by AI_DEPTH). This should, in theory, be slower. However, the fact that we perform a search at each depth, is very good, since the moves are sorted before each search, and the guessing probabilities just increase as we increase the depth. Please note that this patch is the first experimental one and hence most of the things just don't work. For instance, the Classic AI simply doesn't respect this depth and the Adaptive AI is confused with the transposition tables. So there is a long way to 0.4. Besides all this, I implemented a "mandatory" feature, which is the time limitation. It is implemented using SIGALRM on Unix systems. The Windows port will have to wait until some brave person decides to port the code of SIGALRM to use the Windows capabilities. The time limitation is not configurable yet via the command line, so you must edit src/definitions manually and set the maximum number of seconds in the option AI_THINK_TIME_LIMIT. [337e8782934a] 2009-08-03 claudio * .hgtags: Added tag v0.3.2 for changeset f451912b2f15 [a65c0a54c876] * src/definitions: Decrease default dpeth, as adaptive is really slow. [f451912b2f15] [v0.3.2] * src/game/manager.cpp: Fix a critical bug in check-mate detection. Call this release v0.3.2 already. [7503381a88b1] 2009-08-02 Claudio M. Camacho * .hgtags: Added tag v0.3.1 for changeset 26abed3cec98 [dc68baf25115] * src/ai/adaptive.cpp, src/ai/classic.cpp, src/definitions, src/main.cpp: Separate AI_DEPTH into AI_DEPTH_CLASSIC and AI_DEPTH_ADAPTIVE. This is also the milestone for v0.3.1. [26abed3cec98] [v0.3.1] * src/game/board/board.cpp: Fix threefold repetition that wasn't working with the previous commit. [63e07c27213f] * src/ai/adaptive_extensions.cpp, src/game/board/action.cpp, src/game/board/board.cpp, src/game/board/piece.cpp, tests/mvv_lva.c0b: Fix a potential crash in MVV/LVA with empassants (reported by Tito Houzy). Also move threefold rule to Board and prepare for big optimizations by storing pieces' statuses in stacks and then restoring them up on undoMove(), instead of recalculating all the statuses again. However this feature is not enabled yet, since it is quite unstable. [e9d3bcdfc210] 2009-08-01 Claudio M. Camacho * doc/TODO, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/edit.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/manager, src/game/manager.cpp: Move the threefold rule into Board. Please note that another change is in progress, which is the optimization of pieces' updating, and hence this revision consumes huge amounts of memory and it doesn't work properly. Please be patient and wait for the finalization of that patch. [e4a3bbc209be] * doc/PERFORMANCE, src/ai/adaptive_extensions.cpp: Update PERFORMANCE document. [1fbd3a81382a] 2009-07-31 Claudio M. Camacho * doc/TODO, src/ai/adaptive.cpp, src/ai/adaptive_extensions.cpp, src/game/move, src/game/move.cpp: Implement MVV/LVA in adaptive_extensions.cpp. Also add a patch for disabling SIGINT when not thinking. Thus, letting the user to quit the program if he or she wishes so. [c1e2188a1e12] * doc/PERFORMANCE, src/definitions, src/game/board/legal.cpp: Remove insert() in legal.cpp in favor of a new code. The new code is actually comming in a separate patch. The move ordering will be implemented using the MVV/LVA technique in adaptive_extensions.cpp. [91872b36577e] * doc/PERFORMANCE, doc/TODO, src/ChangeLog, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board: Add some performance boost in move generation. This is a patch for optimizations in move generation. The thing is that Piece::update() is being called more than necessary. Now it is called after each doMove() and undoMove(), to update every piece on the board, but no extra updates are used. However, this optimization could go beyond this, since we can store the status of a piece before updating, and then restore it with a de-update() function. This will requiere much more memory, to vectorize all the statuses, but we can't have everything :) [e6bd6e5684f8] * src/ai/adaptive.cpp: Small optimization: if only one valid move, don't search. [193aeb402781] * src/application/cmdparser.cpp: Parse 'sd' as 'depth', for XBoard depth setting. [d8b8d80505a4] 2009-07-30 Claudio M. Camacho * src/application/execute.cpp: Fix null move for black, which was not working. [cb89c1a5330c] * doc/TODO, src/game/game.cpp: Update TODO and re-arrange GameManager::perform(). [690a00b673e3] * doc/TODO, src/ai/ai.cpp, src/application/execute.cpp, src/application/manager, src/application/manager.cpp, src/application/xboard.cpp, src/definitions, src/game/board/action.cpp, src/game/board/legal.cpp, src/game/manager.cpp, src/main.cpp: Fix 50-rule (recently moved to Board) and add different DRAWs. Now Chess0 can realize which type of draw happened and report it to the user, both on the command line interface and on the XBoard protocol. [213ee7b637bd] * doc/TODO, src/ChangeLog, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/manager, src/game/manager.cpp: Move 50-rule to Board. This is the first patch of a series which try to eliminate the draw effect from the AI. The problem until now was that the 3-repetition rule and the 50-moves rule were implemented in the GameManager. This was the cleanest way. However, the AI engine does not know about the game when analyzing, but only about the board. Therefore, if the GameManager is the only module aware of the repetitions, the AI engine does not know and ends up consuming all the repeated moves, thus ending most of the games in draw. With this patch I start to push changes and move them from Game/Manager to Board, thus making the AI draw-aware and hopefully fixing many logical problems when solving positions and playing overscored games. [974e037e357a] * doc/TODO, src/ai/adaptive.cpp, src/application/manager.cpp: Implement 'move now' in Adaptive. When pressing Ctrl+C or sending SIGINT to Chess0, it will interrupt the search and look for the best move. If Chess0 didn't have time to analyze any move, it will just return a random valid move. [0327845e7ffd] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai: Initial support for 'move-now'/'force-move' using SIGINT. [03aec99f67ff] 2009-07-29 Claudio M. Camacho * doc/TODO, src/application/execute.cpp, src/application/manager, src/application/manager.cpp, src/application/xboard, src/application/xboard.cpp: Clean up xboard.cpp a lot and improve protocol support. This commit improves the overall behavior when Chess0 interacts with XBoard. For instance, the 'new' command and the 'quit' command are now more responsive. Furthermore, check-mates and resignation works as well, which didn't work before. Next step, although not yet for the v0.4, I should implement more things from the protocol as well as time control and move forcing. [4f36b372380d] * src/application/cmdparser.cpp, src/definitions: Add initial support for the command 'xboard'. In the future, the command 'xboard' should be interpreted as resetting the game and entering the XBoard mode. For instance, ApplicationManager could stop working and then launch an instance of the class XBoard. Furthermore, XBoard could inherit from ApplicationManager, thus avoiding a lot of duplicated code, as it is now. [035054fcaa67] * src/application/xboard.cpp, src/application/xboard_execute.cpp, src/game/manager.cpp: Move execute() to xboard.cpp. [e31c85aee9df] * src/application/xboard.cpp, src/application/xboard_execute.cpp: Futher clean xboard. Remove a lot of trash that is not in use in xboard.cpp nor in xboard_execute.cpp. [80bfe99b4393] * src/application/manager.cpp, src/application/xboard, src/application/xboard.cpp: First patch to synchronize XBoard with ApplicationManager. [7793cbcc7ac6] * doc/TODO, src/ChangeLog: Update TODO. [e1aabdae135e] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic.cpp: Fix cache clearing. From v0.3, there was a mistake in the code that could actually cause high depths to consume huge amounts of memory. This happened because clearCache() was called after each root move. However, if a root move was analyzed with enough depth, the cache could grow and grow without any limits. The new implementation is trickier, but it works in a suitable way. Any time a board is being cached, that is when we insert a new entry in the cache, we check if the cache is full. If it is, then delete the first item. This way, only small deletions happen when the cache is full. [2ef24b197da6] * doc/TODO, src/application/manager.cpp, tests/half_promotions.c0b: Fix a dumb problem with black promotions. Apparently, it has been there from the dawn of time, and it was that [a-h]1 didn't work for capture-promotions, since ApplicationManager::getInputType() didn't accept it as a command nor a move. So fix that. [57fc04778643] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_extensions.cpp, src/definitions: Fix long thinking in promotions.c0b. [1f745a9c29e9] 2009-07-28 Claudio M. Camacho * src/ChangeLog: Update ChangeLog. [c3467415805a] * src/ai/ai.cpp, src/game/board/legal.cpp, src/game/manager.cpp: Clean up GameManager and add 2 kings draw detection to Board. [47023faad045] * tests/pawn_vs_king.c0b, tests/two_pawns_vs_bishop.c0b: Add two more tests for testing end games. [c37e7bbe3824] * src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_extensions.cpp, src/ai/ai.cpp: Improve auto-depth in Adaptive and move the code to adaptive_extensions.cpp. [0dac2fec031c] * src/ai/adaptive.cpp: Add promotions to quiescence search as critical moves. [6f00e9a01848] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_extensions.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic.cpp: Implement search tree saving and boost performance astonishingly. This is a very nice optimization that boosts performance by a 350% on average and, on most cases, around a 9x faster than the previous revision of Chess0. The code is found in adaptive_extensions.cpp, and it is as simple as saving the last search best moves and then re-ordering the starting moves for the new chess according to the score found in the previous search. This is due to the fact that, if Chess0 finds good moves in a search and performs one of them, the rest of moves are most likely to be still legal in the next situation, and we already know that they are good moves, as they are in the list of best moves. Therefore, start to search, the next time, from those moves, since the possibility of alpha-beta cut-off is extremely high. As an example, tests/lacoz.c0b was solved in 145 seconds in the previous revision of Chess0. However, with this improvement, Chess0 is capable of solving the same problem in 19 seconds, which is very significant. [c177d3621f3a] * doc/TODO: Update TODO. [cbc31eef6753] 2009-07-27 Claudio M. Camacho * doc/TODO, src/ChangeLog, src/ai/ai.cpp, src/application/execute.cpp, src/game/manager.cpp, src/game/moveparser, tests/middle.c0b, tests/queen_vs_king.c0b, tests/rook_vs_king.c0b, tests/two_bishops_vs_king.c0b: Fix solver behavior with loaded matches. Actually, this fix is in MoveParser::pretty(), which had some problem with setting the turn/color and Board::getAllValidMoves() was thus broken. Also, I added three different positions in tests/ to test the end- games with rooks, queens and bishops. [b8c73b6adb5d] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic.cpp, src/application/execute.cpp, src/application/manager.cpp, src/definitions: Implement basic solver. This is a draft of a real solver. It can solve any position whose winner is also the side who is about to move. Draw positions are not a valid solution. This draft works but it has many problems. For example, loaded positions do not work at all, but soon I'll push the fix for this (as soon as I find it). [0230ce88c77d] * doc/TODO, src/ChangeLog, src/application/xboard.cpp, src/definitions: Add SAN notation to XBoard and rise default cache to 128MB. [c4808e9023d6] * doc/TODO, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions: Start coding 'solve' command using 'auto' as a base. [c9d46af94639] * doc/TODO: Update TODO. [2f518af7f517] * doc/TODO, src/ChangeLog, src/game/moveparser, src/game/moveparser.cpp, src/utils: Implement SAN notation for all moves coming from the computer. [ee691346cc7b] * src/ai/adaptive.cpp, src/ai/classic.cpp, src/application/manager.cpp, src/game/moveparser.cpp: Fix broken SAN in AI engines. [e815f7117802] * src/ai/adaptive.cpp, src/ai/classic.cpp, src/application/manager.cpp, src/game/board/book.cpp, src/game/move.cpp: Move 'pretty'-calls to AI. This commit breaks the AI functionality. So please wait for upcoming releases. [6f932aecd153] * src/application/manager.cpp, src/game/moveparser.cpp: SANify pawn moves. [4f38e9991f41] * src/application/manager.cpp, src/game/moveparser, src/game/moveparser.cpp: Initial changes for converting machine moves into SAN notation. [461236d09ee2] 2009-07-26 Claudio M. Camacho * .hgtags: Added tag v0.3 for changeset f241fd6bc56a [a603578ebb23] * doc/PERFORMANCE, doc/TODO: Update TODO and PERFORMANCE once more. [f241fd6bc56a] [v0.3] * doc/TODO, src/ai/classic.cpp, tests/bishop_before_knight.c0b: Implement fast move in Classic AI. Backport fast move, when white opening (picking one at random from the book without even thinking) from the Adaptive AI to the Classic AI. Also update TODO, and please notice that this is the last commit before v0.3. Next commit we are already coding for v0.4 :-) [093f3c7dec48] 2009-07-25 Claudio M. Camacho * src/ai/adaptive.cpp, src/ai/classic.cpp: If found a mate-move, tell it in words if verbose. [1082ec0e40b6] * .hgtags: Added tag v0.3-beta1 for changeset 7a09cbaa8c28 [e89dd8fafeee] * doc/TODO: Update TODO and prepare for v0.3. [7a09cbaa8c28] [v0.3-beta1] * doc/TODO, src/ChangeLog, src/ai/adaptive_position.cpp, src/definitions: Update TODO and clean-up definitions. [4827658ce872] * doc/TODO, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/classic.cpp, src/definitions: Simplify caching methods. Now, since we can store the actual depth of the score for a given board, we don't need to use the CACHE_DEPTH method anymore. Therefore, boards are always stored. Please note that now the cache size will increase very fast, however the 64MB limit is rather appropriate, since old positions will be deleted as they are not needed when the game moves forward. I also added some corrections to the queen evaluation in Adaptive. [94d20a9c37a0] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp: Improve cache storing by keeping also the depth of evaluation. [520b5fa08ea3] * doc/PERFORMANCE, src/application/execute.cpp, src/definitions, tests/grunfeld.c0b, tests/middle.c0b, tests/nodes.orig, tests/ruy_lopez.c0b: Modify nodes.orig and decrease the default randomization factor. [119572f152ee] * doc/TODO, src/ChangeLog, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic.cpp, tests/lacoz.c0b: Re-implement alphabeta() and quiescence(). After many hours of checking what was the problem with quiesce(), I noticed that it is not used properly, as it must be used at the end of a tree. Before, quiesce() use to expand the tree in every recursive call of alphabeta(), thus making the search endless in most of the cases. Currently, quiesce() is now used only to search a quiet position, before any evaluation is given. This is the basic principle of quiescence search, since we cannot return a static evaluation from a board, if we don't know if the board is in a critical move-frame, yet on a quiet position right now. The quiesce() function is always called before any evaluation is given, at the end of alphabeta() (in the leaves), and, if and only if the position is quiet, return a static evaluation. Otherwise, analyze further. Moreover, the alphabeta() function had some mistakes, since every time it was called, it was looking on a wider range (best = -FLT_MAX), thus making it slower and not returning proper values. I changed the way the alpha-beta pruning is performed and the algorithm seems much more solid now. [4654e3c404a4] 2009-07-24 Claudio M. Camacho * doc/TODO, src/ai/adaptive.cpp, src/ai/classic.cpp, src/definitions: Fix quiescence cut-offs, and improve the algorithm. Now, the quiescence search is capable of cutting off in a nice point, and this makes the algorithm times faster. However, there is still some problems in these cut-offs, as the machine may give some pieces away in normal situations. [475cbddd77eb] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic.cpp, src/definitions: Add initial support for quiescence optimizations. This commit introduces a set of patches to produce a faster search when in quiescence mode. This is achieved by detecting when a quiet position is near, and then cutting the search at that "quiet" point. Also, I added an "*" next to a score in the display when the move is cached. And Classic AI can also show now the depth and the cache status for each best move found. Please note that the quiescence search is still quite slow (much slower than not using it), and further improvement should be done to it before it becomes rather usable. [9046a371f8b4] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp: Add full quiescence search support. I added full quiescence search support, which means that the machine will look for any critical move at any depth that it is necessary. However, the search depth can vary critically between nothing and 30 or 40. This means that, for this revision, it will be impossible to play at some point, since the machine looks with a very high depth (sometimes over 30-plies). The fix for this will come in the next commit, since I plan to add a huge optimization in the quiescence search by cutting off any branch that is "quiet" after a quiescence search. I also added the column Depth to the information displayed on every branch search and updated the TODO with some new ideas. [01e47be1012c] 2009-07-23 Claudio M. Camacho * doc/TODO, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/application/manager, src/application/manager.cpp, src/application/test.cpp, src/definitions: Change the command 'nodes' for 'test' and add a moves test. The moves test can be used to see the performance of the logic of the game, namely recalculateMoves(). [65cb5c95c93f] * doc/PERFORMANCE, doc/TODO, src/ChangeLog, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/classic.cpp, src/application/execute.cpp: Simplify adaptive_position.cpp and show calculation times on verbose. This is a big commit, however it introduces few changes. Actually, adaptive_position.cpp is suffering a big overhaul, as it had many repeated lines. Besides, I introduced a change requested by Tito Houzy, in which the best moves calculation is displayed with its time next to it. The output is now much nicer, kind of looking like the crafty one. Please note that the heuristics in adaptive_position.cpp are still sort of broken, and the whole Adaptive engine is suffering changes, as I also plan to introduce more specific quiescence search. [ca7049f6dbd5] 2009-07-22 Claudio M. Camacho * doc/PERFORMANCE, doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/edit.cpp: Simplify adaptive_position.cpp and add queen detection support to Board. [be26dc62fe82] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic.cpp, src/application/execute.cpp: Disable white-fast-move on load, and re-enable it on restart. [dbc5d010b2b5] * src/ai/adaptive.cpp, src/ai/ai.cpp, src/ai/classic.cpp, src/game/board/board, src/game/board/board.cpp: Improve cache storing by adding whose turn is it. This is necessary since a position may be stored when playing white, and then black may recall this position, but with their turn ahead. This would lead to misguidance, since the value is not real. [98e27999bf01] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai.cpp, src/ai/classic.cpp, src/game/board/action.cpp, src/game/board/board.cpp, src/game/move, src/utils: Fix problem when looking for the best move in negamax(). Apparently, there was a problem in the negamax() because of the condition value >= alpha. With this, long time ago, I tried to make the algorithm more generic and let the machine collect a wider range of moves for the randomization. However, it turned out to be evil, as the machine would remember the best value and assign this value to newly-calculated values. The problem with this was that the best move was never assured, as it was mixed along with other moves, and then the randomization took care of picking one of those. Moreover, I will have to research the failure of my previous thinking, since I am almost sure it couldn't be that mistaken. Further, I have cleaned up Board, concerning the log calls. I have also added some comment fixes to AI, suggested by Tito Houzy. [2b9278390bb0] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp, src/definitions, src/game/board/action.cpp: Make the Adaptive engine to search deeper when in check or capture. [591917065260] 2009-07-21 Claudio M. Camacho * doc/PERFORMANCE, doc/TODO, src/game/board/book.cpp, src/game/move, src/game/move.cpp: Fix book openings and add more of them. [467175a74aff] * doc/TODO, src/game/board/action.cpp: Clean-up action.cpp and integrate empty() inside removePiece(). [f8b3db303ba0] * doc/SEQUENCES, doc/TODO, src/ChangeLog, src/game/board/board.cpp, src/game/board/book.cpp: Add some more moves to book.cpp. [fc07500782b6] * .hgtags: Added tag v0.2.3 for changeset 195afef6c794 [08507e5481eb] * doc/TODO: Update TODO, preparing for 0.3. [195afef6c794] [v0.2.3] * src/game/board/legal.cpp: Fix typo (by Tito Houzy). [c54a48017887] * doc/SEQUENCES, src/game/board/edit.cpp, tests/board_status_test.c0b, tests/promotions.c0b: Add two important tests: board_status_test.c0b and promotions.c0b. These two tests are actually positions (.c0b), and they should be loaded and then tested using the command 'go'. board_status_test.c0b tests the status of the board with high depths. It is a generic test for testing the logic of the board using doMove() and undoMove(). promotions.c0b is meant for testing many promotions occurring at the same time. [0bd165188d9a] * doc/TODO, src/ChangeLog, src/ai/ai.cpp: Fix cache disabling. Previously, disabling the cache didn't clear what it was cached until that moment. Currently, the program sets the limit to 0 (when turning off the cache) and also clears the whole cache, thus making the AI engine to re-think all the moves all over. [a59aee8e2509] * doc/TODO, src/ai/ai, src/game/moveparser.cpp: Revert a fix from revision 152 where MoveParser suffered an alteration. In this revision, I changed PROMOTION_CAPTURE for PROMOTION_CAPTURE_SHORT. However, Board::getAllValidMoves() never returns PROMOTION_CAPTURE_SHORT, and thus the promotion capture short type was not working afterwards. [0893491016dc] * doc/TODO, src/game/board/action.cpp, src/game/board/legal.cpp: Rearrange a couple of calls in doMove() and undoMove(). [1b50195fcc99] * src/game/board/edit.cpp: Really solve the the issue with promoting pawns in edited positions. [b5c1e8bd7556] * doc/SEQUENCES, src/game/board/edit.cpp: Check if pawns can move two squares or not after an edited position. This fixes a potential crash when loading a board with pawns one row behind the promotion line, which previously could make two steps, and therefore go over the border of the board. [6e1f54a1c9d8] * src/ChangeLog, src/application/help.cpp, src/game/board/board.cpp, src/main.cpp: Improve help and bump version to 0.3 (where we are heading). [99303bd288b5] 2009-07-20 Claudio M. Camacho * doc/TODO, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/legal.cpp: Add basic logging support. A new command 'log' is now used to specify a disk file for logging board operations, such as move validation, move application, etcetera. By default, the logging support is disabled. For more information, please type 'help log' in the chess0 command line. [2e86df7cdc05] 2009-07-19 Claudio M. Camacho * doc/TODO, src/ChangeLog, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions, src/game/board/board, src/game/board/edit.cpp, src/game/game.cpp: Implement board position save/load to/from disk files. The two new commands are 'save' and 'load'. These commands save and restore a position to and from a disk file. Meaning that we can now store an interesting position for further study later on. Please note that these commands only save the position (recall the command 'edit'). Do not confuse with the PGN format, which is not "yet" implemented in chess0. However, save/load offer now a proper tool for testing different positions at different parts of the game. [d30e166459c9] * doc/TODO, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions, src/game/board/edit.cpp, src/game/game, src/game/game.cpp: Implement null move performing with the command 'pass'. A new command 'pass' allows now to perform null moves. This command is not necessary in normal cases, but it is very useful for testing purposes. [61f94432d290] * doc/TODO, src/ChangeLog, src/ai/adaptive.cpp, src/ai/ai, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/board/edit.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/utils: Initial support for position editing via the 'edit' command. Now it is possible to set a preferred position manually using the 'edit' comand. This command makes chess0 to enter the interactive editing mode, where white pieces are entered first, and then black pieces. Once the pieces have been entered for both sides, the program checks the integrity of the given board and, if everything is correct, the match continues from move white(1) but from the given position. On the other hand, if the integrity of the board is incorrect (e.g. one king missing, two kings of a same color, more than 8 pawns, etc), the program restores the previous board and match, continuing from where it was left. Note: the editor is unstable and it produces some status corruption in certain situations. Moreover, the turn to move is always given to the white, which should be corrected in the next revision. [7b1f09dabb9b] * doc/TODO: Update TODO [d0271ddf246d] * doc/README: Update README. [94a4cb62d467] * doc/TODO, src/ai/adaptive_position.cpp, src/ai/ai.cpp, src/definitions, src/game/board/book.cpp, src/game/move, src/game/move.cpp: Increase search and cache depth defaults, and reduce default cache size to 64MB [b48c2e097fb4] * doc/PERFORMANCE: Update doc/PERFORMANCE with the latest changes. [78edac966c83] * .hgtags: Added tag v0.2.2 for changeset 6459d63eb031 [dc9060263063] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/application/manager, src/application/manager.cpp, src/application/xboard, src/application/xboard.cpp, src/application/xboard_execute.cpp, src/definitions, src/game/board/knight.cpp, src/game/manager, src/game/manager.cpp: Implement draw offering and clean up XBoard. The 'draw' command now works, and the computer evaluates if it is better to stop or continue playing (although the implementation is rather ugly, for now). Clean XBoard a little bit, and remove unnecessary things such as the Prompt usage. [6459d63eb031] [v0.2.2] 2009-07-18 Claudio M. Camacho * .hgtags: Added tag v0.2.1 for changeset cec40f99fcf6 [19d3d2189d22] * doc/TODO, src/ai/ai.cpp, src/application/execute.cpp, src/application/help.cpp: Turn off cache feature if cache limit is set to 0. [cec40f99fcf6] [v0.2.1] * doc/TODO, src/ChangeLog, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic.cpp, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions: Implement cache size limit and provide an user-friendly command. Now it is possible to limit the cache size (in Mbytes) up to some boundary. This can be done, by default, in the src/defintions (using the CACHE_SIZE) definition, or either using a user-friendly command 'cache'. The AI engines work so that, when the cache size limit is reached, the oldest positions are removed. This algorithm is the easiest, yet the most powerful for this application, since old positions are unlikely to be re-evaluated as the game develops towards the end (due to missing pieces, for example). [32c2e6190081] * src/ai/ai.cpp: Display 'cached' after a move in verbose mode, if the move was fetched from the cache. [f7175a79e25e] 2009-07-16 Claudio M. Camacho * doc/SEQUENCES, doc/TODO, src/ai/adaptive_position.cpp, src/game/move, src/utils: Improve middle game playing in adaptive AI a lot. This is the next step after implementing dynamic quantums. Now, the adaptive engine is capable of taking advantage of the dynamic quantums, thus distributing the pieces in a much nicer way. Still, attacks are not well considered, and so the machine only places the pieces, without thinking of the possibilities of the attacks. Also the end-game is kind of forgotten still. [053da7e9ada4] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic, src/ai/classic.cpp, src/application/execute.cpp, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/utils: Implement dynamic quantum rearrangement. This is a nice thing, since this is one of the main purposes of the project. Now chess0 redistributes the weight of each square depending on the positioning of the kings, thus making the pieces to focus on areas where the attack is much more worthy. This patch is only the beginning, further improvements are about to come ;-) [e3ff7ba1d785] * doc/PERFORMANCE, src/ChangeLog, src/ai/ai.cpp, src/definitions, src/game/board/action.cpp, src/game/moveparser.cpp: Set default values for AI to more reasonable ones. Also fix a potential problem in MoveParser using PromotionSimpleShort (reported by Tito Houzy). [76041428b5e0] * doc/SEQUENCES, doc/TODO, src/ChangeLog, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/ai.cpp, src/application/manager.cpp, src/definitions, src/game/moveparser, src/game/moveparser.cpp: Fix problem in cache implementation and clean-up MoveParser. Set the map to use float values (previously it was using int), so that the cache is more accurate, as it should be. Also print the cache size (both in bytes and positions) when obtaining a new move from the AI. Clean up MoveParser, which had unnecessary mtype variables for each translate function (suggestion by Tito Houzy). [323e1474876a] 2009-07-15 Claudio M. Camacho * doc/SEQUENCES, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/ai.cpp, src/definitions, src/game/board/book.cpp: Speed up white opening. Make white move immediately at the first move, as no move is possibly bad if we take them from the list of book moves. The result is that white moves immediately on the very first move, without having to think. [d2518ccdc61e] * doc/PERFORMANCE, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/ai.cpp, src/definitions, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/moveparser.cpp, src/utils, tests/nodes.orig: Add memory cache support (kind of transposition tables). I added a rudimentary of keeping a memory cache. This is done by using transposition tables inserted in a C++ map which acts like a hash table. Thus, the evaluation function first picks the value of the board in the hash, and if it is not found, then the search is performed. In order to keep roughly safe moves, there is a #define named CACHE_DEPTH, which tells until which depth chess0 will save boards in the cache. By default, I set this value to 4, which means that, at least, two captures are assured to be safe, but no further moves. Now, the engine runs much faster on deeper depths, at is stores a huge amount of positions and their score in the cache memory. However, there are two main disadvantages: 1) the search performing is actually slower, if the value is not in the hash (however, this is only a 1% of the times); 2) chess0 consumes now really much memory (e.g. about 400M for a complete game with 6-plies search). The next step is to fix the adaptive heuristics, which do not work properly and they return a similar value for almost every move, and I really don't know yet where did I screw up. Please note that the cache feature is engine-independent, that is, it works both with the classic engine and with the adaptive engine. [19b0fb658d5b] 2009-07-14 Claudio M. Camacho * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_position.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/board/book.cpp: Add hardcoded opening theory in src/game/board/book.cpp. Aside the bad behavior of the heuristic, I added a new file (book.cpp) where opening theory moves are hardcoded. This is only a beginning, but the purpose is to widen this functionality, in order to load a book database from a file. However, this won't happen any soon. Furthermore, it is now very noticeable that chess0 plays from theory most of the time in the opening. As a note, please remember that I am developing the new heuristics, and hence the middle game and the end game are really bad, since the machine does not know how to act. [c674025461ca] * doc/TODO, src/ai/adaptive, src/ai/adaptive_eval.cpp, src/ai/adaptive_position.cpp, src/ai/ai.cpp, src/game/board/board.cpp: Add evalKnights() and improve evalPawns() and evalBishops(). [7e0afb41073b] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_eval.cpp, src/ai/ai, src/ai/ai.cpp, src/application/execute.cpp, src/application/help.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp: Prepare evalBishops() and evalPawns(), and add a debugging tool. Adaptive is receiving many changes, which means that it is totally nonfunctional right now. All the functionality is being split in smaller chunks and I am going to take my time for testing each module separately, until I get a reasonable heuristic function for the adaptive AI engine. Aside, I added a debugging tool which is quite nice. It is a new argument to the command display, named 'quantum'. With this parameter, we can visualize the current quantum distribution on the board, thus getting a rough idea about how the AI engine is thinking. Please note that this tool shows the dynamic quantum value of each square, which actually changes from one position to another. [7fe90440cb04] 2009-07-13 Claudio M. Camacho * .hgtags: Added tag v0.2 for changeset 0f211ae08133 [a8671a3eaca6] * .hgtags: Added tag v0.2-beta2 for changeset 2bf3ae9921cf [0f211ae08133] [v0.2] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/adaptive_eval.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp, src/application/xboard.cpp, src/definitions: Split adaptive engine into different files. This will server the purpose of allocating a larger heuristic funciton, for future improvements. Also, please noticed we are on 0.2-beta2. [2bf3ae9921cf] [v0.2-beta2] 2009-07-12 Claudio M. Camacho * .hgtags: Added tag v0.2-beta1 for changeset cc91fad2cd2f [2bfc69477a1f] * doc/PERFORMANCE, doc/TODO, src/ChangeLog, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/board/square: Improve heuristics on evalOpening(). Add a method to detect how pieces influence an attack on the opponent's side, which will be used for the adaptive engine. However, the evalOpening() function shall be common to both engines, as it has no merit, but pure heuristics. Also increase the default AI depth from 5 to 6, update the TODO and make small improvements all over the code. This is already v0.2-beta1 and, if noone complains before tomorrow, I will release v0.2 in 24 hours. [cc91fad2cd2f] [v0.2-beta1] * doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp, src/definitions, src/game/board/board.cpp, src/game/board/square, src/game/board/square.cpp: Add initial support for dynamic quantums in Square. [3941fbee6132] * src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp: Move more shared code to AI. This time negamax() and alphabeta(). [8f31e959c990] 2009-07-11 Claudio M. Camacho * src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/ai.cpp, src/ai/classic, src/ai/classic.cpp: Share much code across AI engines. Classic and Adaptive differ only in three things: a) randomization + auto-depth b) middle game evaluation c) end evaluation Aside, the opening and the material evaluation are the same in both cases. So this patch introduces a reduction in code that simplifies both engines, by moving shared code into AI. A further step would be to integrate negamax() and alphabeta() in AI as well. [394aa985080e] * src/main.cpp, src/utils: Implement a method for calculating distances. The function is in src/utils, and it is called dist(). Basically, it calculates distances between two squares (absolute distances), which is the maximum of the column difference and the row difference. This method will be very useful for dynamically changing the quantum of the squares, as the opponent's king or pieces are being re- arranged. Thus biasing the program to play more aggressive or more defensive. [e916fe513eec] * doc/PERFORMANCE, src/application/xboard.cpp, tests/001.orig, tests/002.orig, tests/003.orig, tests/004.orig, tests/005.orig, tests/006.orig, tests/007.orig, tests/nodes.orig: Implement 'new' command and simple error handling for XBoard. [19c1c8a3c87e] * doc/TODO, src/application/cmdparser.cpp, src/application/xboard.cpp, src/application/xboard_execute.cpp: Add some improvements to the XBoard protocol. [4a59f3c7f5b8] * doc/TODO, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic.cpp, src/application/cmdparser.cpp, src/application/manager.cpp, src/application/xboard, src/application/xboard.cpp, src/application/xboard_execute.cpp: Support xboard in a much better way. Now, xboard.cpp actually initializes the Xboard communication much better, since it enables supported features and disables unsupported features. Next step is to implement more things in the protocol, such as new game, etcetera. [061f6ecbc8cf] * src/application/execute.cpp, src/application/help.cpp, src/application/xboard, src/application/xboard.cpp, src/application/xboard_execute.cpp, src/main.cpp: Initial bits for XBoard protocol implementation. Now there is a new XBoard class, which is a simpler replica of ApplicationManager, and it is launched when the argument of chess0 is xboard. Nothing works yet, but the good thing is that xboard connects to chess0, and that is the pilar for further development. In order to start xboard with chess0, issue the following command: xboard -fcp "./chess0 xboard" [5c30cae5ab95] * src/application/help.cpp: Improve help (suggestions by Tito Houzy). [33841082e634] * src/application/execute.cpp, src/application/help.cpp: Return prompt when changing the AI engine. [8f81a1dbee52] * doc/TODO, src/application/cmdparser.cpp, src/application/execute.cpp, src/application/help.cpp, src/application/manager, src/application/manager.cpp, src/definitions: Implement a new command input infrastructure. Now commands may have arguments, and the command processing tool is much better. The code of the ApplicationManager is separated in manager.cpp, execute.cpp and help.cpp. Admittedly, the help now is far more informative, and it actually helps :) [46826e2d18ac] * src/game/board/pawn.cpp: Simplify Pawn::recalculateMoves() (suggestion by Tito Houzy). [5dc49489a441] * doc/PERFORMANCE, src/ai/adaptive.cpp, src/ai/ai: Fix a problem with depth setting in Adaptive. [748ec181c025] * src/ChangeLog, src/game/manager.cpp: Fix a crash in check-mate. This code was removed a few days ago, but I noticed that it is necessary, so I put it back again. [a5f40a6ab7d9] 2009-07-09 Isaac Jurado * Makefile, src/application/prompt.cpp, src/game/board/board.cpp: Mac OSX small compilation fixes (patch by C2H5OH). In OSX the G++ major detection was not working properly, which led many warning messages regarding -I- and -iquote. The detection has been improved to remove such warnings. The application/prompt class implementation was not including its header with proper path. It is strange how this error was not appearing in other platforms. Finally, a control flow warning in game/board/board class implementation has been detected due to function inlining in optimization. [8781e14b68d7] 2009-07-11 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ChangeLog, src/application/manager.cpp, src/game/board/board, src/game/board/legal.cpp, src/game/board/pawn.cpp, src/game/move.cpp: Fix a critical (yet stupid) bug in Pawn (fixed by Tito Houzy). I don't know why, but the black Pawn attack calculation was incorrect from the very first moment I implemented the Pawn attacks. The mistake was that pawns from columns B..G have their minimum capture at a1 (position 0 in integer form). However, the code was set to check after square 5, and hence no pawn captures from the black side was allowed for the range a1-e1, which si quite a shame. Astonishingly, this bug has been around since the dawn of time. Yesterday, Tito Houzy worked very hard with and without me, and this morning I received his email with the patch. Thank you, Tito Houzy. At the same time, I fixed a rules-problem that wasn't implemented before. This was the fact that pawns would not attack a square if there was no piece, and hence a castle could be performed even though a pawn was interfering. Now, the legality is totally moved to legal.cpp, thus implementing this missing feature as well. [5441ec1b5914] 2009-07-10 Claudio M. Camacho * doc/SEQUENCES, src/application/manager.cpp, src/game/board/action.cpp, src/game/board/legal.cpp, src/game/manager.cpp: Add debug messages using the proper debug interface. There is a critical bug somewhere, where pieces are being removed massively, so I added debug messages where needed, in order to hunt down the problem. Please be patient, I hope the fix arrives this weekend.. [7a3e27f58b4b] 2009-07-09 Claudio M. Camacho * doc/PERFORMANCE, doc/TODO, src/ai/adaptive, src/ai/adaptive.cpp, src/ai/ai, src/ai/classic, src/ai/classic.cpp, src/ai/eval, src/ai/eval.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/piece, src/game/board/rook.cpp, tests/nodes.orig: Split AI in Classic and Adaptive. This is the first step to build two different AI engines, which is the ultimate goal of this project. The class AI holds an abstract interface to any AI engine that shall be programmed. The class Classic includes the classical methods, returning always the best move found. On the other hand, the class Adaptive uses the adaptive methods, which by now are the randomization threshold and auto-adjustable depth. [2fc4f212000c] * Makefile: Change win32 for exe in the Makefile help (noted by TitoHouzy). [78dd5e59f066] 2009-07-09 mkd * Makefile, doc/TODO: Update TODO, and fix a small thing in Makefile. [9a4659c48c7a] 2009-07-09 Claudio M. Camacho * doc/SEQUENCES, doc/TODO, src/ChangeLog, src/ai/classic, src/ai/classic.cpp, src/ai/eval.cpp, src/definitions: Implement dynamic depth re-adjusting. Now, the machine is able to control the depth of the search, depending on the stage of the game. This can be disabled by defining AI_AUTO_DEPTH as false in src/definitions. Also, a define AI_DEPTH_DEVIATION is used to tell how flexible (in plies) the readjustment can be. Last, modify the heuristics for the opening, really giving a penalty to the pieces that move twice in the development. [f29e728a71c6] 2009-07-08 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ai/classic, src/ai/classic.cpp, src/definitions, src/game/move, src/game/move.cpp: Implement randomization. Simple randomization is achieved by calling negamax() and retrieve a list of all the best possible moves. Then, Classic::getMove() checks the whole list and searches for moves that are close to best (see RANDOMIZATION_THRESHOLD in src/definitions). If a moves is under the RANDOMIZATION_THRESHOLD, it is a potential candidate to be selected as a move. This RANDOMIZATION_THRESHOLD is obtained by substracting the best score minus the current move's score under analysis. [40f42f2f4ab6] 2009-07-08 mkd * src/game/board/board.cpp: Added some TODO comments to Board::updatePhase(). [e9d22a5b708f] * src/application/manager.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/legal.cpp: Rename Board::getAttacks() to Board::getKingAttacks(). [aa6d9b7d728d] * doc/TODO, src/application/manager.cpp, src/definitions: Improve the CLI user interface. Make so that with most of the commands, the board is not redrawn. This makes much more sense than the previous behavior. Also update the TODO list. [25b00d6da069] 2009-07-08 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ai/eval.cpp, src/definitions, src/game/board/legal.cpp, tests/nodes.orig: Finally, fix the problem with consecutive alternating checks. [97bdc685e04a] 2009-07-07 Claudio M. Camacho * src/definitions, src/game/board/action.cpp, src/game/board/board.cpp, src/game/board/legal.cpp: Fix another problem with double checks. I forgot that some pieces may do check when another check is ongoing, due to the ColorType used for checking the check side. [665954412009] * doc/PERFORMANCE, doc/README, doc/TODO, src/ai/classic.cpp, src/ai/eval.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/legal.cpp, src/game/game, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp: Fix a potential problem with kings approaching. Basically, the program didn't handle at all when two kings approach to each other. This situation can never happen, but it was difficult to handle since there is a double check (for both kings to its corresponding opponent). Also fixed another problem that a check could not be solved by a counter-check, and this is possible (it happened to me in one match against chess0 ^_^). Also there are some changes in the heuristics and the program is much more mature in all aspects. The only problem left is randomization (the program always plays the same move) and a segmentation fault in very rare cases, that I haven't been able to tackle down yet. [4e4750eef7f1] * doc/SEQUENCES, src/game/board/legal.cpp: Fix erratic positioning at filterCastlesLong(). [ae7c2cbb2ba8] * doc/PERFORMANCE, doc/README, doc/TODO, src/ChangeLog, src/ai/classic, src/ai/classic.cpp, src/ai/eval.cpp, src/application/manager.cpp, src/definitions: Remove minimax() in favor of negamax(). Up until now, I didn't understand well the purpose of removing minimize() and maximize() function and replace them by one only function and then negating it. This was, as a matter of fact, the negamax() algorithm, which is an elegant version of the minimax() based on the assumption that the best move for me is the worst move for the opponent. Thus, calling the same function and retrieving its negated value (from there the negamax name). Also add improvements into the heuristics, and make the computer to play rather well with depth 4 and 5 until the middle game. Actually, the number of nodes examined now with depth 5 is 16.66Knps, which is one of the best performances chess0 has achieved. Last, I updated the README (still very incomplete), which is totally outdated. [a0216e7b39a3] 2009-07-05 Claudio M. Camacho * src/ai/eval.cpp, src/game/board/board.cpp: Minor improvement about pawns in evalOpening(). [142fd60c554c] * src/ai/classic.cpp, src/ai/eval.cpp, src/game/board/board.cpp: Simplify minimax() function. Also put a penalty on a moving queen when developing. [814509cf2c8e] * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ai/eval.cpp, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp: Improve evalOpening(). Take into account pieces development, castlings and other sort of things. Also fix check-mate, so that the machine is capable of locating the mate in a variant. [0aaeb1b7defd] * Makefile, doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/ai/classic.cpp, src/ai/eval, src/ai/eval.cpp, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp, src/game/game, src/game/game.cpp, src/game/manager.cpp: Add proper detection of the opening, middle game and end. [33c28b105490] 2009-07-04 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, doc/TODO, src/game/board/action.cpp, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, tests/nodes.orig: Fix a regression with empassants. A critical regression has been now fixed. It concerned to empassant capturing, that was misprocessed after the architectural remodelation. Hopefully, this will be one of the few times I have to go back and redo some parts of the infrastructure. Besides the main topic of this patch, I refactored some code and added performance improvements wherever it was possible. I also added a nodes.orig test to the tests directory, which actually sets the board with a few moves so that the nodes estimate is more realistic and pesimistic. Please use: cat tests/nodes.orig | ./chess0, in order to obtain the realistic number of nodes that the Classic AI can estimate in the program. Right now, we are on 11.28Knps, but the heuristic function is messed up and I have to fix also certain aspects of the alpha- beta minimax. [52fc6194c34d] 2009-07-02 Claudio M. Camacho * doc/PERFORMANCE, doc/SEQUENCES, src/ai/classic.cpp, src/ai/eval, src/ai/eval.cpp, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/utils.cpp: Add small optimizations in all pieces. [710b688f32e0] 2009-07-01 Claudio M. Camacho * doc/PERFORMANCE, src/game/board/action.cpp, src/game/board/bishop.cpp, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp: Add optimization in Piece. Use an actual variable for retaining the position of the piece (int pos), and update it whenever the getPosition() is called (using a getPos()). This makes the program much faster, since retrieving the position of a piece is instantaneous. Move on from 8.47 Knps to 12.71 Knps :-) [73a2360b7f6f] * src/game/board/legal.cpp, src/utils: Remove the on-the-move check with queen's side for crossing rook. This rule is not valid, according to the FEDA. In fact, on queen's side castling, the rook may cross a square attacked by an opponent piece, and still castle with the king, as long as the king does not cross an attacked square. [ca7613bab667] * doc/PERFORMANCE, doc/TODO, src/ai/classic.cpp, src/application/manager.cpp, src/definitions: Temporary fix to initial minimax() call. Still I don't know why, but maximize() and minimize() must be called as the first function from minimax() depending on the depth, probably because the last node is either the maximum of the minimums or the minimum of the maximums. Also, I detected that, on move 4, alpha and beta become infinity, and hence the AI stops working. Accordingly, I recalculated the performance with depth 3, and chess0 is already capable of processing 8.47Knps. [330cf5c954a3] * src/ai/classic, src/ai/classic.cpp, src/definitions: Avoid negative depth values (reported by Tito Houzy). [94e285f01ebb] * doc/PERFORMANCE, doc/TODO, src/ChangeLog, src/game/board/action.cpp, src/game/board/board, src/game/board/board.cpp: Initial set of improvements in the Board class. Add npieces and nremoved for performance improvements. This is a very small change, yet it introduced a huge performance boost. The current average speed is set at 6.59Knps, which is double than the previous one (3.75Knps). [a9a6535da2c9] * doc/TODO, src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp: Fix alpha-beta pruning in minimax(). The Classic engine is up and running. However, the performance is still extremely poor. This is due to the fact that the moves are not in order, and many things are not being optimized anywhere. The next step is to optimize everywhere, and also add a better heuristic funcion, since the current one really sucks. [303c7bbc4dcf] * src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp, src/definitions, src/main.cpp: Fix alphabeta(), which "kindda" works. Now it is possible to see some actual moves when playing against the machine. However, there is a problem with pruning, and the alphabeta() algorithm goes down the whole tree, which is very slow. Anyway, you can start playing against chess0. It is fun, because the heuristic is so bad, that it plays aweful :) [dcfa27ef9834] 2009-06-30 Claudio M. Camacho * src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp, src/definitions: Simplify classic.cpp by using a single alphabeta() function. Also add a patch (request by Tito Houzy) for not displaying the board when asking for help. [37ee7f218a57] * .hgtags: Added tag v0.1-rc1 for changeset befcd6eb8609 [c1ad9d5b20b7] * doc/TODO, src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board.cpp: First release candidate (v0.1-rc1). Fix many problems in the new architecture and make minimax work. So minimax() works now, but incredibly slow and silly. I have to really improve performance on it, since it takes ages to calculate a simple move even on depth 7. [befcd6eb8609] [v0.1-rc1] * doc/TODO, src/ai/classic, src/ai/classic.cpp, src/application/cmdparser.cpp, src/application/command, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/bishop.cpp, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp: Fix several segmentation faults in minimax(). These segmentation faults were due to erroneous doPromotion() and undoPromotion() executions. [304d6cac61dc] * tests/001.orig, tests/002.orig, tests/003.orig, tests/004.orig, tests/005.orig, tests/006.orig, tests/007.orig: Forgot to add 'manual' at the beginning of each test. [12609d5aac6a] * .hgtags: Added tag v0.1-beta2 for changeset 835faea36d6e [c8e474431031] * doc/TODO, src/ChangeLog, src/ai/classic.cpp, src/application/manager.cpp, src/definitions, src/game/board/action.cpp, src/game/board/board.cpp, src/game/manager, src/game/manager.cpp: Initial support for an integrated minimax(). Now it is possible to play human vs human, computer vs human or human vs computer, using the commands 'manual' and 'go'. The only problem is that, with a decent depth (already at 3 or 4), many infrastructure bugs are discovered. So the mandatory step before v0.1 is to fix all this problems. [835faea36d6e] [v0.1-beta2] 2009-06-29 Claudio M. Camacho * src/ai/classic, src/ai/classic.cpp, src/game/manager.cpp, tests/006.orig, tests/007.orig: Adapt classic AI to the new architecture. Now the classic AI uses the getAllValidMoves() function available in Board, which is very powerful. Moreover, I added a variable 'nodes' for counting how many nodes can actually be evaluated in the minimax() function. Furthermore, I fixed an issue where the 'fifty' variable of a GameManager (for counting the 50-moves repetition rule) was not set back to 0 up on game restart. Issue reported by Tito Houzy, according to tests #6 and #7. [ef401b3ae0b8] * .hgtags: Added tag v0.1-beta1 for changeset 493eb775153e [871149a47b90] * doc/TODO, src/ChangeLog, src/game/board/legal.cpp, tests/006.orig: Fix the on-the-move check. This is the last improvement, before going for v0.1. Now we are really on v0.1-beta1, and I will take about one week before I release the v0.1, thus allowing myself to have time to discover and fix bugs. I decided that I will try to integrate the simple ready minimax() code, before v0.1. [493eb775153e] [v0.1-beta1] * doc/TODO, src/application/manager.cpp, src/game/board/action.cpp, src/game/board/board.cpp, src/game/game.cpp, src/game/manager, src/game/manager.cpp: Implement the rule of 50-moves repetition. Also add some minor corrections to the game histroy manager (such as the ++ symbol after the winning move). Refactor dealEnd(), although I don't like its current aspect. [410e532a74ce] 2009-06-28 Claudio M. Camacho * src/game/board/action.cpp: Add forgoten action.cpp, fix linking problems (reported by Tito Houzy). [a82ad7de3566] * doc/TODO, src/ChangeLog, src/application/manager.cpp, src/game/board/board.cpp, src/game/board/pawn.cpp, src/game/moveparser.cpp: Finalize migration. Finally, the new architecture is ready. Recall: the move parsing, legality check and move performing (do/undo) are now well separated. This brought many problems, as it is typicall of any migration process. Furthermore, all move types have been implemented, and the regression tests are passed. However, regression test 004 is not well validated, as the on-the-move check functionality is still not working with the new architecture. This, and the 50-moves rule will be the last additions to chess0, before version 0.1 is out. Last, we could call this chess0-v0.1-alpha1, but let's leave it for the next commit, since I would like to be more sure about what is going to be included in v0.1 and what not. [de988a119cab] * src/game/board/legal.cpp, src/game/board/pawn.cpp, src/game/moveparser.cpp: Implement translatePromotion* and improve empassants. Still the code of empassants gives a lot of trouble, and it has to be well tested and readjusted to the new architecture. [a66c163502c2] * doc/TODO, src/ChangeLog, src/game/game.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp: Fix some problems in the game history and add new translateXXX functions. The history now shows the human algebraic notation, however the moves keep their original [from][to][promotion] string in algebraic. The new attribute in Move is 'human', which is a string that contains the actual human input to a valid move. Also add translateCastleLong(), translateCaptureShort() and translateAmbiguous(). [494d9f7ae801] * doc/SEQUENCES, doc/TODO, src/game/moveparser.cpp: Fix a potential crash in translateSimple(), add more translateXXX functions. Fix an important potential crash in translateSimple(), and, at the same time, optimize the translateXXX functions to not to even bother when a move is supposed to not be valid (e.g. a capture move should not even check if we are looking for a castle). translateCapturePawn(), translateCapturePawnShort() and translateCaptureSimple() are back. [d8a1bab24030] * doc/TODO, src/definitions, src/game/board/piece, src/game/moveparser.cpp, src/utils: Re-implement translatePawn() and translateSimple(). This is going gooood! [f41caa47b120] * src/ChangeLog, src/game/moveparser, src/game/moveparser.cpp: Polish MoveParser and add back the old translateXXX() functions. Please note that these functions are now empty, and they must be implemented using the new architecture, which is to retrieve the list of all possible valid moves from Board, and then search, move by move, if any of them is the same as the one specified in the input string. The only supported move type right now is MOVE_TYPE_XY, since it is the most straightforward, but more move types will follow. [81c5de76d432] * doc/TODO, src/ai/classic.cpp, src/application/manager, src/application/manager.cpp, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/legal.cpp, src/game/board/pawn.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/board/square, src/game/board/square.cpp, src/game/manager.cpp, src/game/moveparser.cpp, src/utils: Finish migration to the new architecture. This is a big commit. The whole architecture has been modified so that MoveParser really does only parsing, and the legality stuff is done inside the Board class. This implied to re-adjust the whole application, so that legality, action performing and general things were done in different places. Also added small optimizations and removed unnecessary functions. Now it is possible to play a match human vs human, since the check mate is implemented. However, all these new features are really untested and I will need some time in order to get it working properly. Moreover, please note that MoveParser is a new born, and hence it does not recognize almost any type of move, but the MOVE_XY ones. Good night :) [580466072b48] 2009-06-27 Claudio M. Camacho * doc/TODO, src/ai/classic, src/ai/classic.cpp, src/application/manager.cpp, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/legal.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp: Split Board functionality into board, action and legal. Right now, the architecture migration is going on and I decided to split the Board code into three different parts. First, board.cpp contains the general functionality, such as getPieces, etcetera. legal.cpp contains the legality-related functions, and action.cpp has the functionality for applying a move, undoing a move, setting a piece, removing a piece, etcetera. The source compiles but it doesn't work right now, since there are many features not implemented in legal.cpp and the program crashes at the beginning. [7a7d423b7b1d] 2009-06-26 Claudio M. Camacho * doc/TODO, src/ai/classic.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/moveparser, src/game/potential_move, src/game/potential_move.cpp: Erase PotentialMove and prepare for the new architecture. The new architecture will be a massive change in the code, seeking for separating the legality check and the move parsing once and for all. MoveParser was doing both things until certain extent. However, as the project grew, I noticed that the code is not maintenable, and hence I decided (after some deliveration with C2H5OH and Tito Houzy) to separate the legality check and the move parsing itself. All the legality will be incorporated to the Board class. The Board class will have a new method named Board::getAllValidMoves(), which will return a list of all valid moves for a color. Later, the MoveParser simply will have to try to match a given string to all the moves in the list, thus picking the right one or giving the corresponding error message. [15538d85d48b] 2009-06-23 Claudio M. Camacho * doc/TODO, src/ChangeLog, src/application/manager.cpp, src/utils: Fix a problem with unmap(). unmap() was using a constructor for string that allocated values that did not exist in the memory anymore. As this is fixed, getAllMoves() now works very nice. I have tested several matches and getAllMoves() seems to generate every move quite nicely. So, finally, it is time to implement the check mate. [463611c43a7c] 2009-06-21 Claudio M. Camacho * doc/TODO, src/ChangeLog, src/application/cmdparser.cpp, src/application/manager.cpp, src/definitions, src/game/board/king.cpp: Add castle_short and castle_long to King::getAllMoves(). Now the ::getAllMoves() interface is finished, but it probably will need polishing and, even more important, optimizing. Also add the following commands: 'auto', 'go' and 'manual'. 'auto' makes the machine take the control over the current board and play until the end (play both sides). 'go' forces the machine to play the current side on moving. 'manual' makes the machine detach itself from the game and the match becomes human versus human. Please note that these commands are there but they do not work yet, until the AI is fully integrated with the ApplicationManager. [b1c0d257ed05] * src/ai/classic, src/ai/classic.cpp, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/moveparser, src/game/moveparser.cpp, src/game/potential_move, src/game/potential_move.cpp, src/utils: Add minimax() and many other improvements. Currently, chess0 is ready for checking the mate (check mate) and using some simple intelligence. However, this is not in use yet, I mean, the tools and necessary components are ready, but they are not integrated. I added a new class, PotentialMove, which can be used in every piece in order to return a list of all possible moves by that piece. This can be used both for the AI engine and for checking the mate, since all the moves must be checked before finalizing the match. [dd670e928962] * src/ai/classic, src/ai/classic.cpp, src/game/board/board, src/game/board/board.cpp, src/game/move, src/game/move.cpp: Add basic structures for classic AI, nothing functional yet. [87dd886cd805] * doc/TODO, src/application/cmdparser.cpp, src/application/manager, src/application/manager.cpp, src/definitions: Add command 'nodes' to perform evaluation tests. This command executes a performance test and tells the user how many nodes can be evaluated per second. Thanks to this, I discovered that evalAttacks() and evalMobility() are really costy, and hence they will be optimized in the future. Currently, chess0 only evaluates ~6Knps on a 2.26GHz core (single core CPU). However, disabling attacks and mobility, it can evaluate more than 150Knps. [cb0bc4165132] * src/application/manager.cpp, src/game/board/board.cpp, src/game/game.cpp: Cursor should be set to 0 in Game::restart(). I tested all the regression tests with undo() and back(). The purpose was to unroll the whole match and play it again, then unroll it and play it once again, and so forth. The result is very nice, nothing crashes, so, for now, chess0 is quite stable. The only problem was when restarting a match, because cursor was set to 1, instead of 0, and hence this could lead to potential crashes in rare situations. Now the cursor is consistent and chess0 is more stable than before :-) [5fa4108ea6b9] * src/ChangeLog, src/game/board/board.cpp, src/game/moveparser.cpp: Fix last major bug in updateLists(). Finally, I fixed a major bug that has been around since the dawn of age. In any move, and in captures in general, when a piece of a color is set on a square, that bit is set in the bitboards for that player, but it also _has_ _always_ to be cleared from the opponent's bitboard. Now, all tests are passed without any problem (001 .. 005). Next step, automate testing and implement check mate :-) [344713bfe3df] * src/application/cmdparser.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/board.cpp, src/game/game, src/game/manager, src/game/manager.cpp, src/game/moveparser.cpp, src/utils.cpp, tests/005.orig, tests/efficiency_bitboards.cpp, tests/efficiency_bitsets.cpp, tests/test_bitboards.cpp: Fix critical bug in updateLists() and add minor improvements. First of all, there was a critical bug in Board::updateLists(), due to the conversion of the API (new Piece::getPos()). This fixes many regressions and makes games go further. However, there is a hidden bug (still not fixed), where the pieces' bitboards are not properly updated, but I'm working on it right now. Second, I already introduced the set of commands for letting a player to play a match. These commands are: abort, draw and resign. See help in the program, for more details. Then, I also added two commands for configuring verbosity. They do not much right now, but you can already set the application to display the board in every move (command 'verbose') or not (command 'quiet'). The program is verbose by default, and the non-verbose option is to help with the testing outputs. Added a new regression test (tests/005.orig) and three small test programs to test bitboards functionality (they proved that everything is working until now) and their performance, compared to C++-native bitsets (bitboards kick ass). Moreover, utils.cpp now can display bitboards in a human-readable way, the same way a normal board is displayed, but using 0s and 1s instead. Some castings have been converted to static_cast<&T>, for accordance reasons. Last, MoveParser now really updates everything in a candidate before estimating who can move and who cannot to a given position. Before, it just recalculated the moves on a piece, but this was not enough, since many pieces have an optimization where the attacks are not recalculated every time. So now, explicitly recalculate moves and attacks before judging the candidate. [7097609bcb93] * src/ChangeLog, tests/001.orig, tests/001.txt, tests/002.orig, tests/002.txt, tests/003.orig, tests/003.txt, tests/004.orig, tests/004.txt: Rename tests to .orig. This is the beginning of the regression tests architecture. Later on, I will create the corresponding .result files with the good result, and a script to compare the current output of the program with the proper result, thus determining if the test has been passed or not. [c774098a336e] * src/ai/eval.cpp, src/application/manager.cpp, src/game/board/board.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/move.cpp, src/game/moveparser.cpp, tests/001.txt, tests/002.txt, tests/003.txt, tests/004.txt: Improve doMove() and undoMove(). The code in doMove() and undoMove() is now much cleaner and efficient. Furthermore, many regressions have been fixed in this commit. Please notice that I added a directory with the regression test files, although there is not any automated tool yet to check these tests. Hence, they must be performed manually. [c6daeee144f0] 2009-06-20 Claudio M. Camacho * src/ChangeLog, src/game/board/board.cpp, src/game/moveparser.cpp: Fix a major bug in undoPromotion(). [657eb7542901] * doc/TODO, src/application/manager.cpp, src/game/board/board.cpp, src/game/moveparser.cpp: Implement on-the-move checks. Now, it should not be possible to castle if a piece is threating a middle square where the king or the rook have to cross for castling. [4e9f9a3266d1] * doc/TODO, src/application/manager.cpp, src/game/board/board, src/game/board/board.cpp, src/game/game.cpp, src/game/move, src/game/move.cpp, src/game/moveparser.cpp: Add support for check and X-ray check. This is a every important commit. First, checks are working, and chess0 won't allow any move that is not valid according to the check rules. Futhermore, X-ray checks are implemented nicely, not allowing pieces to move if they are pinned. I also updated the TODO, see that now the mandatory features for 0.1 are almost done. Next steps are the check mate and the on-the-move check (for castling). [4b5a43262c4f] * src/application/manager.cpp, src/game/board/board, src/game/board/board.cpp, src/game/game.cpp: Support '+' symbol both at input and in the game history. [79524da736b1] * src/game/game, src/game/game.cpp, src/game/manager.cpp: Fix a problem in the history (GameManager). [610cc0ec94c0] * src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/game, src/game/game.cpp, src/game/manager.cpp: Add simple check support. Now the king is detected in the check, but still nothing is done about it. [f8a0d523590e] * src/application/prompt, src/application/prompt.cpp: Forot to add the Prompt files, of course. [19017eb5e4f0] * src/application/manager.cpp, src/ui/err, src/ui/err.cpp, src/ui/input, src/ui/input.cpp, src/ui/output, src/ui/output.cpp, src/ui/ui, src/ui/ui.cpp: Remove UI.* classes in favor of application/prompt. [0f7c8a9b142f] * doc/TODO, src/ChangeLog, src/game/board/board.cpp, src/game/board/queen.cpp, src/game/moveparser.cpp: Fix non-promoting captures on row 1 and 8. [ba56a96b9fa2] * doc/TODO, src/ai/eval.cpp, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/moveparser.cpp: Improve move handling a lot. Change the whole infrastructure of how a move is performed. Now, the code for doMove() and undoMove() is much simplier and well structured. Many unnecessary calls were removed and the code has been split into different logical parts, such as doCapture()/undoCapture(), doCastle()/undoCastle(), doPromotion()/undoPromotion(), etcetera. [9806dd48372b] 2009-06-19 Claudio M. Camacho * src/game/board/board.cpp: Fix wrong shift in doCastle(). Reported by Tito Houzy. [b07e7f34d262] * src/game/board/queen.cpp: Fix recalculateMoves() in Queen. Reported by Tito Houzy. There was the move to the east that was not calculated properly (damm copy & paste). [ef27e21c6282] * src/ChangeLog, src/game/moveparser.cpp: Fix ambiguity in translateCapturePawn(). Reported by Tito Houzy. Before, only bitboards where checked against the victim, without actually caring if the capturing pawn is specified to be in a given column. So both pawns from different columns that attacked the same square could be possible candidates. Fix this behavior. [995b6e360fd1] * src/ChangeLog, src/game/board/board, src/game/board/board.cpp: Add full support for promotions. The code is quite experimental, and many errors will follow. However, I will dedicate now some hours to debug and fix all the errors until now. Once all the errors have gone, the next step is to finalize the chess rules by adding check, mage and X-ray checks. [7b43313cff7f] * doc/TODO, src/application/manager.cpp, src/game/board/board, src/game/board/board.cpp, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser.cpp: Initial support for promotions. Now there are three new moves that can be passed to chess0: e8=Q exd=Q exd8=Q These three types of move define the promotions. They are quite unstable and undoMove() will not work with any of them. But these are the initial bits. [316a61e1360d] * doc/SEQUENCES, src/game/manager, src/game/manager.cpp, src/utils: Handle a couple of error codes. Handle error codes when navigating back in an empty history game or when displaying a non-running game's history. [11bba596bed4] * src/application/cmdparser.cpp, src/game/board/bishop.cpp, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/board/square, src/game/board/square.cpp: Undo command finalized. Now undo is totally functional. There might be some minor details, but this will be fixed as soon as a bug is reported. [695e34e72432] * doc/TODO, src/application/cmdparser.cpp, src/application/manager.cpp, src/definitions, src/game/board/board.cpp, src/game/board/piece.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp, src/ui/err, src/ui/err.cpp, src/ui/error, src/ui/error.cpp, src/ui/ui, src/ui/ui.cpp: Initial support for the command 'undo'. Add support for 'undo', althought it has many errors still. Also remove 'next', since it provokes inconsistencies in the game history and corrupts the whole game. Moreover, this type of command is not implemented in common chess engines, so I guess it is not necessary to spend all the time there. Add some background for the coming-up promotion moves, still translation is not implemented. [febd6d996739] * doc/TODO, src/application/cmdparser.cpp, src/application/manager.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp: Implement command 'restart', requested by Tito Houzy. The command restart is able to restore a match to the initial point, that is, the initial board with the white turn. [50261abf6361] * doc/TODO, src/application/manager.cpp: Update help and make possible O-O (o-letter). Feature request by Tito Houzy. Now it is possible to use O-O instead of 0-0 (zero-zero), for short castling. Also update the help and introduce three new commands: back/next/restart. However, they are not implemented yet. [1c7f737685f4] * doc/TODO, src/application/manager.cpp: Fix typo. [de8a750ed230] * src/ChangeLog: Forgot: the previous commit was fixed thanks to Tito Houzy. Also update the src/ChangeLog. Good night! [933c01a16575] * src/ChangeLog, src/game/moveparser.cpp: Fix a crash in MOVE_TYPE_XY. The orig and dest variables are not set when MOVE_TYPE_XY is evaluated, and it needs to know orig and dest before hand. Calculate these variables before accessing the board in order to solve the problem. [8a1737c0049e] 2009-06-14 Claudio M. Camacho * src/ai/eval, src/ai/eval.cpp, src/application/command, src/application/command.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/game, src/game/game.cpp, src/utils, src/utils.cpp: Refactor the whole code, put get/set methods as inlines. [7299774d5dd6] * doc/SEQUENCES, doc/TODO, src/ai/eval.cpp, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser.cpp: Implement empassants. Use empassants. Now the code is much more complex, since empassants introduce a lot of changes into the general rules of chess. Please notice that empassants are, for now, fully supported, according to the different types of pawn capture moves. [a28b67ea2d3c] * doc/TODO, src/main.cpp, src/utils: Added new debugging interface (thanks to C2H5OH). The interface is specified in the following files: - http://www.krenel.net/priv/nnvect/file/b373227d2542/util.h - http://www.krenel.net/priv/nnvect/file/b373227d2542/util.c This interface is not yet used anywhere. However, the application should be soon migrated to this infrasctructure and all new debug messages should go in accordance with this new interface. [e428eb3b23c8] * doc/TODO, src/game/moveparser.cpp: Implement translateCaptureSimpleShort(). It was actually easy to implement it, as it is almost a copy from translateCapturePawnShort(). Now the algebraic-translation support is almost done, with the exception of the promotions (e.g. d8=Q). The next step is to implement check and mate, which is not a piece of cake. [4bcc435c5ebc] * doc/TODO, src/ai/eval.cpp, src/application/cmdparser.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/move.cpp, src/game/moveparser.cpp: Implement translateCapturePawnShort(). Implemented one of the last move translations, and improve recalculateMoves() for pawns that have not been moved. [e8a1b1a60333] * src/ai/eval.cpp, src/game/board/bishop.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp: Improve recalculate moves for Knight and King, refine heuristic. Add improvements to recalculateMoves() in Knight and King. The function is no longer for pseudo-legal, but it actually retrieves a pretty accurate list of valid moves. This decisions comes from the approaching of the minimax algorithm, since we will eventually need the list of only-valid moves. Also refine the heuristic function, which is now much more accurate, thanks to the new mobility improvements. [0b206b0b01ba] * src/game/board/board.cpp, src/game/manager.cpp: Fix doMove() and removePiece(). doMove() now seems functional, and it is used, for its first time, in the GameManager, in order to perform generic moves. [f1677365fa8d] * doc/TODO, src/game/board/board, src/game/board/board.cpp, src/game/move, src/game/move.cpp: Add doMove()/undoMove() interface to Board. Thanks to this interface, the implementation of the minimax function will be easier, since the program will have only one board, and moves will be done and undone to that boad, through the tree. Due to this interface, I had to add certain modifications to Move and a list of removed_pieces, so that pieces can actually be restored to the board with undoMove(), when the move was a killer one. [88345de5c93c] 2009-06-13 Claudio M. Camacho * doc/TODO, src/ai/eval, src/ai/eval.cpp, src/application/manager.cpp, src/utils: Implement evalAttacks() and evalMobility(). The heuristic function is now more refined. It uses the new evalAttacks() and evalMobility() methods. However, these are only in draft version, since they include several mistakes, such as calculating the number of pseudo-legal moves, and not the real ones. Also, remove evalDefense(), since it doesn't seem to be very necessary in the near future. [7f9878c692fb] * doc/TODO, src/ai/eval.cpp, src/application/cmdparser.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/main.cpp: Move application logic to ApplicationManager. The main() function now is totally dummy, which is way better than before. All the tasks are delegated to the ApplicationManager, and it now uses, internally, all the UI components, Game components, etcetera. Moreover, the heuristic funcion is getting some shape. Now it really accounts for material and the normalization of the formula to combine position and material is more polished. [4e1f724d086f] 2009-06-12 Claudio M. Camacho * doc/TODO, src/ChangeLog, src/ai/eval, src/ai/eval.cpp, src/definitions, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/board/square, src/game/board/square.cpp, src/main.cpp, src/utils, src/utils.cpp: Add initial support for heuristic calculations. Improve the Eval class so that it includes several methods for calculating different heuristic estimates, including: evalAttacks() evalDefense() evalMaterial() evalMobility() evalPosition Only evalMaterial() and evalPosition() are actually implemented. However, they do not include a finalized code, but just a draft of what is coming up. Furthermore, there is a general function named eval() which uses all the auxiliar functions listed above and creates a weighted mean of the current board. This is the place where the heuristic formula goes. Added values to pieces (using default values as VALUE_XXX, where XXX is the piece) and assign different values to different squares. Central squares are more valuable than outsiders. Please notice that this is only an initial version, and both white and black play for the center at all moments. This behaviour should change in the future, since in the middle-game the value for the squares is determined by the position of the opponent's king. Also updated TODO and improve certain parts of the code. We are back ;-) [6d436ff878f5] 2009-01-20 Claudio M. Camacho * src/game/moveparser.cpp: Fix a redefinition of translateCaptureSimple in MoveParser. [ccb3390a602a] * doc/TODO, src/application/manager.cpp, src/definitions, src/game/moveparser, src/game/moveparser.cpp: Initial code base for new moves such as CapturePawnShort and CaptureSimpleShort. [b6e7cee3fbd1] * src/application/manager.cpp, src/game/moveparser.cpp: Implement translateCaptureLong. [eff822045d4c] 2009-01-19 Claudio M. Camacho * doc/TODO, src/application/manager.cpp, src/game/moveparser.cpp, src/utils, src/utils.cpp: Implement translateAmbiguous. [3713e309819e] * Doxyfile, Makefile, src/ChangeLog, src/ai/eval, src/ai/eval.cpp, src/application/cmdparser, src/application/cmdparser.cpp, src/application/command, src/application/command.cpp, src/application/manager, src/application/manager.cpp, src/application/settings, src/application/settings.cpp, src/definitions, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/board/square, src/game/board/square.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp, src/main.cpp, src/ui/error, src/ui/error.cpp, src/ui/input, src/ui/input.cpp, src/ui/output, src/ui/output.cpp, src/ui/ui, src/ui/ui.cpp, src/utils, src/utils.cpp: Add all the missing comments to improve doxygen output. Add @file to all the files, comment main.cpp and utils.cpp, and fix the missing methods that had wrong documentation or a missing command. [13eccef31506] 2009-01-18 Claudio M. Camacho * Makefile, doc/SEQUENCES, doc/TODO, src/ai/eval, src/ai/eval.cpp, src/application/cmdparser.cpp, src/application/manager.cpp, src/definitions, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/moveparser.cpp, src/main.cpp, src/utils.cpp: Implement capturePawn and captureSimple, many bug-fixes and improvements. Again a long commit, mainly adding support for translateCapturePawn and translateCaptureSimple, which means that chess0 checks now the legality of taking pieces with other pieces or pawns. Please read below for a full list of changes: 1) Added first bytes in ai/ with a new class Evaluator, which is only (for now) capable of evaluating board's material) 2) Added a SEQUENCES file in doc/ where I will put any move sequence that generates an error or a failure in the program and how could it possibly be fixed. 3) Updated TODO 4) Add new command 'material' for displaying the current board's material evaluation. 5) Board has no longer a set of 64 pieces with 0 for blanks, but instead use a vector where all the 32 pieces are entered at the beginning and then they are being deleted when they are taken from the board. 6) Fix a bug in all major pieces constructor, where all were intialized with pawn code. 7) Implement recalculateAttacks() for pawns, which is necessary for translateCapturePawn. 8) Assign material values to pieces up on construction and implement their respective get/setValue() (used by Evaluator::evalMaterial). Next step will be implementing the two move types left and starting with testing check conditions before applying a move. [d4125ec3c4b2] 2009-01-15 Claudio M. Camacho * doc/TODO, src/game/board/board.cpp, src/game/board/piece.cpp, src/game/board/rook.cpp, src/game/manager.cpp, src/game/move.cpp, src/game/moveparser.cpp: Finish translateCastleShort, implement translateCastleLong and translateXY. This commit is quite important. First, translateCastleShort() has been completed, meaning that now both sides can castle on the short side with no errors (except for the in-the-way check, that is not considered yet). Further, translateCastleLong() has been implemented using the same logic flow found in translateCastleShort, but adding the check for another more piece in the middle. Second, translateXY() has been implemented, which has been almost trivial. Probably this methods needs further testing, but it seems to work for now. Additionally, some other changes have taken place. For instance, the Rook code has been improved, since there was a tiny error that didn't provide the right moves to the left (horizontal displacement), but now it's fixed. Another change is that now chess0 can read lower-letter pieces on moves, such as bc4, re1 and so on. This change was also trivial. Last, a couple of improvements have been introduced. Basically, the Board::setPiece() method is no more bounded to Piece::setPosition(). This avoids a double call to Piece::setPosition(), but it is important that all the code sets the position of a piece independently from the Board set. This means that, although the Board is modified at a certain square, the piece has to be explicitly told (separately from this function) that it has been moved to another position (using Piece::setPosition() or Piece::update()). The next step would then be to implement all the capturing moves. Where the last move type to implement would be translateAmbiguous, since it is the most complex (presumably). [91f237c76802] * doc/TODO, src/game/board/board.cpp, src/game/board/king.cpp, src/game/manager.cpp, src/game/moveparser.cpp: First translateCastleShort() bits. First modifications towards short-castling. However, there is very dirty code and the program segfaults on a valid 0-0 input (note that invalid 0-0 are intercepted and reported back to the user). [43335d327929] 2009-01-12 Claudio M. Camacho * doc/TODO: Update TODO. [a918f467be33] * doc/TODO, src/game/board/bishop.cpp, src/game/board/empty, src/game/board/empty.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp: Finnish Rook and Queen logic, including slide-blocking pieces (obstacles). Fix minor details in Bishop and implement Rook and Queen, which are not finalized. Also remove the Empty class and conclude translateSimple(). Next step is to implement translateCastleShort, translateCastleLong and translateXY. [c6687d53c6b5] * doc/TODO, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/empty, src/game/board/empty.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/manager.cpp, src/game/moveparser.cpp: Fix bishop moving with obstacles checking. Add some optimizations. The first sliding piece that can move without going over obstacles is the bishop. For this commit, some important changes had to be made to the infrastructure, so that checking wasn't painful. The first optimization was to remove the use of Empty (the class still exists in the repository but it will be deprecated). This design is now uglier, but much faster (and less memory consuming), since we do not create 64 objects but just 32, and every check is against 0 (NULL) and not an object call. Second, every Piece::getType() in the code was remodelled so that it wouldn't hurt the new philosophy. From now on, we first get the piece pointer and check if it is 0. If it is 0, then this is an empty square, otherwise, we can use that pointer to retrieve further information (since the piece exists). Now, there is a performance problem when it comes to recalculating the pieces moves. For instance, when a pawn moves, all the pieces that where pointing to its place should update their moves, since they can now moves to that square or even beyond. However, updating every single piece at every move would be too expensive. The solution was to perform a piece moves update only when we are about to translate a move for that piece. That is, before checking if a move is legal or not for a given piece P, we first call P->recalculateMoves() and then we move if it is in place. Last, some changes were made to the bishop, actually some corrections. Next step would then be to apply the same ideas to the Rook and Queen, so that all the translateSimple() can be performed properly, even with sliding pieces. [4fadd9b076b2] 2009-01-04 Claudio M. Camacho * doc/TODO, src/game/move, src/game/move.cpp, src/game/moveparser.cpp, src/main.cpp: Finnish move ambiguity. Now, chess0 can detect ambiguous moves (several candidates of the same type to the same destination) and pass a message back to the higher levels. Then, the main loop is in charged of passing this message to the UI to report the user about the ambiguity of the move. [85266ca135fc] * src/game/board/knight.cpp, src/game/board/queen.cpp: Refine the logic of the Knight, avoid wrapping in move generation. This commit is self-explanatory. [8037c17a2645] * doc/TODO, src/game/board/bishop.cpp, src/game/board/king.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp: Fix behavior for King, Queen, Bishop and Rook. This commits refines the code for King, Queen, Bishop and Rook by introducing wrappingless moves generation. [7a34c41f2e08] * doc/BOARD, doc/README, doc/TODO, src/definitions, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/moveparser.cpp, src/utils.cpp: Initial support for translateSimple() and improvements. First, it is important to say that chess0 already can parse simple moves (such as Nd4, Bc5, etcetera). It is not fully functional though, since many aspects are missing, such as X-ray moving for sliding pieces, discovered-check to the king, or ambiguous moves. Therefore, the next steps should follow: 1) Check that every minor/major piece can generate good pseudo-legal moves even when placed at the border of the board 2) Check if a move is ambiguous, report it properly and tell the user that the move is ambiguous and it cannot be performed 3) Avoid the possibility of X-ray moving for sliding pieces, which right now move as if no piece was in their way 4) Check that a move does not discover the king against a direct attack (which was a X-ray attack, and now is a discovered-check) After these steps are completed, translatePawn() and translateSimple() should be perfect, and next move types could be taken into consideration. This commit also adds support for a better King code, where check, hang and mate are inside the class (with data members and their respective get/set methods). This allows the program to avoid using many different constants as piece types, leaving only the ones that are trully necessary, which is a combination of the piece type and its color, without contemplating if it is moved, nonmoved, and so forth. Another change was the assumption that attacks is recalculated for moves. This means that, now, when recalculating attacks, recalculateMoves() is not called anymore. This speeds up the program by a 50% any time a piece is moved. Please note, that recalculateMoves() should, therefore, be always called before recalculateAttacks(), since the latter just copies moves to attacks. Addtionally, this commit has improved the code in MoveParser, simplifying the way to get piece candidates to move from a square to another (in seek of ambiguous move specifications). Now the code is much more compact, using only candidates = b->getPieces(PieceType), which removes quite many function calls from utils (previously I was converting from positions to BitBoard and from BitBoard to positions). In this commit, also due to the fact that now MoveParser is more efficient, white_pawns and black_pawns structures are not used anymore. However, these will be used, along other piece structures, in the future for other possible legality checks and board evaluations (AI), so this code has not been removed and the lists in the Board are constantly updated, although they are not used at all at this stage. Besides, some minor bugs were corrected (Knight now generates better moves) and other things were re-adjusted to the new changes. Please check out this version, which is much more enterteining, since it allows the user to move any piece. [3087c1cc7778] 2009-01-03 Claudio M. Camacho * doc/TODO, src/game/board/board, src/game/board/board.cpp, src/game/board/empty.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/manager.cpp, src/game/moveparser.cpp, src/utils, src/utils.cpp: Finnish translatePawn() code, improve overall behavior and fix many bugs. This commit could be considered a milestone. First, it adds, for the first time, support for translating a whole type of moves (translatePawn()), where pawns can now legally move (except for captures and promotions). In the meantime, many architectural assumptions have been engineered. For instance, the Board now has two BitBoards with the structures of white pawns and black pawns which are updated on every pawn move. Also, Piece has now a complete method for updating internal information of the piece (Piece::update()), which calls indeed Piece::recalculateMoves() and Piece::recalculateAttacks() according to the new position of the piece on the board. The new functions on the utility file are one for setting a certain bit on a given BitBoard and another one for resetting, which helps the program when updating BitBoards of any kind (reset the old position of the moved piece and set the bit of the position where the piece is now). Finally, BitBoard operations seem to work at a basic level. Next step is to develop translateSimple(), where BitBoards should be used slightly more extensively, and that will bring more robustness to the whole program's architecture. [08bd6bf04e63] * src/game/board/bishop.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/manager.cpp, src/game/moveparser.cpp, src/utils, src/utils.cpp: Optimize utils.cpp and improve translatePawn(). This commit is a half-way improvement over translatePawn(), where the BitBoard operations now work properly in many cases, but there are some cases left out where the pieces do not move correctly. This is probably due to the lists-updating, which is not yet performed upon move performing. Thanks to C2H5OH, utils.cpp now has been further optimized and operations are done in a simpler and faster manner. [bca3f53abf43] * Makefile, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king.cpp, src/game/board/knight.cpp, src/game/board/pawn.cpp, src/game/board/queen.cpp, src/game/board/rook.cpp, src/game/game, src/game/game.cpp, src/game/manager.cpp, src/game/moveparser, src/game/moveparser.cpp, src/utils, src/utils.cpp: Improve BitBoard implementations and start using BitBoard operations. Many changes are included in this commit. Unfortunately, the program is still under strange behavior, but things are moving forward. utils.cpp has been updated and it now has a faster implementation of many functions, as well as code fixes for BitBoardFromPositions(), which now works perfectly. Another important fix was piece creation on startup, which was totally broken, but now it works properly and all the piece objects are created as they should. Finally, the translatePawn() is near completion, however the recalculateMoves() and the BitBoards containing the moves and attacks are not precise, and hence bitboarding doesn't work, since the BitBoard with the moves of the pawns is incorrect (e.g. it generates candidates from upper bits in the board when trying to move 1.e4, where it should generate an only candidate from e2). [8247a2304c67] 2009-01-02 Claudio M. Camacho * src/application/manager.cpp, src/definitions, src/game/moveparser.cpp: Fix a part of move validation. Now moves are accepted properly, however board updating is still broken in many cases. [6c475a48113c] * src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/empty, src/game/board/empty.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/board/square.cpp, src/game/moveparser.cpp, src/utils, src/utils.cpp: Fix board representation for BitBoards and introduce recalculateAttacs(). As from the previous commit, the board representation was broken, due to an incorrect formula for retrieving the piece char at different squares. This has been now fixed. Furthermore, introduced recalculateAttacks() as a new method for setting the BitBoard where a piece can reach (attack), which actually coincide with the moves BitBoard for minor and major pieces. Nevertheless, pawns must implement a totally different recalculateAttacks() method, which is based on diagonal taking and should take in account the enpassant taking. Please notice that move validation is still broken, but I'm working on it. [3bec9e9e8498] 2009-01-01 Claudio M. Camacho * Makefile, doc/TODO, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/empty, src/game/board/empty.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/board/square, src/game/board/square.cpp, src/game/game, src/game/game.cpp, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp, src/main.cpp, src/ui/error, src/ui/error.cpp, src/ui/input, src/ui/input.cpp, src/ui/output, src/ui/output.cpp, src/ui/ui, src/ui/ui.cpp, src/utils, src/utils.cpp: Redesign board to use BitBoard operations everywhere. Add an utils.cpp file with typicall operations which do not change the state of any object (such as isColumn(), isRow(), etcetera). Also represent the list of squares as a flat array (1-dimensional) of 64 slots, one for each square. Create a bidirectional association between squares and pieces (one piece has a pointer to its square, and one square has a pointer to its piece). Clean up a lot of code, reducing the number of lines for implementing previous functionalities. Fix a segmentation fault on quit (although I think this was fixed in a previous commit). Some bugs have entered, however, in this version. For instance, move parsing is broken and displaying the board is incorrect. Hopefully this get fixed in the next commit. Happy New Year 2009! [b276525213a5] 2008-12-29 Claudio M. Camacho * Makefile: Improve automatic generation of dependencies in Makefile (patch by C2H5OH). Dependencies now are also generated fro .dbo and .obj object files. Besides, auto-dependencies may be disabled for several targets, such as clean, help and deinstall. [de94acbbdfbe] * doc/TODO, src/application/cmdparser, src/application/cmdparser.cpp, src/application/command, src/application/command.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/board/square, src/game/board/square.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/game/moveparser, src/game/moveparser.cpp, src/main.cpp, src/parser/cmdparser, src/parser/cmdparser.cpp, src/parser/moveparser, src/parser/moveparser.cpp, src/parser/parser, src/parser/parser.cpp, src/ui/ui, src/ui/ui.cpp: Move code from Parser to ApplicationManager and GameManager. This is a slight re-design of the whole program, where the parser code is removed in favor of a better distributed interconnection between the ApplicationManager and the GameManager. Logically, now MoveParser is inside the GameManager, and so it can easily use the Game and Board facilities, without importing a pointer to another subsystem (as it was done before). On the other hand, CmdParser is now part of ApplicationManager, which is also more logical and we can hence remove all the bytes from Parser. Thus having a cleaner and more simplistic implementation. Also fix compilation problems generated when modifying the Makefile for generating automatic dependency files (see previous commit). [197c03bae5ef] 2008-12-28 Claudio M. Camacho * Makefile: Add support for automatic dependencies generation in the Makefile (thanks to C2H5OH). [b90ac1e62cf8] 2008-12-25 Claudio M. Camacho * doc/TODO, src/application/manager.cpp, src/definitions, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/parser/cmdparser.cpp, src/parser/moveparser.cpp: Add history support and the command 'history' for using it. This commit adds initial support for game history, which is saved in a stack of moves and it provides a way for adding and removing moves to and from it. This way, now we can keep track of theh moves on an ongoing game and then list them using a command (currently using the 'history' command). Further, this functionality can be used for tacking moves back, for any analysis purpose that might be used in the future. [506e6e3c504b] * doc/TODO, src/application/manager, src/application/manager.cpp, src/definitions, src/game/move, src/game/move.cpp, src/main.cpp, src/parser/moveparser, src/parser/moveparser.cpp, src/parser/parser.cpp: New work breakdown inside MoveParser aiming for flexibility. Now MoveParser has many different private methods for translating different moves, according to their different types. Each function (private method inside MoveParser) is in charge of translating one type of move. So far, the only private method working is translatePawn, which has the code that used to have the whole translate() method inside MoveParser. Next step is to develop move translation for each type of move. Also notice that a new type of move has been added (MOVE_TYPE_CAPTURE_PAWN), which is similar to capture simple, but the first character must be a column (e.g. exd4, instead of Nxd4). Additionally, the main program now prints also the type of move involved in each turn (for a better registry of information). Furthermore, this commit adds an improvement in the Move class with the field 'valid', which is supposed to be in sync with MOVE_TYPE_[VALID|INVALID]. Last, some improvements were made to the pawn move code, and now the pawn moves are much more robust, meaning that cheating is more difficult. [173174042b5e] * doc/TODO, src/game/move, src/game/move.cpp, src/main.cpp, src/parser/moveparser.cpp: Mark pawn moving as functional (not capture). This commit add stability fixes to the pawn moving code. In principle, pawns can be moved with the shortest specification (e.g. e4, d4, etc). Please, notice that capturing is not intercepted as it should be always denoted by a 'x' (MOVE_TYPE_CAPTURE_). Also, the next board is not estimated, and hence a discovered check to the king is not forseen. This should be implemented in the near future by creating an infrastructure of creating temporary boards which may be checked on the fly. Finally, a small print out has been added to the main program in order to probe that MoveParser does its job. In fact, MoveParser is the first component to be working before proceeding with any further development, such as AI or basic game management (like checking, check-mating, etcetera). [3cb148dbd097] 2008-12-24 Claudio M. Camacho * doc/TODO, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/main.cpp, src/parser/moveparser, src/parser/moveparser.cpp, src/parser/parser, src/parser/parser.cpp, src/ui/ui, src/ui/ui.cpp: Initial work in pawn moves and board updates. Currently, the game already starts with the White() prompt, including the turn number. This way, two human players (by now) can enter moves into the program and the program should be able to update the board. So far, the code only works for updating the board when entering pawn-type moves (e.g. e4, d4, d6, etc). However, the update of the board doesn't work properly and the validity of these moves is not proper, since an initial e5 can be played from the white side, so this must be checked next. Merry XMAS all!!!! [ca51424f464d] 2008-12-21 Claudio M. Camacho * src/application/command, src/application/command.cpp, src/application/manager, src/application/manager.cpp, src/definitions, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/game/move, src/game/move.cpp, src/main.cpp, src/parser/cmdparser, src/parser/cmdparser.cpp, src/parser/moveparser, src/parser/moveparser.cpp, src/parser/parser, src/parser/parser.cpp: Add Move and Command classes, which intend to improve the flexibility and maintainability of the project. The Move object contains, by now, the initial and final coordinates of a movement, as well as a type entry for describing or grouping the type of move. The Command object has a similar goal, however it is implemented in the Application side. The Command object contains a command name, a type description and a variable list of arguments, which may ease the development towards command line flexiblity (see UI). On the other side, although the whole program has been adapted to use the new Command and Move components, there is a need for creating a more flexible architecture. [d2bcf38f7791] 2008-12-20 Claudio M. Camacho * doc/TODO, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/main.cpp, src/parser/cmdparser, src/parser/cmdparser.cpp, src/parser/parser, src/parser/parser.cpp: Add support for displaying the internal representation of the board. This commit is trivial. It only adds a special method to Board, where the internal representation of the board may be displayed, which aims for debug goals only. A new BOARD_TYPE has been added, so that multiple representations can be called from Board, returning different string-based representations for further debug purposes. The next step is to implement getMoves(), which should return a list of all moves for a piece, without taking in account if a move is valid or not. Further ideas, while developing getMoves(), shall be focused on creating the flexible command architecture, which will probably lead to create a new class Command, including a portable and flexible way to create commands with multiple arguments and a functionality to manipulate those commands. Right now we are only using an 'enum' (CMD_TYPE) for manipulation, which is quite poor and results in headaches when creating clean code. [e145eb028d72] 2008-12-14 Claudio M. Camacho * doc/BOARD, doc/README, doc/TODO, src/application/manager, src/application/manager.cpp, src/definitions, src/main.cpp, src/parser/cmdparser.cpp, src/parser/parser, src/parser/parser.cpp: Add some bytes to the movement checker. Add a better support for checking different types of moves, depending on their length. Now, there is a definition of four different types of moves: pawn move (column + row), move piece simple (piece + column|row + column|row), move origin destination (column_orig + row_orig + column_dest + row_dest) and move ambiguous (piece + column|row + column + row). Please notice that 0-0 (short-castle) and 0-0-0 (long-castle) are still not understood as valid moves. Also add initial support for displaying help (CmdParser and ApplicationManager). [3f1d485193f5] 2008-11-16 Claudio M. Camacho * Makefile, src/application/manager, src/application/manager.cpp, src/definitions, src/game/board/board, src/game/board/board.cpp, src/game/board/square, src/game/board/square.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/main.cpp, src/parser/cmdparser.cpp: Board display support and Win32 compilation support. This commit adds support for representing and displaying the current board through all the class hierarchy. Also add support for compiling chess0 for Win32 platforms (tested and OKed on Windows XP). [6db655e3944b] 2008-11-11 Claudio M. Camacho * Makefile, doc/LICENSE, doc/README, doc/TODO, makedeb.sh, src/application/manager, src/application/manager.cpp, src/application/settings, src/application/settings.cpp, src/definitions, src/game/board/bishop, src/game/board/bishop.cpp, src/game/board/board, src/game/board/board.cpp, src/game/board/king, src/game/board/king.cpp, src/game/board/knight, src/game/board/knight.cpp, src/game/board/pawn, src/game/board/pawn.cpp, src/game/board/piece, src/game/board/piece.cpp, src/game/board/queen, src/game/board/queen.cpp, src/game/board/rook, src/game/board/rook.cpp, src/game/game, src/game/game.cpp, src/game/manager, src/game/manager.cpp, src/main.cpp, src/parser/cmdparser, src/parser/cmdparser.cpp, src/parser/moveparser, src/parser/moveparser.cpp, src/parser/parser, src/parser/parser.cpp, src/ui/error, src/ui/error.cpp, src/ui/input, src/ui/input.cpp, src/ui/output, src/ui/output.cpp, src/ui/ui, src/ui/ui.cpp: Initial commit. Create a set of classes, organized in subdirectories, for further development. The basic user interface and command line processing is ready to be developed in an extensible way. The functional parts are the UI, the parser, the application manager and the game manager. None of them are still working, just exchanging some information for debug purposes. Please check out the files in doc/ for more information about the project. [c2774c0d26d7]