Neurosis and Neurosis-3D 1.8             By Stan Arts             16 August 2004
------------------------------------------------------------------------------------

Neurosis is my 3rd attempt at writing a computerchessprogram.

S-chess was my 2nd chessprogram, it can be used with, or without a GUI like winboard.
You can find it at : S-chess/Stan's chess (Info-pages) at www.wbec-ridderkerk.nl


My name is Stan Arts, I am currently 23 years old and I live in Holland. 


Configuration options. 
---------------------------------------------------------------------

In Neurosis-3D, you can set configurationoptions inside the program.
With the winboard version of Neurosis you'll need to set the configurationsettings
in the textfile neurosis.txt. In there you will find comment on how to use, and set
commands my program will use. 

My program understands eight possible commands. Please include them all in the
configurationfile, and then turn them on or off. The default settings are:

ht 16
log 0
sol 0
hum 0
spe 0
slw 0
var 0
rsn 0

For the winboard version, make sure you have neurosis.txt, and neurosis.bk (opening-
book) in the same folder and location as the program Neurosis.exe.

For the 3D version, make sure to have N3D.dll, N3D.dat and neurosis.bk in the same
folder and location as the program N3D.exe.


Options and commands for Neurosis in a Winboard-compatible Graphical interface.
---------------------------------------------------------------------

Neurosis understands timecontrols sent with the level command, fixed time per move
sent with the st command, and fixed search depth sent with the sd command. (With a
minimum of 2 ply, and a maximum of 40 ply.)
It supports force mode, and therefore edit-game mode etc. Further it accepts
positions sent with setboard in FEN format. Out of the FEN line it will read the
position, and castle posibilities. The En-passant square and 50 move rule counter
are not read out of the FEN-line. 
Neurosis can do shuffle-chess in Arena. Neurosis will accept any type of position,
even if it is not fully legal, (for instance, pawns on the lowest rank, or
something like 20 queens from one side that can not happen in a real game) as long
as the position has a white and black king. (Otherwise it will instantly show
mate.) 
Neurosis does not ponder, it can not read winboard commands while it is thinking.
Therefore I don't let it support analysis-mode, but you can easely let Neurosis
look at a position by having it think for a longer time. I made a special option
so you can set timecontrol of 1 move in x minutes, it will then use this time
exactly. Send a command such as: level 1 10 0 (one move in ten minutes) , and it
will look at the position for 10 minutes. (Minus 5 seconds, that my program will
not use to avoid going through a time-flag.) 
When Neurosis has receaved the xboard command, it will not display the ASCII
chessboard every move, and it will send it's book-move in a way so that winboard
can read it, and display it. 
My program supports and will play castling and en-passant, and it will accept 
underpromotion of the opponent. Neurosis will claim result when the game ends in:
mate, draw by stalemate, draw by 3x repetition, draw by the 50 move rule, and
resigning.
My program will display a hintmove when you request one. It can only give a hint
after it calculated the last move. When you request a hint while Neurosis is still
in book, or directly after you set up a new position, it will display "none".

How to use Neurosis-3D. The 3D stand-alone version.
------------------------------------------------------

Before running Neurosis-3D, (N3D.exe) make sure your computer can meet the
following requirements:

- It's atleast a Pentium MMX compatible processor.
- 32 MB free internal memory available. (Neurosis-3D always uses a 16MB hashtable)
- Can run at 800x600 at 65536 colours (16-bit colours) as a full-screen mode.
- Make sure your mouse works without problems. 
- All the data-files that belong to Neurosis-3D are in the same folder as the
N3D.exe main file and that you start the program from this folder. Also when you
want to save a played game or enable the log-file, make sure you aren't running
the program from a CD-ROM and that your disk isn't full. The games will be saved
in the same folder all the N3D files are in.

After starting N3D you are in the main menu. 

With "options" you are able to set all the options for the game. 
Enable or disable options by clicking the small boxes with your mouse. Select
a timecontrol to play at. This only sets the computers playing-speed, and you
won't get flagged for thinking too long. With "show computers thinking" you can
select if you would like to see what the computer thinks of the position and
what it would like to play and expects you to play.
The "show move-list" option will show a small box with the moves of the game. You
can scroll up and down by clicking the up and down arrow at the left side of the
box. 
You can change side to play, but not during a game. When you do so, it will
automaticly start a new game. If you want to change sides with the current 
boardposition, use edit boardposition, and change your play-side. (But time used
by both sides will then be set to 0.)
There are 3 levels of play. Default is Neurosis at full speed, and it will use
all the computers speed for thinking. It's for strong players. The middle option
will limit Neurosis's speed to about 5000 nodes/second and will play a bit 
weaker. At the lowest option Neurosis will run at just approx. 500 nodes/sec,
and it will not be able to think very deeply. 
Toggle "use time more realistic" to make Neurosis use it's time more human-alike.
(For instance, not move instantly when playing moves out of the openingbook, and
vary it's time a little more.)
Use the "speculative" modes to sometimes let Neurosis find positional advantages
more important then material, and might sacrifice material for positional
advantages. 
With the vary option Neurosis will use small random values in it's search to
vary it's play to some extent. 
There are 3 available backgrounds/enviroments for the 3D room. Default is none,
but you can select the background to be a room.  Also you can select the dots as a
bit of a computeristic background. They are mostly to give a background reference
when you are flying around.
You can select several different boardcolours. They are stone, wood, green and
blue. 
Also you can select a different colour for the white pieces. These can be wood
or pure white. The black pieces are always grey, but can be turned light or dark. 
Select the 2D perspective to see the board from above. To see the board from the
opponent's side in 2D mode select the flip-2Dboard option.
Switch log-file (it will create a file named N3Dlog.txt) on to review after the
game what Neurosis was thinking.
Change the size of the pieces by selecting another percentage. Normally the
pieces are quite small to give the impression of a large tournament board, but
you might prefer the pieces to be bigger compared to the board. You can switch
on and off if captured pieces should be kept next to the board, so you can keep
better track of what's happening and the material balance.  
 
With "edit boardposition" you can setup a new boardposition to play. It's use is
very straightforward. However, note that when clicking edit boardposition, the
time-clocks will be set to 0, even when you don't change the position. To use a
position you created, you have to click resume current game. 

Click "Save to PGN-file" to save your current game to a pgn-file. Many other
chessprograms such as winboard will be cabable of reading these files. (Also, the
PGN's are in readable format so you can open them with any text-editor and print
them for instance.) 
After clicking this option you have to select game1 to 5 as a filename. Note
that existing files will be overwritten. When you play many games please copy
existing files to another folder, or rename them, to keep them.

"Help and info" is a screen with some info about Neurosis-3D and short help on 
how to use the program.

With "Start new game" a new game at the selected timecontrols and playside will
start.  By pressing the ESCAPE key while in the game, or clicking the upper-left
box you can return to the main menu. Then you have to use the "resume current
game" option to return to the current game.

Click "quit the game" to exit Neurosis-3D and return to windows.

Neurosis-3D does not require a 3D-acceleratorcard. Neurosis uses my free-movement
and rotational software-rendering 3D-engine, that I've started on in 1994 and is
a continuous work from then on. 3D-technically it's quite different from anything
else, and if you can stand polygongraphics, then hope you'll enjoy the 3D board. 
You are able to move around freely in the 3D enviroment.:

Hold the right mousebutton or spacebar and move the mouse around to change your
viewing direction.

Press the up, down, left or right arrowkey on the keyboard to fly into the 
direction you like.

Playing chess with my program.:  Just select the piece you would like to move by
clicking (with your left mousebutton) on the square the piece is on. It will then
light up. Then move your mouse to the square you would like to move the piece to
and click again. Neurosis will make sure your move is legal, so when the piece
doesn't move make sure you selected the right square and that it is a legal move
and that it is your turn and your king isn't in check. Please refer the "rules of
chess and strategical tips" section of this readme file, or other chess-
documentation if you are unfamiliar with the rules of chess.


The rules of chess in short, and some strategical tips.
----------------------------------------------------------
 
Here is a quick explanation of the rules of chess. Please refer to other chess-
documentation for a more detailed explanation.

Chess is a boardgame, and it's played on 64 squares. (8 rows and 8 colums.)
There are always 2 players and one side has the white side, and one side has the
black side.

Each side has pieces, which could represent an army or a kingdom if you like. 

The goal of the game is to capture the opponents king. When the opponents king
can not avoid capture anymore the game ends and you win. (This is called check-
mate, the actual capture is never played.)

For each side, there are 6 different pieces, and they can all move in a different
way. As you'll find out, the way each piece can move will turn out to be very
important for it's value or importance in the game. 

A list of the pieces and their movement :

The Pawn.   The pawn is least important of pieces, and that is because it is most 
limited in it's movement. It can only move forward (and never backward) one 
square at a time. And it may only move forward when there is no piece on the
square infront. There are however a lot of exceptions to the pawns movement where
it can move in a different way.: When it is still in it's original place on the
2nd row, it may jump forward 2 squares, when both squares infront are free. 

. . . . . . . .8 black
. . . . . . . .7
. . . . . . . .6
. . . . . . . .5
. . . . . * . .4  < it may go here because it was still on the 2nd original row
. . . . . . . .3
. . . . . P . .2  < 2nd row
. . . . . . . .1 white
a b c d e f g h 

A pawn can "capture" a piece (capturing in chess is done by landing on the enemy
piece and taking it's square. Unlike checkers for instance where you jump over
the enemy piece to capture it.) when it is 1 square up and to the left or right
of the pawn. 

. . . . . . . .8 black
. . . . . . . .7
. . * . * . . .6  < It can only capture pieces on the *'s . 
. . . P . . . .5
. . . . . . . .4  
. . . . . . . .3
. . . . . . . .2  
. . . . . . . .1 white
a b c d e f g h 

A pawn can become very important, when it has managed to get all the way across
the board and reaches the 8th row. Then it "promotes", and you can choose it to
become eighter a Queen, Rook, Bishop or Knight.  

There is one very special chessmove, that is called an en-passant pawncapture,
and it can be played when you reach the 4th row of the opponent (5th row of 
the board in the case you are white) and the opponent has a pawn on the original
row eighter 1 square left or right of your pawn. When the opponent chooses to
play his pawn on the original square 2 squares forward so it lands directly
left or right from your pawn, you can choose to capture it. This is the only
case in chess where a capture doesn't happen on the square the enemy piece is
on. And you place your pawn 1 square forward and 1 square eighter left or right 
(depending on what side the opponent pawn is on) and take the opponent's pawn
of the board. It can only be done DIRECTLY after the opponent played up his
pawn.

. . . . . . . .8 black
. . . . = . . .7  < original square of the opponents pawn
. . . . * . . .6  < You can capture to the e6 square, and take his pawn off.
. . . . p P . .5  < Before it was your turn the opponent moved to e5
. . . . . . . .4  
. . . . . . . .3
. . . . . . . .2  
. . . . . . . .1 white
a b c d e f g h 


The Knight.  The knight is more important than a pawn, because it can move a lot
more freely over the board. Unlike the pawn, it can move forward but also
backward. When capturing it always has to land on the square occupied by the
opponents piece. The knight is special because it can jump over any piece, and
move in a L shape. It always moves eighter 2 squares up or down or to the left
or right, and 1 square up or down or to the left or right but always in a 90
degree angle to the 2 square direction. In english notation the Knight is often
refered to as N, because the King also uses the K. 

. . . . . . . .8 black
. . . . . . . .7  
. . . * . * . .6  
. . * . . . * .5  
. . . . N . . .4   < your knight can land on all the *'s . 
. . * . . . * .3
. . . * . * . .2  
. . . . . . . .1 white
a b c d e f g h 

The Bishop.  The bishop is capable of moving in a diagonal way. This may be
forward, left or right but also backward. It can not jump over any pieces so the
line must be free and the square you want it to go to can't be occupied by any of
your own pieces. But it can capture an opponents piece by landing on it. You'll
notice each side has a bishop on a light square and a dark square, a bishop can
never leave the light or dark squares it started on. 

. . . . . . . *8 black
* . . . . . * .7  
. * . . . * . .6  
. . * . * . . .5  
. . . B . . . .4   < your bishop can go to all the *'s . 
. . * . * . . .3
. * . . . * . .2  
* . . . . . * .1 white
a b c d e f g h 

The Rook.   The rook is one of your more important pieces, because it has greater
power and force. The rook moves in straight line. These can be left, right but
also forward and backward. Just aslong as the line is free and the square you
want to go to isn't occupied by any of your pieces. It too may capture opponent
pieces by landing on them.

. . . . * . . .8 black
. . . . * . . .7  
. . . . * . . .6  
. . . . * . . .5  
* * * * R * * *4   < your rook can go to all the *'s . 
. . . . * . . .3
. . . . * . . .2  
. . . . * . . .1 white
a b c d e f g h 

The Queen.  The queen is your most important combating piece, because she has
the greatest power in movement and force. She is a combination between a bishop
and a rook. 

* . . . * . . .8 black
. * . . * . . *7  
. . * . * . * .6  
. . . * * * . .5  
* * * * Q * * *4   < your queen can go to all the *'s . 
. . . * * * . .3
. . * . * . * .2  
. * . . * . . *1 white
a b c d e f g h 

The King.  Although the king is the most important of the game, it can't move as
far as the queen.  The king can move the same as the queen but it can only go 1
square at a time. It can capture similair to other pieces but you can't let it
capture a piece when it could be captured afterwards itself. (Can not put itself
in check)

. . . . . . . .8 black
. . . . . . . .7  
. . . . . . . .6  
. . . * * * . .5  
. . . * K * . .4   < your king can go to all the *'s . 
. . . * * * . .3
. . . . . . . .2  
. . . . . . . .1 white
a b c d e f g h 

The king (and rook) have a special move, called castling. It allows the king to
get away from the centre of the board, and be more protected. 

. . . . . . . .8 black
. . . . . . . .7  
. . . . . . . .6  
. . . . . . . .5  
. . . . . . . .4   
. . . . . . . .3
. . . . . . . .2  
. . . . K # * R1 white
a b c d e f g h 

In this case, the king (on e1) can be moved to g1, and the rook (on h1) to f1.
But ONLY, if -The king and rook haven't moved before -The path between the two
pieces is free -The squares e1,f1 and g1 are not in check.

The resulting position would be : 

. . . . . . . .8 black
. . . . . . . .7  
. . . . . . . .6  
. . . . . . . .5  
. . . . . . . .4   
. . . . . . . .3
. . . . . . . .2  
. . . . . R K .1 white
a b c d e f g h 

This is called a short ("kingside") castle. It is also possible to castle
long, to the queen side. See below.

. . . . . . . .8 black
. . . . . . . .7  
. . . . . . . .6  
. . . . . . . .5  
. . . . . . . .4   
. . . . . . . .3
. . . . . . . .2  
R . * # K . . .1 white
a b c d e f g h 

In this case, the king (on e1) can be moved to c1, and the rook (on a1) to d1.
The same rules as for a short castle count, but square a1 and b1 may be in check. 

For black, it is also possible to castle, when pieces are in the same order but
on the 8th row.

When any of the opponents pieces "aim" (fall in the movement reach of that piece,
and could capture your king next move) at your king, then your king is in "check"
and you MUST get out of check, eighter by moving out of the way or capturing the
opponents piece or place something in between. When you can't avoid the check it 
is checkmate and the game is over. However, when you are not in check but you can
not move without putting your own king in check or have no other legal moves then
it is stalemate and the game is a draw.   
The game also ends in draw when the same boardposition occurs 3 times, (with all
conditions being the same those 3 times) or there hasn't been a pawnmove or
capture by any piece for 50 moves. Then the game ends in a draw by the 50 move
rule.

As I already wrote some pieces are more important than others because of their
movement. A queen can be far more helpfull than a pawn. The goal of the game is
to "win" the opponents king, however this is made difficult by the army forces
the opponent has, and this makes that you have to try to break his/her army.
Usually this is done by outsmarting your opponent in traps or so called 
combinations where your opponent loses more material then you do. Then it will
become easyer to win his king.

It is important to keep your eye on your material and try to keep your valuable
pieces. When trading, you should think and calculate it is a good idea..and in
general you could award the different pieces the following scores. : 

King   : has infinite importance
Queen  : 9 points
Rook   : 5 points
Bishop : 3 points
kNight : 3 points
Pawn   : 1 point

There are however a lot of exceptions to this. A pawn near the 8th rank can be
worth as much as a queen, and a bishop is usually worth slightly more then a
knight. (Depending if the opponent has many pieces on the square-colour of 
your bishop for instance, and many other factors) A knight near the centre
or near the opponents weak points can be very valuable and maybe worth a rook.
And an undeveloped piece or a piece unable to move somewhere in the back can be
worth very little, to give a few examples.

The starting position is as following: (CAPS are the white pieces)

r n b q k b n r  8 black
p p p p p p p p  7  
. . . . . . . .  6  
. . . . . . . .  5  
. . . . . . . .  4   
. . . . . . . .  3
P P P P P P P P  2  
R N B Q K B N R  1 white  

a b c d e f g h 

Where you can remember that the queen of both white and black is always on the 
d-collum and kings are always on the e-collum. (The white queen starts always on
a light square, and the black queen always starts on a dark square)

Some strategical tips : 

At the beginning of the game, try to get your pieces of the back row and make
them active on the board. You should try to occupy and control more space then
your opponent, this will make it easyer for you to come up with plans and make
it difficult for your opponent to move around. Besides making your pieces
active, try to get your king in a safe place as fast as possible, as this will
give the opponent far less chances.

All in all you try to create opportunity's by opening important lines and trying
to get your pieces to be able to move around freely and limit your opponents
movement.  


Info about Neurosis. 
---------------------------------------------------------------------

Neurosis is written in Pascal, the winboard-version is compiled with Free-Pascal
v1.0.6, and the 3D version with v1.0.10 . (1.0.10 seems to communicate with
winboard differently, and I haven't solved that yet at this time.)
(www.freepascal.org) The winboard version of Neurosis will run on any 386 and up,
but Neurosis-3D requires atleast a MMX processor.

Neurosis is written with what I learned from writing my previous two chessprograms,
and is written from scratch. The chessboard is represented as a 10x12 array of
bytes. Maximum searchdepth is 40 ply, and extentions can go on to a depth of 55 ply.
It knows all chessrules, but does not generate underpromotions in the searchtree.
Search is based on minimaxing, with alpha-beta aplied to it. The programmingstyle in
which the searchtree is built up is "not recursive". It does not make and unmake
moves, but the entire position and properties are stored for each depth, as well as
on a general virtual board from which moves are generated, evaluationfunction will
look at, etc.  
At each tip of normal search, extentions are done for checkingmoves, (the number
of checks in the normal searchline are counted, When more then one check, then this
gets extended. When at the tips and in check, counted is if there is more then one
move for the side in check, this is only allowed once from the tips on. If there 
is just one move, then this gets always extended, upto a depth of 14 extra ply over
the normal searchdepth. If a more-then-one-move out of check occurs later after
one-move replies, and there wasn't a more-then-one-move extention before, then this
gets allowed.) and an extention at the tips of 1 ply for a pawn on the 7th row,
ontop of the depth of extra check-moves if there were any in the normal line. 
Neurosis has a quiescent search, where only specific moves are tried. Mostly
capturemoves, but also checkingmoves upto the normal depth if a null-move was done.
Capturemoves on any square over the board are tried to 4 ply over the normal
searchdepth, or another 3 ply over the maximum extentiondepth. Captures that do not
bring the score close to alpha with some margin are ignored. The margin is dependant
on the setting of "speculative", and if a capture recaptures on the same square as
the previous move or not.  After the first level of quiescent search where all
captures are tried, only recaptures on the square of previous moved piece are tried,
these may go on to unlimited depth. In quiescent search checkdetection is done to
detect pieces pinned to the king.  
Neurosis uses hashtables. The main hash/transportationtable has two parts. The
biggest (3/4 of size) has a depth, and PV preference. The second (1/4th of size)
has an always-replace strategy. Each entry has a size of 8 bytes. Also a small
(1 MB) hashtable is used to store evaluationvalues of pawn-structures. These have a 
size of 5 bytes per entry. When Neurosis prints the best-line, this is
reconstructed from the hashtable.  Hashkeys are generated from scratch at each
position. The key-indexes are generated by multiplying piece-type and board-square
with 2x 64 fixed random numbers. When retrieving I also try if the stored move is
legal in the current position.
When generating moves, I store them in a list, and orden them as following. : 
-Hashmove. 
-Winning captures (A piece capturing a piece with a bigger score.)
-killers, no captures in the killers. (2 killers per ply, and I look at the killers
of ply-2, so I look at 4 killers.) 
-Rest of the captures, sorted by looking at the value left by subtracting the
value of the attacker from the captured piece. At this fase, all these values will be
equal or less, so capturing on the square of the last moved piece get placed first,
after the winning captures and killers. 
-Rest of the moves, these do not get sorted, but generated from back of the board
forward. (from the side's backside of the board.) Only on the first two ply in the
searchtree I sort these moves on evaluation.
-In quiescent search I orden the captures like in normal search, promotions without
captures are placed last, and if I generate checks here, I find the checks out of
the remaining moves, and place them last. 

Neurosis's evaluationfunction is fairly complex, and will look at several hundred
properties in a position. Makes very little use of so-called piece-square tables,
many factors are dependant on each other. Each position gets a full evaluation. I
think it has quite a unique style.

Neurosis prunes in an uncommon way.  I wish is to make Neurosis a very accurate
program, rarely missing an important tactic, and in 99% of cases find a tactic on
the same depth as it would without pruning.
Besides alpha-beta, pruning is based on an idea similair to null-move. But in
Neurosis, they are not allowed recursivly. (=not more then one in any line.) Because
of this, I have to wait and find a position in the line where it's very lickely the
null-move will return positive. So if or not a null-move is done is dependant on
static evaluation, and a few other variables, such as the alpha and beta values. If a
nullmove will be done, the amount of reduction is also dependant on static evaluation,
and depth in the searchtree. These are 1 and 2, but for very large depths, and a static
evaluation very high above beta, a reduction of 3 is allowed. Whenever a nullmove is
done, at the end of the line this is made more safe by trying checking moves from the
side that didn't do the nullmove, in quiescent search, upto the otherwise nominal
depth. So when searching to a normal depth of 8, but a nullmove was done and reduced
the tree to depth 6, checks are tried on either depth 7 or 8 in quiescent search. 
Also, the nullmove searches starting on a depth further then 2 away from the tips of
the searchtree get a verificationsearch with an overal reduction-factor of 3, to
quickly find solutions for the so-called zugzwang positions.

When retrieving a move from the openingbook, it is checked for legality. It does
not understand transpositions in the openingbook. A maximum of 15 moves are played
out of the openingbook.

Version 1.8's improvements over 1.7 are mostly tactically, hopefully it is
significantly stronger.

The 3D version has improved 3D-graphics, (Improvements are for instance, finer steps
of rotation, and faster) and now an option to display a 2D board. 

Neurosis and I have competed in a strong international computerchesstournament in
Leiden in April 2004. CSVN's ICT04.  This was my first computerchesstournament, and
Neurosis could score 2.5 points out of 9. I was happy about that, and hope to be able
to join more tournaments in the future.

Neurosis will display moves in short notation. For instance: e4, or Nf3. Also it
will always report (also in the best line) when a move leads to check with a +,
and ep when it is an en-passant move. When two or more pieces can move to the
same square, then Neurosis will write the move out long. For instance: Nf1xe5+
instead of Nxe5+ or Nfxe5+. 

My program searches with score-bounds, and when a position is found to be better
or worse, it will display < + > to say it will be better, or < - > if it see's it
will be worse, and it will do a research to determine the correct score and best
line. Note, when it is in the process of doing a re-search and displaying a < + >
or < - > , the hint-move might not be a good one. Neurosis opens up it's search
window in more then one step sometimes when there's a big scorechange. Giving
two or three < + >'s or < - >'s in a row. 

Hope you will enjoy my program.

Any suggestions, questions or anything else, write to: stan_live@hotmail.com

Neurosis is a band, that gives me inspiration and hope. Visit www.neurosis.com


Stan
