特隆lightcycles AI在序言 [英] Tron lightcycles AI in Prolog

查看:161
本文介绍了特隆lightcycles AI在序言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的AI游戏(像TRON lightcycles)的问题。 我写的关于使用ncurses的C中的所有图形和运动。 现在我需要编写机器人的人工智能的序言。我使用SWI序言。

I have the problem to write the AI to game(like tron lightcycles). I write all the graphics and movements on C using ncurses. Now i need to write the bot's ai on the prolog. I'm using swi prolog.

我保存当前的游戏场(所有的矩阵),当前人类的位置和当前机器人的位置(如基质细胞I,J)。他们节省了像predicats在从C特等文件。

I save the current game field(all matrix), current human position and current bot position(like matrix cells i, j). They saves like predicats in the .pl file from c.

我的游戏领域是一个矩阵,其中包含1和0(1 - 参观,0 - 未访问过)。 像这样的:

My game field is a matrix which contains 1 and 0( 1 - visited, 0 - unvisited ). Like this:

human_current_position(0,1).
bot_current_position(1,2).
matrix([[1,1,0,0],
[1,1,1,0],
[0,0,0,0],
[0,0,0,0]]).

然后我需要分析这个矩阵,如:

Then i need to analyze this matrix like:

analyze(matrix).

因此​​,在序言中的分析函数将返回某个方向(左,下,上,右)保存到文件 我的C程序读取这个文件,移动机器人。

So the analyze function in prolog will return some direction(left, down, up or right) save into file and my c program read this file and move the bot.

所以我有这个问题 - 我怎么能分析该矩阵的序言。 我读了一些关于最小 - 最大算法,但我不能在序言认识到这一点。 任何人都可以帮助或显示的方向如何使工作最小值最大值算法 我在序言矩阵​​的当前位置?

So I have the question - How i can analyze this matrix in Prolog. I read something about min-max algorithm, but i can't realize this in Prolog. Can anyone helps or show the direction how to make work min max algorithm with my matrix and current positions in Prolog?

推荐答案

我不知道是否最小 - 最大引出好的结果TRON。由于在网格人有 通常很多交换动作,吹起来的搜索空间。也许一个小 场和/或一个小的搜索深度。但是你可以尝试使用否定为失败 为最小 - 最大,你会得到阿尔法-β修剪免费(我想是这样)。

I am not sure whether min-max leads to good result for tron. Since on a grid one has usually many commutative moves, blowing up the search space. Maybe for a small field and/or a small search depth. But you could try to use negation as failure for min-max and you get alfa-beta pruning for free (I guess so).

在不确定性游戏最小 - 最大算法计算的最小对手增益应该对手,另一方面试图最大化其收益。让我的范围在球员的动作和j了对手的动作。这导致一个递归式如下:

In games without uncertainty the min-max algorithm computes the minimal opponent gain supposed the opponent on the other hand tries to maximize his gain. Let i range over the players moves and j over the opponent moves. This leads to a recursive formula as follows:

Worst-Opponents-Gain = min_i (max_j ( Worst-Opponents-Gain_i_j) )

由于我们处理一个零和博弈的对手增益为我们的胜利。所以,我们有反对者增益= - 赢。我们可以重新制定了最小 - 最大搜索到max的搜索。每个球员是一个最大化。

Since we deal with a zero sum game the opponents gain is our win. So that we have Opponents-Gain = - Win. We can re-formulate the min-max search into a max search. Each player is a maximizer.

Best-Win = max_i ( - Best-Win_i).

当你赢值的范围是{-1,0,1}那么你可以使用否定为失败。只实现 以下predicates模拟游戏:

When your win values are in the range {-1, 0, 1} then you can use negation as failure. Just implement the following predicates to model your game:

% move(+Board,+Player,-Board)  
% init(+Board)  
% win(+Board,+Player)  
% oposite(+Player,-Player)  
% tie(+Board,+Player)

以上predicates将在参数完全模拟游戏,因此游戏的状态将被存储在一个局部变量。本场比赛又被分析通过以下predicate:

The above predicates will model the game completely in the Arguments, thus a game state will be stored in a local variable. The game is then "analyzed" via the following predicate:

% best(+Board,+Player,-Board)  
best(X,P,Y) :-  
  move(X,P,Y),  
  (win(Y,P) -> true;  
    oposite(P,Q),  
    \+ tie(Y,Q),  
    \+ best(Y,Q,_)).

您可能需要添加额外的参数,以限制搜索的深度,或返回 的举动象征repesentation。

You might want to add additional parameters to limit the search depth, or to return a symbolic repesentation of the move.

再见

P.S:你会找到一个井字棋例如<一href="http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/15_stdy/06_bench/09_programs/06_tictac/package.html"相对=nofollow>这里。

P.S.: You find a tic-tac-toe example here.

这篇关于特隆lightcycles AI在序言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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