From 7278e00ed1baf37d9c4d751a38ac9d6e1ab35b9e Mon Sep 17 00:00:00 2001 From: gfuse Date: Tue, 16 Jan 2024 12:44:36 +0100 Subject: [PATCH] corrected the mentioned issues --- knight/main.py | 12 +++++++----- knight/player.py | 6 +++--- run.sh | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/knight/main.py b/knight/main.py index 77b24f6..5f579b9 100644 --- a/knight/main.py +++ b/knight/main.py @@ -5,12 +5,14 @@ def main(): prog='Knight', description='', epilog='') - parser.add_argument('-x', '--x_pose', help='Destination X between 0 and 8', type=int, required=True) - parser.add_argument('-y', '--y_pose', help='Destination Y between 0 and 8', type=int, required=True) - parser.add_argument('-n', '--image_name', help='Destination Y between 0 and 8', type=str, required=True) + parser.add_argument('-ix', '--x_init', help='Initial X between 0 and 7', type=int, required=True) + parser.add_argument('-iy', '--y_init', help='Initial Y between 0 and 7', type=int, required=True) + parser.add_argument('-fx', '--x_des', help='Destination X between 0 and 7', type=int, required=True) + parser.add_argument('-fy', '--y_des', help='Destination Y between 0 and 7', type=int, required=True) + parser.add_argument('-n', '--image_name', help='the name of the output file', type=str, required=True) args = parser.parse_args() - player = Player() - player.find_paths(destination=(args.x_pose,args.y_pose)) + player = Player(pose=(args.x_init, args.y_init)) + player.find_paths(destination=(args.x_des,args.y_des)) player.plot_paths(name=args.image_name) if __name__ == '__main__': diff --git a/knight/player.py b/knight/player.py index 32293c2..e880bca 100644 --- a/knight/player.py +++ b/knight/player.py @@ -3,8 +3,8 @@ import logging from graphviz import Digraph, render class Player(Cell): - def __init__(self) -> None: - super().__init__() + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) self.destination = None self.paths = [] self.depth = 0 @@ -21,7 +21,7 @@ class Player(Cell): def find_paths(self, destination: tuple = (0, 0)): self.destination = Cell(pose=destination) if self.destination.pose[0] < 0 or self.destination.pose[1] > 8 or self.destination.pose[0] < 0 or self.destination.pose[1] > 8: - logging.error("Invalid destination position: it should be between 0 and 8") + logging.error("Invalid destination position: it should be between 0 and 7") return while len(self.paths) < 1: self.depth += 1 diff --git a/run.sh b/run.sh index c3f8611..5e1318a 100755 --- a/run.sh +++ b/run.sh @@ -3,4 +3,4 @@ if [ $1 == "build" ]; then docker build -f Dockerfile -t knight:0.0 . fi echo "Run Knight ..."; -docker run -t -v ${PWD}:/app:rw --name knight knight:0.0 knight -x $2 -y $3 -n $4 \ No newline at end of file +docker run --rm -t -v ${PWD}:/app:rw --name knight knight:0.0 knight -ix $2 -iy $3 -fx $4 -fy $5 -n $6 \ No newline at end of file