Figuring out evaluator function for best-first search

While running a best-first search from M Tim Jones' *Artificial Intelligence: A Systems Approach*, we're asked to determine how the next moves are generated and why the solution is picked. In order to do that, two code sections are stumping us: #define checkPiece( board, y )((board & (1 << (15-y))) ? 1 : 0) #define MAX_TESTS 14 #define MAX_VECTOR 4 typedef struct { unsigned char len; unsigned char vector[MAX_VECTOR]; } test_t; and const test_t tests[MAX_TESTS]={ { 4, { 0, 4, 8, 12 } }, { 4, { 1, 5, 9, 13 } }, { 4, { 2, 6, 10, 14 } }, { 4, { 3, 7, 11, 15 } }, { 2, { 8, 13 } }, { 3, { 4, 9, 14 } }, { 4, { 0, 5, 10, 15 } }, { 3, { 1, 6, 11 } }, { 2, { 2, 7 } }, { 2, { 1, 4 } }, { 3, { 2, 5, 8 } }, { 4, { 3, 6, 9, 12 } }, { 3, { 7, 10, 13 } }, { 2, { 11, 14 } } }; Both these are used in the EvaluateBoard function void evaluateBoard( node_t *node_p ) { int test, i, check; int cost = 0; for (test = 0 ; test < MAX_TESTS ; test++) { check = 0; for (i = 0 ; i < tests[test].len ; i++) { check += checkPiece( node_p->board, tests[test].vector[i] ); } if (check > 1) cost+= (check-1); } node_p->g = cost; printf(" evaluateBoard %04x = (h %d, g %d)\n", node_p->board, node_p->h, node_p->g); return; } The next move is determined by the Cost int, and is a result of the checkPiece result. In this case, board== 1288, but how is the y value chosen from `test_t tests`? Also, just what is the structure `test_t tests`? We've never seen anything similar in C code. Is it a form of multi-dimensional array?

以上就是Figuring out evaluator function for best-first search的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏