First, let me say this. Writing a chess engine is *incredibly*
difficult. But, don't get discouraged. Take it one step at a time.
raylopez99 wrote:
Quote:
I just program for fun, as a hobby. Since I also play chess, I figured
I would write a two-ply alpha-beta algorithm for generating the best
moves from any given position (within this event horizon). I have a
number of books on this subject (some with pseudo-code), so I'm
generally familiar with the subject (as a amateur).
Start by getting the minimax algorithm to work then move to alpha-beta
pruning.
Quote:
If you have open
source code (dumbed down or otherwise, since from what I can tell the
"move ordering" algorithm is the proprietary part of any chess engine,
since, like you say, after around ply 4 you cannot exhaustively search
the entire chess tree), please feel free to send it my way or otherwise
post it in some FTP public directory)
>
There are plenty of resources available on the net. You just have to
know what to google for. Don't worry about move ordering right now.
Take small steps. Get the minimax algorithm working, then add
alpha-beta pruning, and then worry about move ordering. Here's a
resource I've used in the past. Hopefully that will get you started.
http://www.seanet.com/~brucemo/topics/topics.htm Quote:
Quote:
The best way is to not store the moves at all. The branching factor,
which I think is a little higher than 30, will cause the tree to grow
so quickly that you'll run out of memory. The complexity of the tree
is O(b^n) where b is the average branching factor and n is the number
plies. Do the numbers. It's not pretty.
>
Very interesting! So you would have a predefined way of traversing the
tree and perform "alpha-beta" (from memory, sorry if my lingo is off)
"on the fly", with a suitable cutoff, pruning the tree as you go from
right to left or whatever order you traverse. Never even thought of
this.
Yes, I suppose that's one way of looking at it. The important thing is
that you prune so that you don't have to even examine parts of the
tree. Let me back track a little bit though. It is good to store
small parts of the tree. It's usually done in what's called a
transposition table which has a fixed and limited size. It's purpose
is to recognize positions that have already been examined. Chess is a
game where different paths can lead to the same position.
Quote:
Then you can store the best moves in a stack and pop/push the
winner candidate moves to the top of the stack. Very clever, as this
saves memory (if this is what was in mind).
Yep, all of these algorithms visit one node at a time and use the
function call stack to do so. An actual tree is never really built in
memory.
Quote:
BTW it amazes me that
ChessBase commercial computer programs can find the best move X% of the
time (with X around 90% it seems) with just five seconds of time
elapsed. The way I code, I can't get anything to work that fast (and
it seems C++.NET is very resource hog intensive--getting a console
"Hello World" appl to run seems to take a few seconds on a modern
Pentium 4 system, LOL.
>
Those programs are *incredibly* sophisticated. Their speed comes from
a combination of the algorithms that are used and how a position is
represented. For example, the algorithms don't stop at alpha-beta.
There's the principal variation search (PVS) and MTD(f) algorithms that
are generally better. I believe most (?) engines use a form of the PVS
algorithm. The way a position is represented is also important. Most
use a bitboard strategy where the position is completely defined in
small number 64-bit fields. That way moves are generated by doing low
level bit masks and shifts.
Quote:
Quote:
Quote:
I can think of a variety of ways of implementing this, including a
series of linked lists all pointing to the same header node at the
root, but I would like to know if there's a practical 'best' way, since
the tree will be traversed often, and it must be traversed quickly.
There will be no additions to the tree besides making it grow bigger
(longer, as move moves are added in a sequence). Certain branches will
be pruned, but the tree does not have to be rebalanced after pruning
(meaning the pruned branches will be simply marked as pruned but can
stay where they are).
>
It really depends on what the intent of the application is. Are you
asking because you want to create an intelligent player or just scan
the possible moves?
>
Actually both. Though I would like to scan all the moves for 2 ply (I
don't think it will cost too much memory)
>
Quote:
Quote:
Ideally I would like something already found in the .NET Standard
Collection Classes or Generic Collection classes, which include:
SortedList (key/value collection) and KeyedCollection, which are kinds
of Sets/Maps it appears.
None of those will work.
>
Far from me to argue with you, but I do recall a binary tree can be
made from a Map/Set (this was my motivation for writing the above).
A chess game tree isn't binary though. SortedList uses an array
implementation. You may be thinking of the SortedDictionary which uses
a red-black tree implementation. However, neither are really suitable
for storing a chess position.
Quote:
Quote:
Quote:
BTW, nearly every reference I look shows as the sole example of tree a
red-black binary tree, which is not that helpful to me, though I
realize probably as a mathematical matter you can parse any multnode
tree into a red-black binary tree.
A red-black has a specific purpose. It happens to be the one of the
most common implementation for sorted dictionaries. A sorted
dictionary has absolutely nothing to do with decision trees. No, you
can't transform a decision tree into a red-black tree.
>
OK. Probably true, and if you say so. Though if I were betting money
some clever Russian probably could do some transformation.
>
I doubt it. First, a red-black tree is used to store key-value pairs
in a sorted order. What would it mean to store chess positions in a
sorted order anyway? Also, a red-black tree is binary so unless you
only plan on storing 2 moves per position then there's an even more
fundamental conflict.
Quote:
Thanks for replying. Just collecting information for now. I do have
Professor Hyatt's open source code ("Crafty") but it's kind of hard for
me to follow.
It's hard for me to follow as well. Crafty is an excellent program.
Mine couldn't even come close to beating it :(. I had mine good enough
to beat GNU Chess half the time though :)