Just an idea..and enough code to make it workable.
We can show the NN the state of a chessboard..
Each cell of the 8x8 grid contains a 'chesspiece id', and each chesspiece id is represented as a series of floating point values (ie the binary string of each id value is represented by a floating string containing only 0.0 and 1.0).
Since we only have to represent 6 chess pieces (and an empty cell), we can do this with just three bits, ie, three floats, so I used Vec3.

In this demo, I'm teaching the NN what the board looks like for a new game of chess, and that when its inputs are shown a new game of chess, its outputs should ALSO show a new game of chess ... ie, NOP.

It's VERY easy to teach this AI by letting it 'observe' games between actual humans, while in 'training mode'... heh.. in a loop, train it witht inputs=old chessboard and desired outputs=new chessboard, until its outputs=desired outputs.
Bad players will make it more stupid, but I mentioned the solution in another thread.

Once the AI has had a little training, you can play against the computer, and/or let the computer make suggestions :)
Attachments:
Posted on 2006-12-31 01:17:30 by Homer
Hi Homer,

Board representation:
---------------------
In the representation of the board, I can see no difference between a white and a black piece.

Suppose we have a position:
White: King e7, pawn d6
Black: King e5

It's a big difference, whether the pawn at d6 is black or white.
It doesn't matter who's turn it is, but the one who is owning the pawn is going to win.

It's also a big difference, if the King at e7 is black, instead of white. (The King at e5  is white then ofcourse). If the pawn at d6 is white, the game will result in a draw.

In all these situations we have the same representation of the board, but all having a different meaning, and outcome of the game.

The NN shouldn't be confused by the colors of the pieces.
How would the NN know the difference?


Strong moves:
--------------
If I understand it well: You first want to see the result of the game. And you save the NN of the winning side.

But in chess the following rule often applies:
The one who makes the LAST mistake, will lose.

In other words: The losing side can have produced better moves than the winning side, until there was a turning point: The moment the losing side made his big mistake!

The difficulty with chess is, that it exists of a sequence of moves.
Each of them can be (relatively) strong, or not. It depends on the evaluation of the resulting position.
So, we have to figure out a way to evaluate a position as good as possible. It can lead us to the right move. For it's the strong moves we are interested in. Not just who has won. Ofcourse there is a chance, that the winning side made all the right moves. But there is no guarantee.

How can a Neural Network help us on this matter?

Friendly regards,
mdevries.
Posted on 2006-12-31 03:01:28 by mdevries
In any particular given chess position, the next move is what matters most... we have a selection of N moves, leading to a selection of N outcomes.
If we recall what moves lead to a win, we win :)

Regarding the colors, you are right - I'd recommend setting another bit to determine the colour, so we'd work with Vec4 instead of Vec3.

Anyway, this was not a serious project source, this was my half cocked response to your suggestion.
I've not actually employed the NNet code in a serious project, but here we have a perfect example.

Posted on 2006-12-31 08:48:30 by Homer
Actually, now I thought about this some more, you're wrong - theres NO NEED to distinguish between the colors of the chess pieces.
In fact, the AI requires NO KNOWLEDGE of chess or its rules.
The AI simply needs to know how to evolve the state of the chessboard when it has to make a move, and this experience is acquired through observing actual games between humans.

If we train our NN properly, the AI will NEVER make illegal or stupid moves, so we ought not to need any code to check whether the AI's moves are legal or not - if trained correctly, it only knows how to make LEGAL moves (for example, it's never seen a game where a player takes his own piece, so it'll never produce such an outcome).

If we DONT train our NN properly, it's going to do crazy things, it's going to make bad and/or illegal moves etc - we can write some code to enforce the rules of the game, but if we did our job as developers,  and our betatesters did their job too, we'd never need rules.

It's actually quite strange when you think about it that an Expert System can operate effectively with no actual comprehension of what it is really doing, with no concept of limitations imposed on it etc, until you think about some of the PEOPLE you might know who seem to do this on a daily basis (my local member of parliament springs to mind).
Posted on 2007-01-01 12:45:06 by Homer
I don't think I get the idea of a NNet then.

This is my understanding of a Neural Net:
You have an input layer, fed by the actual position. The actual position is formed by a certain amount of pieces scattered all over the board.
The stimuli coming from the input layer, generate a flow through zero or more hidden layers in the network, until the output layer is reached. For a Chess Neural Net the output layer could be a resulting position, or just a move, or whatever you want it to be.

Now, what if we have the same position? Only the colors of some pieces differ, but we can't tell the difference. In both cases we have the SAME INPUT for the Neural Net, and I guess also the SAME OUTPUT. But we really don't want the same output. We want a DIFFERENT OUTPUT, depending on the colors of the pieces, not just on the kind of pieces. How is the Neural Net able to produce the right move, if he can't distinguish the colors?

I think I am missing the point at the moment.

Friendly regards,
mdevries.
Posted on 2007-01-02 10:21:16 by mdevries
Forget about the colors of the pieces for the moment, and consider the state of the chessboard, with pieces here and there, regardless of their colors.

If we exhaustively trained our NN.. show its inputs every possible combination of pieces in every possible position (ie every possible state of the board) and for EACH set of inputs show it one or more sets of desirable outputs, it can only produce those.

If the NN is simplistic, it can only produce ONE move from any given chessboard state, but if its a little more elegant, it can choose from several.

Typically, NN's produce one (set of) outputs for a given (set of) inputs, but that's not the way it has to be - after all, our biological NN (our brain) can produce decision making behaviours - what makes you think an NN can't do that also?

If the NN is a 'single layered network', it can't choose - but we can have a smaller NN whose job is to make a selection from the outputs of several chess NNs - its weights are trained by progressive outcomes from previous attempts to use a given set of outputs.

Now we have a two layered expert system, with a 'decision-making' NN presiding over several 'past experience' NNs - now we can implement behaviours such as 'fight or flee' and other pseudobiological concepts.. now our AI can adjust its own behaviour - what ya think about that? Kinda scary eh?
Posted on 2007-01-02 11:27:23 by Homer

If we exhaustively trained our NN.. show its inputs every possible combination of pieces in every possible position (ie every possible state of the board) and for EACH set of inputs show it one or more sets of desirable outputs, it can only produce those.


It's quite impossible to train the NN this way, because the amount of possible combinations of the pieces is just too great.
It seems there are more possible combinations then there are atoms in the universe.

Besides, if you would be able to cycle through ALL the possible combinations (which is far too time consuming), and you could save them in a database (which is not possible given the amount of atoms you would need), you could use this database as a lookup table for the best move, which is far more simpler than using a NN.

If the NN is simplistic, it can only produce ONE move from any given chessboard state, but if its a little more elegant, it can choose from several.


I agree it's possible to invoke a choosing system. That's ok as long as we are choosing a LEGAL move from it.
However, if the input is taken from an ambiguous position, there is a chance the system will choose an ILLEGAL move.

I can't help rementioning the position, earlier in this thread:
White: King e7, pawn d6
Black: King e5

The only legal move for the white pawn is to square d7.
Moving to d5 would be illegal.
But if the pawn was black, instead of white, the opposite would be true: Moving to d5 would be legal, and moving to d7 would be illegal.

We surely don't want the NN to choose an illegal move. Those moves have to be discarded. How does the NN know what is illegal if it can't determine the color of the pawn?

Friendly regards,
mdevries.
Posted on 2007-01-02 14:08:18 by mdevries