Skip to content
Snippets Groups Projects
Commit 2536b015 authored by Xuan Trinh's avatar Xuan Trinh
Browse files

Add the move selection logic to add to Queue for expanding using either DFS or...

Add the move selection logic to add to Queue for expanding using either DFS or BDF. i need to stop to wait for we come to argee on how we want to store the block, the move. Before i can continue check for move collision and avoiding block
parent 19d1d3f2
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
"""
logic:
-> prioritise the action which take the token closer to its target
"""
from search.method import distance_between
from search.movement_logic import slide_right, slide_left, slide_up_left, slide_up_right, slide_down_left, \
slide_down_right
def add_to_queue(record, queue, token_position, target):
"""
:argument record: the tile that current token already pass by
:param queue: tile a wait to be process.
:param token_position: current position
:param target: where the token want to go
:return:
-> check the adjcent tile and weight them {prioritise the tile close to the target first}
-> append them to the queue in that order
"""
#add all the adjcent move to queue
appending_list = add_adjcent_action(record, token_position, target)
#sort the list base on the how close it is to target
appending_list.sort(key = (lambda x: distance_between(x, target)))
#add the list to the head to the queue
appending_list.extend(queue)
return appending_list
def add_if_new_tile(record, list, tile, target):
"""
handle check if the tile has been seen by the token before
we only add after we expand the node
:param record: log all move of the token while moving toward the target.
:param list: the temporary list to append to while await to process
:param tile: the adjcent tile of a token
:return: the list so the local change can be pass to higher scope
"""
if not tile in record or (record[tile] != target):
list.append(tile)
return list
def add_adjcent_action(record, token_position, target):
"""
create a abstraction to hide implementation detail on how to add adjcent move
:param record: ensure add the move we have not seen
:param token: current position of the token
:param target: where the token want to get to
:return: the queue
"""
appending_list = []
# check the right tile
appending_list = add_if_new_tile(record, appending_list, slide_right(token_position), target)
# check the left tile
appending_list = add_if_new_tile(record, appending_list, slide_left(token_position), target)
# check the up_left
appending_list = add_if_new_tile(record, appending_list, slide_up_left(token_position), target)
# check the up_uight
appending_list = add_if_new_tile(record, appending_list, slide_up_right(token_position), target)
# check the down_left
appending_list = add_if_new_tile(record, appending_list, slide_down_left(token_position), target)
# check the down_right
appending_list = add_if_new_tile(record, appending_list, slide_down_right(token_position), target)
return appending_list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment