function fineTume(picked, placed) {
let to_center = {x: picked.x - wall_center.x, y: picked.y - wall_center.y}
function tune(attempt, adjust, centerCheck) {
if (checkOpen(attempt, placed)) {
picked = attempt
if (centerCheck(attempt) !== 0) {
let adjusted = adjust(attempt)
tune(adjusted, adjust, centerCheck)
}
}
}
function yCenterCheck(frame) { return frame.y - wall_center.y }
function xCenterCheck(frame) { return frame.x - wall_center.x }
if (to_center.y < 0) {
function adjust(attempt) { return Object.assign({}, attempt, {y: attempt.y + tuner}) }
tune(picked, adjust, yCenterCheck)
}
if (to_center.y > 0) {
function adjust(attempt) { return Object.assign({}, attempt, {y: attempt.y - tuner}) }
function centerCheck(attempt) { return attempt.y - wall_center.y }
tune(picked, adjust, yCenterCheck)
}
if (to_center.x < 0) {
function adjust(attempt) { return Object.assign({}, attempt, {x: attempt.x + tuner}) }
function centerCheck(attempt) { return attempt.x - wall_center.x }
tune(picked, adjust, xCenterCheck)
}
if (to_center.x > 0) {
function adjust(attempt) { return Object.assign({}, attempt, {x: attempt.x - tuner}) }
function centerCheck(attempt) { return attempt.x - wall_center.x }
tune(picked, adjust, xCenterCheck)
}
return picked
}