15 April 2025

A-Star-Search-Assignment

by Carson Kempf


A* Search


Assignment

Goal


Specifications

Input/Output Structure

python3 src/puzzle4.py "$1" "$2"

$1

$2

Output Grading

’#’

’ ‘

‘S’

‘F’

‘T’

‘X’

Goal


Heuristic Function

Considering Mr. Toad Plans

Cost Function

cost(s)

Heuristic Function

h(s)

Graph Search Function

f(s) = cost(s) + h(s)

Note


Initial Game Board Preconditions


Input File Format

5 # number of rolls following this line
21
21
10
14
27


Output File Format

GAGAF
7
#SS SS#
# SSS #
# S S #
#S S S#
#   T #

Notes


Submission

Main File

puzzle4.py

Primer for Puzzle Assignment


Intuition

Final Implementation


Implementation

GameBoard

TransitionFunction(s,p) -> s’

Input

Output


Main Change


PseudoCode

FUNCTION River-Toad-Astar-GS
INPUT 
    s0 : the initial GameBoard
    goal(s) : boolean function that tests if the goal is true in GameBoard s.
    cost(s) : A cost function that returns the "cost" from the initial board to s.
    h(s) : A heuristic function that returns an estimate of the "cost" from s to the goal.
 
OUTPUT : a sequence of actions that takes the game from s0 to a state that satisfies the goal.

VAR frontier : Priority-Queue of sequences of actions.
               // Smallest priority value is highest priority

==============================================================================================
BEGIN
    enqueue [] (empty sequence) into frontier
    
    WHILE frontier is not empty
    
        dequeue sequence of actions p = [a0, a1, a2, ..., ak] from frontier
        // p has highest priority / smallest priority in frontier.
        
        sk ← TransitionFunction( s0, p )
        // sk is the GameBoard that results from executing p in s0
        
        IF goal(sk)
            RETURN p
            
        FOR every valid action a at sk
            px ← [a0, a1, a2, ..., ak, a]
            sx ← TransitionFunction( s0, px )
            // sx is the GameBoard that results from executing px in s0
            
            enqueue px into frontier with priority cost(sx) + h(sx)
            // cost() is the cost function
            // h() is the heuristic function
            
        ENDF
    ENDW
END.

Further Refinement