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

I did not decide when to terminate if there are no possible path to the...

I did not decide when to terminate if there are no possible path to the target{since the piece dont know if it can get to its target or not, it just move}
parent 8eee33b7
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
"""
:argument coordinate - a tuple contain 2 number (r, q)
:pram coordinate a tuple contain 2 number (r, q)
:return coordinate of the token after the action is complete
if the new position is out of the board:
return the token'
......@@ -19,12 +19,14 @@ Slide action logic:
# '-._.-'-._.-'
#
"""
from typing import Tuple
ROW = 0
COLUMN = 1
# 1
def slide_left(coordinate: tuple[int, int]) -> tuple[int, int]:
def slide_left(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW], coordinate[COLUMN] - 1)
......@@ -32,13 +34,13 @@ def slide_left(coordinate: tuple[int, int]) -> tuple[int, int]:
return coordinate
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
# 2
def slide_right(coordinate: tuple[int, int]) -> tuple[int, int]:
def slide_right(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW], coordinate[COLUMN] + 1)
......@@ -47,14 +49,13 @@ def slide_right(coordinate: tuple[int, int]) -> tuple[int, int]:
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
# 3
def slide_up_left(coordinate: tuple[int, int]) -> tuple[int, int]:
new_pos = ()
def slide_up_left(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW] + 1, coordinate[COLUMN] - 1)
......@@ -63,13 +64,13 @@ def slide_up_left(coordinate: tuple[int, int]) -> tuple[int, int]:
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
# 4
def slide_up_right(coordinate: tuple[int, int]) -> tuple[int, int]:
def slide_up_right(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW] + 1, coordinate[COLUMN])
......@@ -78,13 +79,13 @@ def slide_up_right(coordinate: tuple[int, int]) -> tuple[int, int]:
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
# 5
def slide_down_left(coordinate: tuple[int, int]) -> tuple[int, int]:
def slide_down_left(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW] - 1, coordinate[COLUMN])
......@@ -93,13 +94,13 @@ def slide_down_left(coordinate: tuple[int, int]) -> tuple[int, int]:
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
# 6
def slide_down_right(coordinate: tuple[int, int]) -> tuple[int, int]:
def slide_down_right(coordinate: Tuple[int, int]) -> Tuple[int, int]:
if coordinate:
new_pos = (coordinate[ROW] - 1, coordinate[COLUMN] + 1)
......@@ -108,7 +109,7 @@ def slide_down_right(coordinate: tuple[int, int]) -> tuple[int, int]:
else:
print("Empty coordinate")
return
return -10, -10
return new_pos
......@@ -159,7 +160,7 @@ Swing action logic:
"""
def swing_to_tile_1(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, int]:
def swing_to_tile_1(piece: Tuple[int, int], x: Tuple[int, int]) -> Tuple[int, int]:
position = get_relative_position(piece, x)
new_position = ()
if position == LEFT:
......@@ -188,7 +189,7 @@ def swing_to_tile_1(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, in
return new_position
def swing_to_tile_2(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, int]:
def swing_to_tile_2(piece: Tuple[int, int], x: Tuple[int, int]) -> Tuple[int, int]:
position = get_relative_position(piece, x)
new_position = ()
......@@ -218,7 +219,7 @@ def swing_to_tile_2(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, in
return new_position
def swing_to_tile_3(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, int]:
def swing_to_tile_3(piece: Tuple[int, int], x: Tuple[int, int]) -> Tuple[int, int]:
position = get_relative_position(piece, x)
new_position = ()
......@@ -248,7 +249,7 @@ def swing_to_tile_3(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, in
return new_position
def get_relative_position(piece: tuple[int, int], x: tuple[int, int]) -> tuple[int, int]:
def get_relative_position(piece: Tuple[int, int], x: Tuple[int, int]) -> int:
"""
:param x: the adjacent game object
:argument piece: the selected game object that is presented by its position on board { (row, column)}
......@@ -281,17 +282,16 @@ def get_relative_position(piece: tuple[int, int], x: tuple[int, int]) -> tuple[i
return DOWN_RIGHT
def compare_tile(tile1: tuple[int, int], tile2: tuple[int, int]) -> bool:
def compare_tile(tile1: Tuple[int, int], tile2: Tuple[int, int]) -> bool:
"""
:param tile2: compose of (row, column)
:param tile1: compose of (row, column)
:return true if both of the row and column are matches between 2 tiles
"""
return tile1[ROW] == tile2[ROW] \
and tile1[COLUMN] == tile2[COLUMN]
return tile1[ROW] == tile2[ROW] and tile1[COLUMN] == tile2[COLUMN]
def check_within_board(tile: tuple[int, int]) -> bool:
def check_within_board(tile: Tuple[int, int]) -> bool:
"""
ensure that the tile is exist within the board
:param tile: coordinate of the tile
......@@ -310,7 +310,7 @@ def check_within_board(tile: tuple[int, int]) -> bool:
return True
def distance_between(piece: tuple[int, int], target: tuple[int, int]) -> bool:
def distance_between(piece: Tuple[int, int], target: Tuple[int, int]) -> bool:
"""
:argument piece - compose of (row, column)
:argument target - compose of (row, column)
......
"""
This module is hold all method relate to Search algorithm
"""
from typing import Dict, Set, List
from search.movement_logic import *
from search.search_algo import piece_collision
......@@ -21,7 +23,7 @@ ROW = 0
COLUMN = 1
A_WIN = 1
B_WIN = 2
DRAW = 1
DRAW = 0
MAX_DISTANCE = 10
FIRST_ENTRY = 1
RE_ENTRY = 1
......@@ -29,9 +31,9 @@ HIGHEST_RANK = 0
# Global variable:
# All the dictionary is made into global variable since all method is interact with them
upperPiecesDict: dict[str, tuple] = {}
lowerPiecesDict: dict[str, tuple] = {}
setBlocks: set[tuple, ...] = set()
upperPiecesDict: Dict[str, tuple] = {}
lowerPiecesDict: Dict[str, tuple] = {}
setBlocks = set()
targetsDict = {}
# keep track all the lower player's piece <- to ensure no two Upper piece can target only one distinguish lower piece
......@@ -41,7 +43,7 @@ targetedPiece = set()
# this help rank the action.
positionHistory = {}
board: dict[tuple:str] = {}
board: Dict[Tuple[int, int], str] = {}
'''
METHOD
'''
......@@ -89,7 +91,7 @@ def make_board():
board[block] = BLOCK
def check_valid_action(piece: str, new_position: tuple) -> bool:
def check_valid_action(piece: str, new_position: Tuple[int, int]) -> bool:
"""
check if the action is resolved successfully.
-> no piece should defeat any other piece unless the one whom it defeated is its Target.
......@@ -116,7 +118,7 @@ def check_valid_action(piece: str, new_position: tuple) -> bool:
return True
def check_in(position: tuple, piece: str):
def check_in(position: Tuple[int, int], piece: str):
"""
log each time piece visit a tile.
-> if the piece comeplete its journey {arrived at its Target's location}
......@@ -131,7 +133,7 @@ def check_in(position: tuple, piece: str):
positionHistory[piece][position] += RE_ENTRY
def rank(position: tuple, piece: str) -> int:
def rank(position: Tuple[int, int], piece: str) -> int:
"""
rank is base on how far of interested position to piece's target position
-> how ever position is will be rank lower if it is visit before
......@@ -161,7 +163,7 @@ def result_of_collision(pieceA: str, pieceB: str) -> int:
"""
pieceA = pieceA[TYPE].lower()
pieceB = pieceB[TYPE].lower()
if pieceA is LOWER_ROCK:
if pieceA == LOWER_ROCK:
if pieceB == LOWER_SCISSOR:
return A_WIN
elif pieceB == LOWER_PAPER:
......@@ -199,7 +201,7 @@ def slide_action(piece: str) -> list:
return action_list
def swing_action(piece: str) -> list:
def swing_action(piece: str) -> List[Tuple[int, int]]:
"""
for each adjacent piece there will be at most 3 swing move.
-> check those move to ensure they are valid
......@@ -257,7 +259,7 @@ def find_target(piece: str):
targetedPiece.add(target)
def make_ranked_move_list(piece: str) -> list:
def make_ranked_move_list(piece: str) -> List[Tuple[int, int]]:
"""
add all the possible position after perform an action.
sort them according to their rank{low to high}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment