Expert answer:program 5 code

  

Solved by verified expert:please read the instructions file , then go ahead and modify the code that is being asked , so that you get the output is needed.
instructions.pdf

output.pdf

Don't use plagiarized sources. Get Your Custom Essay on
Expert answer:program 5 code
Just from $10/Page
Order Essay

the_code.pdf

Unformatted Attachment Preview

4/7/2018
CSCI 127, Program 5
Program 5: Eight Puzzle
Logistics
Due Date: Friday, April 13th no later than 11:59 p.m.
Partner Information: You may complete this assignment individually or with exactly one partner. If you
work with a partner, you must both be enrolled in the same lab section or you will both lose 10 points.
Submission Instructions: Upload your solution, renamed to YourFirstName-YourLastNamePartnerFirstName-PartnerLastName-Program5.py to the BrightSpace Program 5 Dropbox. If you
work with a partner, only one person should submit the solution.
Deadline Reminder: Once the submission deadline passes, BrightSpace will no longer accept your Python
submission and you will no longer be able to earn credit. Thus, if you are not able to fully complete the
assignment, submit whatever you have before the deadline so that partial credit can be earned.
Learning Outcomes
Utilize NumPy arrays to solve a problem.
Utilize object-oriented programming to solve a problem.
Eight Puzzle Overview
The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. It is played
on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the
blocks so that they are in order. You are permitted to slide the blank square horizontally or vertically. The
following shows a sequence of legal moves from an initial board position (left) to the goal position (right).
4
7
1
2
8
3
5
6
=>
1
4
7
2
8
3
5
6
=>
1
4
7
2
8
3
5
6
=>
initial
1
4
7
2
5
8
3
6
=>
1
4
7
2
5
8
3
6
goal
Assignment
Using program5.py as a starting point, supply the missing functions such that interaction with a user could
produce this transcript.
When the user is asked for input, the legal responses are left, right, up and down (using any combination
of uppercase and lowercase letters).
The user commands indicate how the blank space such be moved. For example, if the user enters left, the
blank space should be exchanged with the number that is located to its left. Note: if the blank space is on
the far left of the board, it can not be moved to the left.
Grading – 100 points
25 points. The method is_puzzle_solved works correctly (all or nothing).
10 points. The method move_blank works correctly when the user enters a legal left move (all or nothing).
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/
1/2
4/7/2018
CSCI 127, Program 5
10 points. The method move_blank works correctly when the user enters a legal right move (all or
nothing).
10 points. The method move_blank works correctly when the user enters a legal up move (all or nothing).
10 points. The method move_blank works correctly when the user enters a legal down move (all or
nothing).
10 points. The method move_blank works correctly when the user enters an illegal command (all or
nothing).
10 points. The output format shown in the sample transcript is matched exactly. (5 points for each type of
difference up to 10 points.)
15 points – The methods you write are properly commented, easy to understand and do not contain
unnecessary code. (3 points for each type of improvement up to 15 points.)
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/
2/2
4/7/2018
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/output.txt
Puzzle:
+-+-+-+
|1|2|3|
+-+-+-+
|4|5|6|
+-+-+-+
|7|8| |
+-+-+-+
Congratulations – you solved the puzzle in 0 steps!
Puzzle:
+-+-+-+
|4|1|3|
+-+-+-+
|7|2|5|
+-+-+-+
|8| |6|
+-+-+-+
Enter choice [up, down, left, right]: down
That move is invalid. Please try again.
Enter choice [up, down, left, right]: LEFT
+-+-+-+
|4|1|3|
+-+-+-+
|7|2|5|
+-+-+-+
| |8|6|
+-+-+-+
Enter choice [up, down, left, right]: up
+-+-+-+
|4|1|3|
+-+-+-+
| |2|5|
+-+-+-+
|7|8|6|
+-+-+-+
Enter choice [up, down, left, right]: UP
+-+-+-+
| |1|3|
+-+-+-+
|4|2|5|
+-+-+-+
|7|8|6|
+-+-+-+
Enter choice [up, down, left, right]: up
That move is invalid. Please try again.
Enter choice [up, down, left, right]: right
+-+-+-+
|1| |3|
+-+-+-+
|4|2|5|
+-+-+-+
|7|8|6|
+-+-+-+
Enter choice [up, down, left, right]: up
That move is invalid. Please try again.
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/output.txt
1/2
4/7/2018
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/output.txt
Enter choice [up, down, left, right]: Down
+-+-+-+
|1|2|3|
+-+-+-+
|4| |5|
+-+-+-+
|7|8|6|
+-+-+-+
Enter choice [up, down, left, right]: right
+-+-+-+
|1|2|3|
+-+-+-+
|4|5| |
+-+-+-+
|7|8|6|
+-+-+-+
Enter choice [up, down, left, right]: down
+-+-+-+
|1|2|3|
+-+-+-+
|4|5|6|
+-+-+-+
|7|8| |
+-+-+-+
Congratulations – you solved the puzzle in 7 steps!
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/output.txt
2/2
4/7/2018
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/program5.py
import numpy as np
#
#
#
#
#
#
#
————————————–CSCI 127, Joy and Beauty of Data
Program 5: Eight Puzzle
Your Name, Your Partner’s Name
————————————–A brief overview of the program.
—————————————
class EightPuzzle:
def __init__(self):
self.solution = np.array([1,2,3,4,5,6,7,8,” “])
self.solution = self.solution.reshape(3,3)
def __str__(self):
separator = “+-+-+-+n”
answer = separator
for row in range(3):
for col in range(3):
answer += “|” + str(self.puzzle[row][col])
answer += “|n”
answer += separator
return answer
def puzzle_1(self):
self.puzzle = np.array([1,2,3,4,5,6,7,8,” “])
self.puzzle = self.puzzle.reshape(3,3)
self.blank_x = 2
self.blank_y = 2
def puzzle_2(self):
self.puzzle = np.array([4,1,3,7,2,5,8,” “, 6])
self.puzzle = self.puzzle.reshape(3,3)
self.blank_x = 2
self.blank_y = 1
def swap_positions(self, x1, y1, x2, y2):
self.puzzle[x1][y1], self.puzzle[x2][y2] =
self.puzzle[x2][y2], self.puzzle[x1][y1]
# ————————————–# Do not change anything above this line
# ————————————–# Your solution goes here …
# ————————————–# Do not change anything below this line
# ————————————–def solve(puzzle):
steps = 0
print(“Puzzle:n”)
print(puzzle)
while not puzzle.is_puzzle_solved():
puzzle.move_blank()
print(puzzle)
steps += 1
print(“Congratulations – you solved the puzzle in”, steps, “steps!n”)
def main():
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/program5.py
1/2
4/7/2018
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/program5.py
puzzle = EightPuzzle()
puzzle.puzzle_1()
solve(puzzle)
puzzle.puzzle_2()
solve(puzzle)
# ————————————–main()
https://www.cs.montana.edu/paxton/classes/csci127/programs/program5/program5.py
2/2

Purchase answer to see full
attachment

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Order your essay today and save 30% with the discount code ESSAYSHELP