Coding Hill Climbing Create a python program called queens_hc.py that takes in one parameter from the command line: an i
Posted: Sun Jul 03, 2022 12:01 pm
Coding Hill Climbing
Create a python program called queens_hc.py that takes in oneparameter from the command line: an integer. This integer willindicate the number of puzzles it will have to solve. Run it likeso (for example, to solve 5 random puzzles):queens_hc.py 5. Followthe directions/advice below:
1. The program should generateas many 8-queens initialstates(boards) as the num-ber from the command line indicates. Eachstate should be represented by a list with 8 elements. Each elementindicates the position of a queen in a column. For example: [8, 2,5, 1, 3, 4, 7, 6] represents the following board:
2.
queens.py, should have the following functions named exactly asfollows:
heuristic(board) that takes a board (state) as described aboveand
returns the number of attacking queens (directly andindirectly).
find_best_successor(board) that will explore all possible suc-cessors of a board by altering the position of each queen, onespace at a time along its colum. best_successor should explore 56boards and return two values: The best board and its heuristic.
find_solution_HC(board) implements hill climbing. Returns thefinal board, the number of iterations, and the heuristic of theboard in a list.
Use the skeleton here http://fid.cl/courses/ai/hw/queens_hc. pyto get you started. Also, if this program prints “True” under the“Tests” section, you are likely on the right track. (AKA. you willget a C or better for sure).
MUST HAVE
You must type your answers to the first task. Model it after thepseudo code on the slides. You can use the followingstatements:for, if, else, while and auxiliary functions such asmax, min, cool_down,select_best and the like.
TheanswerstothefirsttaskmustbeinaPDFdocumenttitledalgorithms.pdf.
You must have only ONE python file called queens_hc.py that canread di- rectly from the command line. It should not ask the userfor a number. For example, to test 350 puzzles you could invoke theprogram as follows:
You must comply with the guidelines for python listed in thenext section. All comments marked TODO must be dealt with
8 Mi 7 6 5 + 2 1 w 1 2 3 4 5 6 7 8
Create a python program called queens_hc.py that takes in oneparameter from the command line: an integer. This integer willindicate the number of puzzles it will have to solve. Run it likeso (for example, to solve 5 random puzzles):queens_hc.py 5. Followthe directions/advice below:
1. The program should generateas many 8-queens initialstates(boards) as the num-ber from the command line indicates. Eachstate should be represented by a list with 8 elements. Each elementindicates the position of a queen in a column. For example: [8, 2,5, 1, 3, 4, 7, 6] represents the following board:
2.
queens.py, should have the following functions named exactly asfollows:
heuristic(board) that takes a board (state) as described aboveand
returns the number of attacking queens (directly andindirectly).
find_best_successor(board) that will explore all possible suc-cessors of a board by altering the position of each queen, onespace at a time along its colum. best_successor should explore 56boards and return two values: The best board and its heuristic.
find_solution_HC(board) implements hill climbing. Returns thefinal board, the number of iterations, and the heuristic of theboard in a list.
Use the skeleton here http://fid.cl/courses/ai/hw/queens_hc. pyto get you started. Also, if this program prints “True” under the“Tests” section, you are likely on the right track. (AKA. you willget a C or better for sure).
MUST HAVE
You must type your answers to the first task. Model it after thepseudo code on the slides. You can use the followingstatements:for, if, else, while and auxiliary functions such asmax, min, cool_down,select_best and the like.
TheanswerstothefirsttaskmustbeinaPDFdocumenttitledalgorithms.pdf.
You must have only ONE python file called queens_hc.py that canread di- rectly from the command line. It should not ask the userfor a number. For example, to test 350 puzzles you could invoke theprogram as follows:
You must comply with the guidelines for python listed in thenext section. All comments marked TODO must be dealt with
8 Mi 7 6 5 + 2 1 w 1 2 3 4 5 6 7 8