************************************************
* Mediocre v0.33 by Jonatan Pettersson         *
*                                              *
* Homepage: http://mediocrechess.blogspot.com/ *
* E-mail:   mediocrechess@gmail.com            *
*                                              *
* Release date: 2007-05-17                     *
************************************************

------------
Introduction
------------

Mediocre is the result of a chess programming blog (http://mediocrechess.blogspot.com/).
In the blog every aspect added to Mediocre is described in detail as it develops.

Mediocre is written in Java and supports both the WinBoard and UCI protocols.

------------
Installation
------------

Being a Java chess engine Mediocre needs Java Runtime Environment in order to run.
It can be found on http://java.sun.com.

Note: If you do not have the path to 'java.exe' set you might have to adjust the
.bat-file to:

"C:\j2sdk1.4.2_08\bin\java" -classpath "<path to Mediocre>" Mediocre

Where C:\j2sdk1.4.2_08\bin\ is the path to your 'java.exe'.

---------------------
WinBoard installation
---------------------

To run Mediocre in WinBoard open the winboard.ini file and find the line:

/firstChessProgramNames={GNUChess.exe
}

It might include more engines but should look something like that. Then add Mediocre
like this:

/firstChessProgramNames={GNUChess.exe
"java -classpath <path to Mediocre> Mediocre"
}

The next time you start WinBoard you will be able to choose Mediocre in the opening dialog.

-----------------------------
Other winboard/uci interfaces
-----------------------------

In other interfaces (like Arena; http://www.playwitharena.com) choose Add Engine from
the the menus and select the Mediocre.bat-file in the Mediocre folder.

Mediocre will recognize what protocol to run as.

Note: To use Mediocre with the Shredder or Chessbase interfaces (and perhaps other) you will need
to use the executable file. These are compiled by Jim Ablett and are available at his
site

http://homepages.tesco.net/henry.ablett/jims.html

and also at mine

http://mediocrechess.blogspot.com/

--------
Settings
--------

Mediocre now comes with mediocre.ini in which you can set the size of the hash tables, and decide wether the
own opening book should be used.

Since Mediocre is a Java engine it gets 64mb RAM allocated by default. In the .bat file I have now added "-Xmx1024M"
which allocates 1024mb RAM instead. This is NOT the size of the hash tables or how much RAM Mediocre will use, it is
merely the maximum amount the application CAN use.

If you set the size of the hash table to anything larger than the allocated memory Mediocre will not run. If you want
more RAM to be allocated simply increase the number in the -Xmx1024M (e.g. -Xmx2048M). Again this is not how much
the application will use, but how much it can use. Decreasing the number will have no other effect than not making
Mediocre start if hash table size is set to anything larger.

-------
Changes
-------
    v0.33: * Eval hash added
           * Pawn hash added
           * The zobrist keys are now pseudorandom, meaning they stay the same when restarting the application
           * Pawn zobrist key added to the Board class
           * Pawn eval divided between structure and passed pawns to fit with the pawn hash
           * Switched name between 'depth' and 'ply' in the search, depth is the number of plies left to search
             ply is the number of plies deep the search currently is
           * Fractional plies added
           * Matethreat extension and pawn to 7th rank extension added
           * It is now possible to change the transposition table size in the mediocre.ini file

    v0.32: * Killer moves verification to avoid generating unnecessary moves
           * The finalEval is now started with globalBestMove to make sure we always get the right move there
             (I'm not sure this was ever a problem, but just in case)
           * Passed pawn values halfed in middle/opening
           * Fixed x-ray attacks for queens
           * Simplified castling rights code
           * Added time search to line input and fixed some bugs
           * Dynamic null move depth
           * Futility check moves outside while loop
           * Fixed bug with black queen on 2nd rank bonus
           * Increased bonus for rook on 2nd/7th rank
           * Searched moves instead of HASH_EXACT to determine LMR and PVS (results in more reduced moves)
           * Hung piece check in the evaluation
           * Tempo bonus in evaluation

   v0.311: * Fixed a bug that made the engine enter an infinite loop if it was mated using the winboard protocol
           * Reworked the ended game draw detection using the winboard protocol (does not affect the search)

    v0.31: * Made a few arrays static in the SEE, speeding it up quite a bit
           * Futility pruning added
           * X-ray attacks in the evaluation (e.g. queen attacking empty squares behind own bishop)
           * Eval is adjusted towards 0 if a draw is likely
           * Pawns are valued slightly less but becomes a bit more valuable in endings
           * Knight outposts added
           * King tropism added
           * Rook/queen on 7th rank only awarded if enemy king on 8th or enemy pawns still on 7th
           * Fixed bug with bishop positioning and also one with pawn evaluation

     v0.3: * Mediocre is now stable enough to leave the beta, this is the frist 'sharp' version
           * Complete redesdign of the evaluation
           * In line input mode the command 'eval' now prints a list of the results of the
             different evaluation segments
           * New piece lists that store every type of piece in its own list, no more looping over the pawns
             to check for promoted pieces
           * Simple late move reduction added, every move after the first four are reduced with one ply
             if they were not a capture or a check
           * Static exchange evaluation added, used for sorting of both ordinary and quiescent moves
           * Losing quiescent captures (captures that lose material) are now pruned
           * New move generation methods gen_caps and gen_noncaps replaces the old generatePseudoMoves
           * Sorting moves is now handled inside the alpha-beta method, it is done step by step so
             we do not have to generate all moves up front, but rather one portion at a time
           * Move legality (not leaving king in check) is now verified when the pseudo-legal move is being
             played in the alpha-beta method instead of verifying all moves up front
           * With the new move sorting all non-losing captures are searched before the killer moves,
             the killer moves can only be non-captures now
           * The UCI protcol would crash the engine if an illegal move was sent in the position string,
             while this really should not happen Mediocre now recognizes illegal moves and sends an error
             message instead of crashing

  v0.241b: * Internal iterative deepening was added along with hash move search before generating moves       
           * The aspiration windows were reduced to 10 centipawns
           * The evaluation output was changed back to show the eval from the engine's point of view
             (in accordance with the winboard and uci protocols)

   v0.24b: * The evaluation was readjusted, resulting in quite an improvement in overall strength
           * Fixed an issue with the force mode in winboard, was not leaving force mode on the 'new' command
           * Added searchRoot() that works a bit differently on root nodes than ordinary alpha-beta,
             this should take care of the rare occasions where Mediocre did not have a move to make
           * The thinking output now shows white ahead as positive value and black ahead as negative value,
             the evaluation output no longer depends on what side the engine is playing
           * Fixed the contempt factor again, hopefully it works now (slightly negative number for the
             draw if white is moving, and slightly positive if black)

  v0.232b: * Mediocre now automatically detects what interface is being used, no parameter is needed

  v0.231b: * A bug in the new 'game over' check for winboard that made the engine crash was fixed
           * The transposition tables now use depth/new replacement scheme

   v0.23b: * Completely new evaluation, now accounts for king attacks, pawn evaluation and more
           * Check extension added
           * Draw repetition is now accounted for in the search tree as well
           * A bug concerning contempt factor was fixed
           * Piece lists added, no more 120 loops
           * Now gives correct mate count (and not just a high number) for both uci and winboard,
             evaluations from the transposition tables gives the count when the mate was found
             (this is on the todo-list)
           * The broken 'force' mode in winboard should now be fixed
           * Winboard protocol now sends the score when the game is finished (still needs some work)

   v0.22b: * Fixed a bug in the isAttacked method that made it do unnescessary checks
           * Changed the way unmake move works. The Board-class now has a history array where
             it keeps track of passed positions instead of using the Move-objects
           * The Board-class now keeps track of passed Zobrist keys so we do not have to
             'unmake' them when unmaking a move
           * The alphaBeta() does not generate moves at leaf nodes anymore
           * Changed ordering values for hash moves and killer moves so they always come
             first and second (at high depths the history moves sometimes came first)
           * Fixed an issue with reporting time using the UCI protocol
           * The Board-class now keeps track of king positions so we do not need to loop
             through the boardArray to find them
           * Changed move generation to use arrays instead of Vectors. generateMoves() now
             fills a given array from a certain index and returns the number of moves that
             were added
           * Alpha-beta and quiescent search now uses a common big array for storing
             generated moves instead of creating many small local arrays
           * Moves are now represented by an integer instead of a Move-object
           * The Move-class was completely rewritten and now only contains static
             methods for analyzing the new move integer
           * Fixed yet another issue with en passants (hopefully they work now)
           * The transposition table now uses an integer array instead of using Hashentry                                  objects. Many new methods for retrieving different values were added

   v0.21b: * Added support for 'infinite' search in uci (not applicable in winboard)
           * Added support for fixed time per move search for both uci and winboard
           * Added support for fixed depth search for both uci and winboard
           * Added support for the '?' (winboard) and 'stop' (uci) move-now commands,
             the 'move now' command in certain interfaces make Mediocre move immediately
           * Made null-moves only possible if the game is not in a pawn ending
           * Introduced contempt factor to draw values (dependant on game phase)
           * Added a game phase check that decides if the game is in the opening,
             middle game, ending or pawn ending
           * Added final INFINITY variable instead of using 200000 in the code
           * Cleaned up the line input, currently it can only set up a board with FEN
             and do perft/divide, might be enhanced again in later releases
           * Increased the number of nodes before time or interrupt command are checked,
             hopefully this should take care of the bug where Mediocre stops searching

   v0.2b:  * Transposition tables are implemented along with a new draw detection scheme
           * There is now a zobrist key field in the Board-class, the key is updated when
             making and unmaking moves, but can also be generated from scratch with the
             static getZobristKey-method in the Zobrist-class
           * Changed pv search so it is only used if a best move has been found
           * Sorting moves is now done with a much faster bubble-sort method
           * Changed move generation slightly and added a new filterQuis-method which adds
             the right values to the captures
           * Quiescent search now re-uses the moves generated in the alphaBeta method
           * Mediocre is now developed in Eclipse so the folders look a bit different
           * The .bat-files now point to "/bin/" so they work as long they are kept in the
              original folder (you should not have to update the path in them anymore)
           * Sorting methods are completely rewritten, based on orderingValue
           * Preliminary orderingValues are added to moves at generation time
           * Move-objects now have a orderingValue used in sorting
           * Implemented fixed depth search, call Engine.search() with depth>0 to use,
             call with depth=0 for time control mode
           * The line input can now be used to play games with fixed depth (5 for now)
             if you enter moves on the form "e2e4" etc. It is still very crude and is
             supposed to be used for testing
           * Plus many minor tweaks and changes

   v0.12b: * Time mangement added
           * UCI support added
           * Machine vs. Machine in winboard should now work
           * Added support for the 'force' command in winboard
           * Fixed a bug conerning en passant, perft values are now correct
           * Perft and Tests classes were added, these are best called in the new line mode
           * Calling Mediocre without argument now enters a simple line mode
           * Added a few parameters to Engine.search() to allow uci/winboard thinking,
             fixed depth and time management
           * Added setupStart() to Board, which sets up the initial position

   v0.11b: * Null-moves added
           * Added isInCheck() to the engine class (used by null-moves)
           * Move sorting is now done after the mate check to save time

    v0.1b: * Aspiration windows added
           * Killer moves heuristic added
           * Principal Variation Search added
           * A new opening book, shorter but lets the engine play itself better
