Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set array to {{"C", "A", "X", "L", "A", "Q", "B", "H", "Z", "X"}, {"E", "K", "M", "P", "Z", "D", "W", "B", "V", "B"}, {"O", "L", "P", "A", "N", "A", "N", "A", "B", "I"}, {"L", "L", "O", "K", "K", "Y", "S", "H", "Q", "Y"}, {"E", "K", "E", "R", "L", "W", "T", "Q", "E", "L"}, {"G", "I", "X", "O", "E", "R", "J", "K", "C", "Z"}, {"B", "J", "P", "D", "A", "S", "R", "U", "N", "X"}, {"M", "M", "W", "E", "E", "I", "S", "F", "A", "E"}, {"E", "S", "P", "Q", "U", "F", "P", "A", "D", "R"}, {"Z", "Y", "L", "C", "V", "V", "G", "Y", "C", "X"}}
- set word_bank to {"APPLE", "BANANA", "CASSEROLE", "DANCE", "EARTH"}
- my main(array, word_bank)
- on main(array, word_bank)
- set x_quantity to (count items of array)
- set y_quantity to (count lists of array)
- set array_quantity to (x_quantity * y_quantity)
- set selected_x to 1
- set selected_y to 1
- set selected_word to 1
- set selected_character to 1
- repeat array_quantity times
- set selected_item to (item selected_x of (list selected_y of array))
- set valid_positions to (my find_valid_positions(selected_x, selected_y, x_quantity, y_quantity))
- set current_word to (item selected_word of word_bank)
- repeat with selected_valid_position from 1 to (count valid_positions)
- set current_valid_position to (item (item 1 of (item selected_valid_position of valid_positions)) of (list (item 2 of (item selected_valid_position of valid_positions)) of array))
- if current_valid_position = (character selected_character of current_word) then
- display dialog current_valid_position & "; true"
- else
- display dialog current_valid_position & "; false"
- end if
- end repeat
- # display dialog selected_item & return & "x: " & selected_x & ", y: " & selected_y
- set selected_x to (selected_x + 1)
- if (((selected_x - 1) mod (count items of array)) = 0) then
- set selected_y to (selected_y + 1)
- set selected_x to 1
- end if
- end repeat
- end main
- on find_valid_positions(x, y, x_quantity, y_quantity)
- set t to {x, (y - 1)}
- set tr to {(x + 1), (y - 1)}
- set r to {(x + 1), y}
- set br to {(x + 1), (y + 1)}
- set b to {x, (y + 1)}
- set bl to {(x - 1), (y + 1)}
- set l to {(x - 1), y}
- set tl to {(x - 1), (y - 1)}
- set positions to {t, tr, r, br, b, bl, l, tl}
- set valid_positions to {}
- repeat with selected_position from 1 to (count positions)
- if (((item 1 of (item selected_position of positions)) > 0) and ((item 1 of (item selected_position of positions)) < (x_quantity + 1)) and ((item 2 of (item selected_position of positions)) > 0) and ((item 2 of (item selected_position of positions)) < (y_quantity + 1))) then
- set valid_positions to (valid_positions & {item selected_position of positions})
- end if
- end repeat
- return valid_positions
- end find_valid_positions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement