0% found this document useful (0 votes)
92 views3 pages

AI Programming Assignment: Rubik's Cube

The document outlines the first programming assignment for the Artificial Intelligence course at FAST-NUCES, focusing on the Rubik's Cube and state space search. Students, in groups of up to three, are required to implement cube state representation, scramble the cube using specified moves, and compare search strategies (BFS, DFS, A*) to find the optimal solution. The assignment is due on 09/02/2025 and includes penalties for late submissions and plagiarism.

Uploaded by

Mohsin Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views3 pages

AI Programming Assignment: Rubik's Cube

The document outlines the first programming assignment for the Artificial Intelligence course at FAST-NUCES, focusing on the Rubik's Cube and state space search. Students, in groups of up to three, are required to implement cube state representation, scramble the cube using specified moves, and compare search strategies (BFS, DFS, A*) to find the optimal solution. The assignment is due on 09/02/2025 and includes penalties for late submissions and plagiarism.

Uploaded by

Mohsin Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Computer Science FAST-NUCES Lahore Campus

Artificial Intelligence

Programming Assignment No 1 (Sections CS 6A, CS 6B)


Spring 2025
Assigned on 02/02/2025 Deadline 09/02/2025 11:59 p.m.
Submission: Online on GCR Weight 4%

Instructions:

Following rules will be enforced for this assignment

 Group of at most three students (Cross-Section group formation is allowed)


 You might be asked to explain you approach and implementation details during a
detailed evaluation.
 Late submission will be allowed only if prior permission is granted
Please remember that PLAGIARISM is INTOLERABLE and anyone found involved in it will
get -4 marks (i.e. 100% penalty) in this assignment.

State Space Search


The Rubik's Cube is an important test domain for heuristic search that has 1019 possible states, making
it impossible to store in memory and solving it using exhaustive search.

For this assignment we will use that convention that a single move on a Rubik's Cube can be defined as
a quarter turn (90') of any face either clockwise or anticlockwise. Therefore there are twelve possible
moves in each state of the cube.

Part a) [Implement the Basics] [20 Points]

In this part you are required to find and implement an efficient representation of the cube state and
implement the basic functions of applying a move in a given state to generate the next state. It might be
a good idea to package the state and the functions in a class.
Department of Computer Science FAST-NUCES Lahore Campus

Artificial Intelligence

Programming Assignment No 1 (Sections CS 6A, CS 6B)


Spring 2025
Assigned on 02/02/2025 Deadline 09/02/2025 11:59 p.m.
Submission: Online on GCR Weight 4%

Part b) [Create a problem] [20 Points]

Implement a function to scramble the state using a sequence of moves that are specified in a text file.
The text file will contain an initial state of the cube on a single line followed by the moves to be applied
on this state with each successive line containing a single move consisting of a faceID and moveID pair.
The faceID will have six distinct values {F: Front, T: Top, B: Bottom, L: Left, R: Right, A: bAck} and
moveID can have two values {C: Clockwise, A: Anti-clockwise}. Implement a function that generates a
new state NS from the initial state IS by successively applying the moves to the initial state. Finally
write the new state and the initial state in a new file on two separate lines.

Write a function that scrambles a given cube state based on a sequence of moves specified in a text file.
The text file will contain the initial cube state on a single line followed by a series of moves. Each move
consists of a faceID and a moveID pair, where faceID represents one of six faces ({F: Front, T: Top, B:
Bottom, L: Left, R: Right, A: Back}) and moveID indicates the rotation direction ({C: Clockwise, A: Anti-
clockwise}). The function should iteratively apply these moves to transform the initial state into a new
state. Finally, both the resulting final and the initial states should be written to a new file creating the
problem for state-space-search algorithms.

Part c) [Solve the problem] [60 Points]

Compare the performance of three search strategies including BFS, DFS/Iterative deepening and A*
search to determine a sequence of moves that will transform the initial state into the final state using
minimum number of moves (i.e. 90' turns of faces)

Your code for this part will use the problem generated in part b (the text file containing the two states)
to search for a solution that will transform the first state into the second.

The comparison of the three search strategies must include i) the number of states expanded and ii) the
size of the queue at every instance in time while solving the problem. For the A* search strategy you
must research a good heuristic function that can guide the search effectively. You must solve multiple
problems of varying complexity to make the comparison.
Department of Computer Science FAST-NUCES Lahore Campus

Artificial Intelligence

Programming Assignment No 1 (Sections CS 6A, CS 6B)


Spring 2025
Assigned on 02/02/2025 Deadline 09/02/2025 11:59 p.m.
Submission: Online on GCR Weight 4%

Submission.
1. A folder/directory containing your code Use your University ID to name the folder
[10 Points]
2. A detailed report documenting your implementation and results obtained
[40 Points]

Common questions

Powered by AI

Generating a 'new state' involves applying a predefined sequence of moves to an initial cube configuration, which establishes the starting point and the target puzzle configuration for state-space search algorithms. This process enables the setup of a search problem where the goal is to find a sequence of moves to transform the initial (scrambled) state back to a solved state. By having both the initial and goal states defined, search algorithms like BFS, DFS, and A* can explore possible paths and solutions efficiently . This setup simulates a controlled problem environment that helps in objectively comparing the performance of different search strategies .

BFS (Breadth-First Search) expands the shallowest unexpanded nodes first, typically leading to a broader search as it explores all nodes at the present depth before moving deeper. This approach tends to have a large queue size as it needs to store all nodes at the current level before moving to the next . DFS (Depth-First Search) dives deeper into the problem space before exploring sibling nodes, which reduces its memory overhead (queue size) but may explore deeper paths that can be unnecessary for finding the shortest solution . A* Search uses a heuristic to guide the search process, aiming to find the optimal solution more efficiently by only expanding promising nodes. This means fewer states are expanded compared to BFS, but the performance heavily relies on the effectiveness of the heuristic used .

Implementing a scramble function provides a controlled means to create diverse initial states from which search algorithms must resolve the cube back to a solved state. This functionality is crucial for benchmarking, as it allows researchers to test algorithms on various starting configurations to assess their robustness, efficiency, and scalability . By standardizing the test cases from scrambled states, comparisons across different algorithms become more objective, making it easier to evaluate the effectiveness of each algorithm's approach .

Group work in this complex programming assignment encourages collaborative learning and allows students to tackle the multifaceted problem-solving process together, leveraging diverse skill sets. This can enhance idea generation, lead to more innovative solutions, and result in more efficient debugging and implementation. However, it can also lead to issues such as unequal work distribution and reliance on more skilled members, potentially impairing individual learning experiences. Thus, clear communication and responsibilities division are essential to maximize learning outcomes and ensure fair evaluation . Allowing cross-section group formation can also foster a broader perspective in approaches taken .

Documenting the 'number of states expanded' and 'queue size' provides quantifiable metrics that reflect the efficiency and resource usage of a search strategy. The number of states expanded indicates how extensively the strategy explores the state space, directly relating to its time complexity. The queue size reflects the memory overhead of the algorithm, indicating its space complexity. These metrics are crucial in evaluating and comparing the performance of algorithms, particularly in resource-constrained environments, and help in understanding trade-offs between exploration depth and computational resources usage . By analyzing these measures, researchers can better assess which strategy is optimal or feasible for solving similar or more complex problems .

The state representation of a Rubik's Cube impacts search algorithms by influencing the ease and efficiency with which operations can be performed to compute new states. An effective representation allows for efficient application of moves to generate subsequent cube states, which is crucial given the high number of potential states (10^19). If the state representation is cumbersome or inefficient, it can slow down the computation and increase the computational resources required . Proper state representation also aids in efficiently storing states and reduces the redundancy in explorations .

The challenges include the complexity of representing the cube's state in a manner that allows for efficient updates when applying moves. Since each move can alter multiple stickers on a face and affect connected sides, accurately translating a 3D move into a data structure (often 1D or 2D arrays) is non-trivial . Additionally, ensuring that the implemented moves correctly reflect real-world cube rotations (90° turns) without errors requires careful indexing and boundary condition handling . Debugging such implementations can also be complex due to the high number of possible states (10^19).

The report should comprehensively document the algorithmic approaches taken (BFS, DFS, A*), including specifics about the state representation and move application. It should detail the heuristic used for A* and justify its selection. Experimental results should be clearly presented, highlighting the performance differences among search strategies in terms of expanded states and queue sizes. Finally, the report should analyze these results, discussing the implications and potential areas for improvement or further research . Well-organized presentation and clarity in explaining complex concepts are crucial for effective communication .

Understanding heuristic functions is fundamental in A* search as these functions determine the search's efficiency and effectiveness by estimating the lowest-cost path to the goal. In state-space problems like the Rubik's Cube, a heuristic must accurately estimate the number of moves remaining without overestimating, ensuring A* maintains its optimality and completeness. A poorly designed heuristic can lead to inefficient searches, exploring many extraneous states before converging on a solution, which is computationally expensive given the cube's vast state space . Hence, a deep understanding of heuristic functions enables one to design or choose those that minimize computational resources while delivering quick solutions .

Heuristics in A* search are pivotal as they guide the search towards the goal more efficiently by estimating the cost from the current state to the goal. A well-chosen heuristic can dramatically reduce the state space that needs to be explored by prioritizing the expansion of nodes that appear to be closer to the goal . For the Rubik's Cube, a heuristic should account for the complexity and possible configurations, ideally leveraging patterns or sub-problems (such as solving layers or edge pieces first) to estimate the remaining moves to solve the cube. Developing such a heuristic involves both the analysis of possible move sequences and historical data on solving configurations efficiently .

You might also like