如何为国际象棋编程神经网络? [英] How to program a neural network for chess?

查看:192
本文介绍了如何为国际象棋编程神经网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编程一个象棋引擎,该引擎学会做出好动作并与其他玩家对抗.我已经编码了国际象棋棋盘的表示形式和一个输出所有可能动作的函数.因此,我只需要一个评估功能,该功能说明董事会的给定情况有多好.因此,我想使用一个人工神经网络,然后应该评估给定位置.输出应该是一个数值.值越高,白人球员的位置就越好.

I want to program a chess engine which learns to make good moves and win against other players. I've already coded a representation of the chess board and a function which outputs all possible moves. So I only need an evaluation function which says how good a given situation of the board is. Therefore, I would like to use an artificial neural network which should then evaluate a given position. The output should be a numerical value. The higher the value is, the better is the position for the white player.

我的方法是建立一个由385个神经元组成的网络:板上有6个独特的棋子和64个场地.因此,对于每个领域,我们需要6个神经元(每块神经元1个).如果有一块白色,则输入值为1.如果有一块黑色,则值为-1.并且,如果该字段上没有该种类的块,则该值为0.此外,应该有1个神经元供玩家移动.如果是白色,则输入值为1;如果是黑色,则输入值为-1.

My approach is to build a network of 385 neurons: There are six unique chess pieces and 64 fields on the board. So for every field we take 6 neurons (1 for every piece). If there is a white piece, the input value is 1. If there is a black piece, the value is -1. And if there is no piece of that sort on that field, the value is 0. In addition to that there should be 1 neuron for the player to move. If it is White's turn, the input value is 1 and if it's Black's turn, the value is -1.

我认为神经网络的配置非常好.但是缺少主要部分:如何将这种神经网络实现为编码语言(例如Delphi)?我认为每个神经元的权重在开始时应该相同.然后根据比赛结果调整权重.但是如何?我想我应该让2位电脑玩家(都使用我的引擎)互相对抗.如果白方获胜,则黑方会得到其权重不好的反馈.

I think that configuration of the neural network is quite good. But the main part is missing: How can I implement this neural network into a coding language (e.g. Delphi)? I think the weights for each neuron should be the same in the beginning. Depending on the result of a match, the weights should then be adjusted. But how? I think I should let 2 computer players (both using my engine) play against each other. If White wins, Black gets the feedback that its weights aren't good.

因此,如果您能帮助我将神经网络实现为编码语言(最好是Delphi,否则为伪代码),那就太好了.预先感谢!

So it would be great if you could help me implementing the neural network into a coding language (best would be Delp otherwise pseudo-code). Thanks in advance!

推荐答案

在此完成.由于您的问题没有连续性(一个位置的值与一个位置的值并不紧密相关,而一个输入的值只有1个变化),因此NN的工作机会很小.而且在我的实验中从未如此.

Been there, done that. Since there is no continuity in your problem (the value of a position is not closely related to an other position with only 1 change in the value of one input), there is very little chance a NN would work. And it never did in my experiments.

我宁愿看到具有临时启发式(其中有很多)的模拟退火系统来评估位置的值...

I would rather see a simulated annealing system with an ad-hoc heuristic (of which there are plenty out there) to evaluate the value of the position...

但是,如果您开始使用NN,则表示起来相对容易.一般的NN只是一个图,每个节点都是一个神经元.每个神经元都有一个当前激活值,以及一个转换公式,用于根据输入值(即与之链接的所有节点的激活值)来计算下一个激活值.

However, if you are set on using a NN, is is relatively easy to represent. A general NN is simply a graph, with each node being a neuron. Each neuron has a current activation value, and a transition formula to compute the next activation value, based on input values, i.e. activation values of all the nodes that have a link to it.

一种更经典的NN,即具有输入层,输出层,每一层相同的神经元且没有时间依赖性,因此可以由输入节点数组,输出节点数组和a表示.连接这些节点的链接图.每个节点都有一个当前的激活值,以及它转发到的节点列表.计算输出值只需将输入神经元的激活设置为输入值,然后依次遍历每个后续层,使用转换公式计算上一层的激活值.到达最后一个(输出)层时,您将得到结果.

A more classical NN, that is with an input layer, an output layer, identical neurons for each layer, and no time-dependency, can thus be represented by an array of input nodes, an array of output nodes, and a linked graph of nodes connecting those. Each node possesses a current activation value, and a list of nodes it forwards to. Computing the output value is simply setting the activations of the input neurons to the input values, and iterating through each subsequent layer in turn, computing the activation values from the previous layer using the transition formula. When you have reached the last (output) layer, you have your result.

这篇关于如何为国际象棋编程神经网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆