From a4ee4776ec17b090940838b94e15c6321ac58159 Mon Sep 17 00:00:00 2001
From: Michael Mutote <130656746+mr1Michael@users.noreply.github.com>
Date: Sun, 19 Nov 2023 16:15:55 +0100
Subject: [PATCH] 22202956 - touch up on testing functions

---
 Search_Algorithms/Heuristics.py       | 13 ++++---------
 Search_Algorithms/solution testing.py | 27 +++++++++++----------------
 2 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/Search_Algorithms/Heuristics.py b/Search_Algorithms/Heuristics.py
index ec2ebf6..6351ccc 100644
--- a/Search_Algorithms/Heuristics.py
+++ b/Search_Algorithms/Heuristics.py
@@ -3,10 +3,11 @@ import Sucessors
 
 
 def queens_opt(path):
+
     """
     Heuristic for the N-Queens problem that calculates the minimum number of moves
     required to move each queen to a position where it is not in conflict with any other queen.
-    
+
     Args:
     path (list): The path taken so far, where the last element is the current state of the N-Queens board.
 
@@ -27,7 +28,7 @@ def queens_opt(path):
                         conflict = False
                         # Check row and diagonals for conflict
                         for k in range(n):
-                            if state[y][k] == 1 and k != x:
+                            if state[y][k] and k != x:
                                 conflict = True
                                 break
                             if y + (col - x) < n and y + (col - x) >= 0 and state[y + (col - x)][col] == 1:
@@ -43,12 +44,10 @@ def queens_opt(path):
     return total_moves
 
 
-
-
 def maze_opt(path):
     """maze search heuristic going to have to use the euclidian distance, so it works for any maze"""
     state = path[-1]
-    return (is_goal.MAZE_GOAL[0] - state[0])**2 + (is_goal.MAZE_GOAL[1] - state[1])**2
+    return (is_goal.MAZE_GOAL[0] - state[0]) ** 2 + (is_goal.MAZE_GOAL[1] - state[1]) ** 2
 
 
 def puzzle_opt(path):
@@ -65,7 +64,3 @@ def sudoku_opt(path):
                       Sucessors.choose_best_column(path[-1])]
     return max(starting_point, key=lambda w: w[2])[-1]
 
-
-def queens_opt(path):
-    pass
-
diff --git a/Search_Algorithms/solution testing.py b/Search_Algorithms/solution testing.py
index 60914e7..88e09d4 100644
--- a/Search_Algorithms/solution testing.py	
+++ b/Search_Algorithms/solution testing.py	
@@ -40,7 +40,7 @@ import time
 # for rows in sln:
 #     print(rows)
 
-
+#
 # board = ((False, False, False, False, False, False, False, False, False, False),
 #          (False, False, False, False, False, False, False, False, False, False),
 #          (False, False, False, False, False, False, False, False, False, False),
@@ -57,19 +57,19 @@ import time
 # # ===============================================================================================================
 # sln = (Search_Algorithms.BreadthFirstSearch(
 #     board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])
-
+#
 # output_tuple = tuple(tuple("Q" if value else "." for value in sln)
 #                      for sln in sln)
 # for rows in output_tuple:
 #     print(rows)
 
 
-# # ===============================================================================================================
-# # BREADTH FIRST SEARCH PUZZLE PROBLEM
-# # ===============================================================================================================
+# ===============================================================================================================
+# DEPTH FIRST SEARCH N-QUEENS
+# ===============================================================================================================
 # sln = (Search_Algorithms.DepthFirstSearch(
 #     board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])
-
+#
 # output_tuple = tuple(tuple("Q" if value else "." for value in sln)
 #                      for sln in sln)
 # for rows in output_tuple:
@@ -151,20 +151,15 @@ import time
 
 
 
-board = ((False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False),
-         (False, False, False, False, False, False, False, False, False, False))
+board = ((False, False, False, False),
+         (False, False, False, False),
+         (False, False, False, False),
+         (False, False, False, False))
 
 sln = (Search_Algorithms.A_StarSearch(board, Sucessors.queens_successor,
        is_goal.is_goal_queens, Heuristics.queens_opt))[-1]
 
+print(sln)
 output_tuple = tuple(tuple("Q" if value else "." for value in sln)
                      for sln in sln)
 for rows in output_tuple:
-- 
GitLab