不论高手不高手,如果能够把这个东西看懂不想得分都很难

myadvice 2003-04-10 11:24:34
刚从网上认识一个大家的女孩,她告诉我她们的一道平时作业,反正我的C语言已经忘得差不多了,现在用的是Delphi,所以如果哪位想看看现在的大学怎么样看看这道题吧!按要求或者是调试正确者肯定给分,我这个人没有不结贴的习惯。

其题目要求如下:(现在学校可能升级了,连题目全都用英文了)

Modify take_e.c, the exhaustive search version of the game take, to use alpha-beta pruning and the optional argument that specifies a maximum lookahead depth.



Provide detailed inline documentation of all modifications, starting all your comments with /*! and ending them with !*/.



You will be evaluated on the

* correctness of your implementation of alpha-beta pruning

* correctness of your implementation of maximum lookahead

* quality of your functions for estimating the value of a non-terminal node

* understanding of the task demonstrated by your inline documentation



The submitted code must compile under Turbo C.


程序代码在下边,因为csdn不准贴子太长
...全文
36 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
lymgf 2003-04-12
  • 打赏
  • 举报
回复
/* if it is the best so far, remember it and its value */
if (depth==1)
{
if (this_score > alpha) move = move_codes[move_index];
if (this_score > alpha) alpha = this_score;
}
这一段忘了去掉
lymgf 2003-04-12
  • 打赏
  • 举报
回复
楼上说的不对,被评估的节点并非同时展开的,因此内存消耗只跟搜索深度相关,为线性增长。

下面是我写的alpha-beta剪枝搜索,由于不想改原程序定义的数据结构,所以写的时候总觉得别扭,另外附上do_a_move的测试函数。可以看出alpha-beta剪枝有效减少了评估的节点,但是到7*7的棋盘时,显得力不从心。如果增加其他搜索手段,如历史启发、备忘录等,可能可以对7*7搜索到根,也就不用估值函数。若棋盘继续加大,就必须限制搜索深度,这时估值函数显得极为重要,个人认为这才是最难点,就不费心写了。

/*
**alpha-beta pruning 返回评估值
*/
char move; //增加一个全局变量,表示最佳解

int alpha_beta(position_type *pos,int alpha,int beta,int depth)
{
int this_score; /* the score of the move being considered */
int move_index; /* the move to check */
position_type posn = *pos; /* copy of the current position - may be modified */

no_of_nodes++;
if (finished(&posn))
{
return ((posn.player=='x')?1:-1)*posn.score;
}

/* check each of the possible moves in turn */
for (move_index = 0; move_index < NO_OF_MOVE_CODES; move_index++)
{
/* check if the move is valid */
if (valid_move(pos, move_codes[move_index]))
{
update_position(&posn, move_codes[move_index]);
/* if so, evaluate it */
this_score = -alpha_beta(&posn, -beta,-alpha,depth+1);
/* copy of the current position - may be modified */
posn = *pos;

/* if it is the best so far, remember it and its value */
if (depth==1)
{
if (this_score > alpha) move = move_codes[move_index];
if (this_score > alpha) alpha = this_score;
}
if (this_score > alpha)
{
if (depth==1) move = move_codes[move_index];
alpha = this_score;
}
if (alpha>=beta) break;
}
}

return alpha;
}

/* do a move
** updates the global data structures representing the current position
*/
void do_a_move(void)
{
int val;

no_of_nodes=0;
move = select_best_move(&position, &val);
printf("I predict a final score of %d\n", val);
printf("Consider %ld nodes.\n",no_of_nodes);
printf("E-S suggest move:%c\n",move);

no_of_nodes=0;
val=alpha_beta(&position,-20000, 20000,1);
printf("I predict a final score of %d\n", val);
printf("Consider %ld nodes.\n",no_of_nodes);
printf("A-B suggest move:%c\n",move);

update_position(&position, move);
}
myadvice 2003-04-12
  • 打赏
  • 举报
回复
楼上那两位兄弟说得正确,所以下次结分时肯定要放分给你,特别是lymgf兄,谢谢你了,下次结

分时我给你发信息。我还想知道其它人对这个程序的看法,所以暂时不能结贴,以后的兄弟们请想

lymgf兄弟一样对此程序进行分析分析就更好了。
mudsong 2003-04-11
  • 打赏
  • 举报
回复
这是道题目啊,要慢慢研究
myadvice 2003-04-11
  • 打赏
  • 举报
回复
上面那位老兄说得有理,不过当时他们的头文件全部放在include/下的,所以是这个样子的

但是这个程序应该不只这么简单,因为从题目我们可以看出有几出需要修改并且将你的做法

写在注释里。
HugeWizard 2003-04-11
  • 打赏
  • 举报
回复
俺明白也!
坐着等天亮 2003-04-11
  • 打赏
  • 举报
回复
对呀,我也看懂了,人工智能的东西嘛,给分。
lymgf 2003-04-11
  • 打赏
  • 举报
回复
代码质量不高,竟然为每一个搜索节点保存一个棋盘,要知道,博弈搜索评估的节点随深度呈几何级数增长,内存消耗极大,也就这种分枝因子不大、搜索深度不深的才能如此编码。
kajing 2003-04-11
  • 打赏
  • 举报
回复
include头文件的路径错了。
应该是:
#include <stdio.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/limits.h>
编译通过了。但是程序有错,会溢出。
78hgdong 2003-04-11
  • 打赏
  • 举报
回复
好的,让我试试.
myadvice 2003-04-11
  • 打赏
  • 举报
回复
以上几位老兄说得对是人工智能,但是我说过的,这是大学一个女孩子讲给我的,第一贴是要求,麻

烦看看要求,否则我怎么给分呢?况且这个程序调试都没通过,所以至少要把程序调试过才行嘛
tuxw 2003-04-11
  • 打赏
  • 举报
回复
太长了!
pcitman 2003-04-11
  • 打赏
  • 举报
回复
没有看不懂的,只是需要时间……以后再看
sampdoria 2003-04-11
  • 打赏
  • 举报
回复
怎么现在的学校都学这些东西,上来就这么长的程序吗?真可怕
cenphoenix 2003-04-11
  • 打赏
  • 举报
回复
@mark@
aiyinsitan 2003-04-11
  • 打赏
  • 举报
回复
ding
「已注销」 2003-04-11
  • 打赏
  • 举报
回复
呼呼啥?给分!
zhouhu 2003-04-11
  • 打赏
  • 举报
回复
晕菜
langziji 2003-04-11
  • 打赏
  • 举报
回复
这么臭的程序,谁看谁傻B。有些程序是不值得看的,还不如帮他写一个。
98440622 2003-04-11
  • 打赏
  • 举报
回复
做个标记,回去漫漫看
加载更多回复(5)

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧