SE250:lab-X:stsa027

From Marks Wiki
Jump to navigation Jump to search

Followed instructions. Used cmd to run the code with 'make' followed by 'search' after I changed the goal and current state to have 9 elements in them, instead of 15.


Task One

Number of different states = 9!

Guessing number of edges = 8! Because the last layer does not give any more edges... this assumes that each state only has one edge going to it (if the state has already been seen, other states don't go to it anymore).


Task Two

First few lines creates some instance variables, which are then initialised with some init_ functions.

Then, the initial state (start) is recorded in both OrderedStateList and StateSet.

While loop block:

Condition is: loop as long as ordered state list is not empty... which means it'll never stop looping

while( ! is_empty_OrderedStateList( &open ) )

If the last state in the ordered state list is the goal state, then change "success = true", and break.

    if( same_state( &s, goal ) ) {
      success = true;
      break;

Otherwise, find the children of the current state, and for each of the children, determine whether the children is already known by attempting to add it to StateSet (returns false if the state is already present in StateSet). If the state is not already present in the StateMap, then ... and add it to the OrderedStateList.

    } else {
      int i, n_children;
      State* cs = get_children( &s, &n_children );
      for( i = 0; i < n_children; i++ )
	if( add_to_StateSet( &visited, &cs[ i ] ) ) {
	  /* we have not yet seen this state */
	  put_StateMap( &path_map, &cs[ i ], &s );
	  add_to_OrderedStateList( &open, &cs[ i ] );
	}


Moving on to next task at 11:22am.

Task Three