Question

Random-restart hill climbing for the 8-puzzle with h2 as the heuristic function. Implement preferably in C/C++...

 Random-restart hill climbing for the 8-puzzle with h2 as the heuristic function. Implement  preferably in C/C++ if not in Java or Python. 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static bool HillClimbingRandomRestart(int[,] _state)
{
int[,] _current = _state;
int hMax = Problem.GetHeuristic(_state);
int Counter = 0;
int _h = hMax;
int[,] _best = _current;
int[,] _next = _current;
while (Counter < 100000)
{
Counter++;
if (isGoal(_current))
return true;
foreach (Move suit in Enum.GetValues(typeof(Move)))
{
_next = Problem.MoveEmptyTile(_current, suit);
if (_next == null)
continue;
_h = Problem.GetHeuristic(_next);
if (_h < hMax)
{
hMax = _h;
_best = _next;
}
}
if (_current == _best)
{
Random rnd = new Random();
int[,] _nextRandom = Problem.MoveEmptyTile(_current, (Move)rnd.Next(4));
while(_nextRandom==null)
_nextRandom = Problem.MoveEmptyTile(_current, (Move)rnd.Next(4));
_current = _nextRandom;
}
else
_current = _best;
hMax = Problem.GetHeuristic(_current);
}
return false;
}

// You can make changes in this code .

Add a comment
Know the answer?
Add Answer to:
Random-restart hill climbing for the 8-puzzle with h2 as the heuristic function. Implement preferably in C/C++...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Generate a large number of instances of the following problems: 8 × 8 Puzzle and 8-Queens...

    Generate a large number of instances of the following problems: 8 × 8 Puzzle and 8-Queens Problem and solve these problems (if possible) using different local search algorithms (Hill Climbing Algorithm, Random Restart Hill Climbing Algorithm and Simulated annealing). Measure the cost of each search and the percentage of problems solved and make a graphical representation of these values based on the optimal cost. Comment on your results. Programming language can be either Python, C++ or Java. + code comments...

  • (C++) Implement Genetic Algorithm to solve the 8-puzzle problem. Please display output.

    (C++) Implement Genetic Algorithm to solve the 8-puzzle problem. Please display output.

  • Implement message passing using hash table or dictionary that maps constant strings to function pointers in...

    Implement message passing using hash table or dictionary that maps constant strings to function pointers in java or c++ or python programming language. Provide well documented working code. Hint:Assign message names to constant strings and implement constant as keys that maps to function pointers.

  • you will implement the A* algorithm to solve the sliding tile puzzle game. Your goal is...

    you will implement the A* algorithm to solve the sliding tile puzzle game. Your goal is to return the instructions for solving the puzzle and show the configuration after each move. A majority of the code is written, I need help computing 3 functions in the PuzzleState class from the source code I provided below (see where comments ""TODO"" are). Also is this for Artificial Intelligence Requirements You are to create a program in Python 3 that performs the following:...

  • Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as...

    Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as a Constraint Satisfaction Problem, with the following guidelines: 1. Since 3 x 3 puzzles are too trivial for a computer, your program should use 4 x 4 puzzles (also known as Super Sudoku puzzles; see Figure 2 for an example). 2. The program should read a Sudoku puzzle from a text file. The user should be able to browse the file system to select...

  • Write a set of C++ programs to implement the following operations listed in the menu function...

    Write a set of C++ programs to implement the following operations listed in the menu function below. a. File: main.cpp - contains the main function b. File: arrayhw.cpp – contains the 1D array function implementations c. File: arrayhw.h – contains the 1D array function prototyped declarations d. May create other files to implement any other needed function The main menu function should display the following: Main Menu, 1D Array Functions Enter a number to choose one of the following actions:...

  • Create and implement a C++ class, RandomGenerator, that: Allocates and stores an array of random floating...

    Create and implement a C++ class, RandomGenerator, that: Allocates and stores an array of random floating point numbers between 0 and 1. The size of the array is passed into the constructor. The class contains a next() function which returns a new random number from the array every time the next() function is called (without calling rand()). Deletes any memory allocated on the heap when the class is destroyed. Note: This trick pre-calculates random numbers and saves execution time by...

  • 7. (24 pts.) Implement the following Boolean function with an 8-to-1 multiplexer, a 2-to-4-line d...

    7. (24 pts.) Implement the following Boolean function with an 8-to-1 multiplexer, a 2-to-4-line decoder, 3 x inverters and a OR-gate. (20 pts.) F(A, B, C, D, E) -2 (0,1,2,3,5,6,7,8,9,10,13,14,16,19,23,24) 7. (24 pts.) Implement the following Boolean function with an 8-to-1 multiplexer, a 2-to-4-line decoder, 3 x inverters and a OR-gate. (20 pts.) F(A, B, C, D, E) -2 (0,1,2,3,5,6,7,8,9,10,13,14,16,19,23,24)

  • C++ We are to implement 8 small additional functions and 2 helper functions to a singly...

    C++ We are to implement 8 small additional functions and 2 helper functions to a singly linked list. 1. removeSecondNode340 deletes the second node in the Linked Bag. 2. addEnd340 inserts the new node at the end of the Linked Bag. 3. getCurrentSize340Iterative counts the number of nodes in the Linked Bag iteratively. 4. getCurrentSize340Recursive counts the number of nodes in the Linked Bag recursively. Use 1 helper function: getCurrentSize340RecursiveHelper.   5. IMMEDIATE RECURSION: getCurrentSize340RecursiveNoHelper counts the number of nodes in...

  • Implement the following Boolean function with an 8 x 1 multiplexer and with variable D as its input.

    Implement the following Boolean function with an 8 x 1 multiplexer and with variable D as its input. F(A, B, C, D) = ∑m(2, 4, 6, 9, 10, 11, 15)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT