Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:23:13+00:00 2026-05-25T13:23:13+00:00

While running a best-first search from M Tim Jones’ Artificial Intelligence: A Systems Approach

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:23:14+00:00Added an answer on May 25, 2026 at 1:23 pm

    test_t is a structure. The author of code is initializing the tests array with an array of initialized structures. In C, you can initialize a structure like this;

    struct t {
         int num1;
         double num2;
    };
    
    struct t my_struct = { 123, 3.141 };
    

    If I wanted to initialize an array of struct t’s, then I could do something like this:

    struct t my_array[] = {
        {123, 3.141},
        {3245, 6.2156},
        {912, 5.3},
        {0, 1.0}
    };
    

    For the BFS stuff, Best first search is a purely heuristical combinatorial search algorithm. This means that at any given node in your graph, you will choose the successor that is the most optimal. Optimal could be least cost or most cost. node_t looks like a generic C structure to support A*, BFS, and Dijkstra search algorithms. This is why the h member variable of the node_t structure is ignored–it’s not used in BFS.

    evaluateBoard() is evaluating the cost of the node_t position by going through the entire list of tests. The y value isn’t chosen, you are merely evaluating the cost of the node so that later you can choose the most optimal successor move in the algorithm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While running through the cheat sheet create a navigation rule for the Eclipse JavaServer
While running a batch file in Windows XP I have found randomly occurring error
While running my application (which does a good bit of custom drawing) I get
I get numerous method redefined warnings while running an application under Merb 0.9.3. Of
How to hide cmd window while running a batch file? I use the following
I'm getting an Undefined Instruction error while running an embedded system, no coprocessor, no
I wish to automatically enter a password while running an install script. I have
I am getting the following error while running my MVC application, which uses the
I am getting he following Exception while running my Quartz Schdular program. Below is
hi i am getting the following exception while running my application and my applicationContext.xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.