COMP3411/9814 Artificial Intelligence

COMP3411/9814 Artificial Intelligence

Term 1, 2025

Assignment 1 – Search, Pruning and Treasure Hunting

Due: Friday 21 March, 10pm

Marks: 25% of final assessment

In this assignment you will be examining search strategies for the 15-puzzleand pruning in alpha-beta search trees. You will also implement an AI strategy for an agent to play a text-based adventure game. You should provide

answers for Questions 1 to 3 (Part A) in a written report, and implementyour agent to interact with the provided game engine (Part B).

Note: Parts A and B must be submitted separately ! Submission detailsare at the end of this specification.

Part A: Search Strategies and Alpha-Beta Pruning

Question 1: Search Strategies for the 15-Puzzle (2 marks)

For this question you will construct a table showing the number of statesexpanded when the 15-puzzle is solved, from various starting positions, usinfour different search strategies:

Run each of the four search strategies from three specified starting positions, using the following combinations of command-line arguments:

Starting Positions:

start1--start 1237-5A46-09B8-DEFCstart2:--start 134B-5287-960C-DEAFstart3:

-start 7203-16B4-5AC8-9DEF

Search Strategies:

--s astarIn each case, record in your table the number of nodes Expanded duringthe search(b) Briefly discuss the efficiency of these four search strategies.

Question 2: Heuristic Path Search for 15-Puzzle (3 marks)In this question you will be exploring a search strategy known as Heuristic Path Search, which is a best-first search using the objective function:

fw(n) = (2 w)g(n) + wh(n), where h() is an admissible heuristic and w is a number between 0 and 2.

Heuristic Path Search is equivalent to Uniform Cost Search when w = 0,

to A* Search when w = 1, and Greedy Search when w = 2. It is Complete

for all w between 0 and 2.

(a) Prove that Heuristic Path Search is optimal when 0 w 1.

Hint: show that minimizing f(n) = (2 w)g(n) + wh(n) is the same

as minimizing f (n) = g(n) + h (n) for some function h (n) with theproperty that h (n) h(n) for all n.

2(b) Draw up a table in this format (the top row has been filled in for you):Starting Positions: start4:--start 8192-6DA4-0C5E-B3F7

start5:--start 297F-DEB4-A601-C385

start6:--start F5B6-C170-E892-DA34Search Strategies: 代写COMP3411/9814 Artificial IntelligenceIn each case, record in your table the length of the path that was found,and the number of nodes Expanded during the search. Include the completed table in your report.

(c) Briefly discuss the tradeoff between speed and quality of solution forHeuristic Path Search with different values of w.

3Question 3: Game Trees and Pruning (4 marks)

(a) The following game tree is designed so that alpha-beta search will prune

as many nodes as possible. At each node of the tree, all the leaves in theleft subtree are preferable to all the leaves in the right subtree (for theplayer whose turn it is to move).MAXMINMAXMIN10 11 8 9 1314 12 2 3 0 1 6 7 4 5 15Trace through the alpha-beta search algorithm on this tree, showing thevalues of alpha and beta at each node as the algorithm progresses, andclearly indicate which of the original 16 leaves are evaluated (i.e. not

pruned).(b) Now consider another game tree of depth 4, but where each internal node

has exactly three children. Assume that the leaves have been assignein such a way that alpha-beta search prunes as many nodes as possible.Draw the shape of the pruned tree. How many of the original 81 leaveswill be evaluated?Hint: If you look closely at the pruned tree from part (a) you will seea pattern. Some nodes explore all of their children; other nodes exploreonly their leftmost child and prune the other children. The path downthe extreme left side of the tree is called the line of best play or PrincipalVariation (PV). Nodes along this path are called PV-nodes. PV-nodesexplore all of their children. If we follow a path starting from a PV-nodebut proceeding through non-PV nodes, we see an alternation betweennodeswhichexplore all of their children, and those which explore onlyone child. By reproducing this pattern for the tree in part (b), you shouldbe able to draw the shape of the pruned tree (without actually assigningvalues to the leaves or tracing through the alpha-beta search algorithm).

(c) What is the time complexity of alpha-beta search, if the best move isalways examined first (at every branch of the tree)? Explain why.

4Part B: Treasure Hunt (16 marks)For this part you will be implementing an agent to play a simple text-basedadventure game. The agent is considered to be stranded on a small group ofislands, with a few trees and the ruins of some ancient buildings. The agentis required to move around a rectangular environment, collecting tools andavoiding (or removing) obstacles along the way.

The obstacles and tools within the environment are represented as follows:nding on which direction it is pointing. The agent is capable of thefollowing nstructions:

L turn left

R turn rightF (try to) move forwardU (try to) unlock a door, using an keyC (try to) chop down a tree, using an axeB (try to) blast a wall, tree or door, using dynamite

When it executes an L or R instruction, the agent remains in the samelocation and only its direction changes. When it executes an F instruction,the agentattempts to move a single step in whichever direction it is pointing.

The F instruction will fail (have no effect) if there is a wall or tree directlyin front of the agent.

When the agent moves to a location occupied by a tool, it automaticallpicks up the tool. The agent may use a C, U or B instruction to remove anobstacle immediately in front of it, if it is carrying the appropriate tool. Atree may be removed with a C (chop) instruction, if an axe is held. A doormay beremoved with a U (unlock) instruction, if a key is held. A wall, treeor door may be removed with a B (blast) instruction, if dynamite is held.Whenever a tree is chopped, the tree automatically becomes a raft which theagent can use as a tool to move across the water. If the agent is not holdingaraft and moves forward into the water, it will drown. If the agent is holding araft, it can safely move forward into the water, and continue to move around

on the water, using the raft. When the agent steps back onto the land, the

aft it was using will sink and cannot be used again. The agent will need tochop down another tree in order to get a new raft.5If the agent attempts to move off the edge of the environment, it dies.To win the game, the agent must pick up the treasure and then return to itsinitial location.nter Action(s):This allows you to play the role of the agent by typing commands at the

keyboard (followed by <Enter>). Note:

  • a key can be used to open any door; once a door is opened, it has effectively been removed from the environment and can never be “closed”again.
  • an axe or key can be used multiple times, but each dynamite can beused only once.

C, U or B instructions will fail (have no effect) if the appropriate toolis not held, or if the location immediately in front of the agent doesnot contain an appropriate obstacle.

6Running in Network Mode

Follow these instructions to see how the game runs in network mode:

  1. open two windows, and cd to the src directory in both of them.
  2. choose a port number between 1025 and 65535 – let’s suppose you

choose 31415.

  1. type this in one window:

java Raft -p 31415 -i s0.in

  1. type this in the other window:

java Agent -p 3141In network mode, the agent runs as a separate process and communicateswith the game engine through a TCPIP socket. Notice that the agent cannotsee the whole environment, but only a 5-by-5 “window” around its currentlocation, appropriately rotated. From the agent’s point of view, locations off

the edge of the environment appear as a dot.We have also provided a C version of the agent, which you can run by typingmake./agent -p 31415

Writing an Agent At each time step, the environment will send a series of 24 characters to the

agent, constituting a scan of the 5-by-5 window it is currently seeing; theagent must send back a single character to indicate the action it has chosen.

You are free to write the agent in any language of your choosing.

  • If you are coding in Java, your main file should be called Agent.java(you are free to use the supplied file Agent.java as a starting point)
  • If you are coding in Python, your main file should be called agent.py(you are free to use the supplied file agent.py as a starting point) andthe first line should specify the version of Python you are using, e.g#!/usr/bin/python37• If you are coding in C, you are free to use the files agent.c, pipe.cand pipe.h as a starting point. You must include a Makefile withyour submission which, when invoked with the command “make”, willproduce an executable called agent.
  • In other languages, you will have to write the socket code for yourself.

You may assume that the specified environment is no larger than 80 by 80,

but the agent can begin anywhere inside it.dditional examples of input environments can be found in the directory

https://www.cse.unsw.edu.au/~cs3411/25T1/hw1raft/sample(or download it from here).

Question

At the top of your code, in a block of comments, you must provide a briefanswer (one or two paragraphs) to this Question:Briefly describe how your program works, including any algorithms and data structures employed, and explain any design decisions you made along the way.

Submission Parts A and B should be submitted separately.You should submit your report for Part A by typinggive cs3411 hw1a hw1a.pdf

You should submit your code for Part B by typinggive cs3411 hw1raft ...(Replace ... with the names of your submitted files)You can submit as many times asyou like – later submissions will overwriteearlierones. You can check that your submission has been received by usingone of this command:3411 classrun -check

The submission deadline is Friday 21 March, 10 pm.

8A penalty of 5% will be applied to the mark for every 24 hours late after thedeadline, up to a maximum of 5 days (in accordance with UNSW policy).Additional information may be found in the FAQ and will be considered aspart of thespecification for the project. Questions relating to the project

can also be posted to the course Forums. If you have a question that hasnot already been answered on the FAQ or the Forums, you can email ittocs3411@cse.unsw.edu.auPlease ensure that you submit the source files and NOT any binary files. Thegive system will compile your program using your Makefile and check thatit produces a binary file (or java class files) with the correct name.

Assessment

Your program will be tested on a series of sample inputs with successively

more challenging environments. There will be:

  • 10 marks for functionality (automarking)
  • 6 marks for Algorithms, Style, Comments and answer to the QuestionYou should always adhere to good coding practices and style. In general,

a program that attempts a substantial part of the job but does that partcorrectly will receive more marks than one attempting to do the entire jobbut with many errors.

Plagiarism Policy Group submissions will not be allowed. Your program

must be entirely your own work. Plagiarism detection software will be useto compare all submissions pairwise (including submissions for similar assignments in previous years, if applicable) and serious penalties will be appliedincluding an entry on UNSW’s plagiarism register.You are also not allowed to submit code obtained with the help of ChatGPT,Claude, GitHub Copilot, Gemini or similar automatic tools.

  • Do not copy code from others; do not allow anyone to see your code.
  • Do not copy code from the Internet; do not develop or upload your owcode on a publicly accessible repository.

Code generated by ChatGPT, Claude, GitHub Copilot, Gemini and

similar tools will be treated as plagiarism.Please refer to the on-line resources to help you understand what plagiarismis and how it is dealt with at UNSW:

  • Academic Integrity and Plagiarism
  • UNSW Plagiarism PolicyGood luck9
posted @ 2025-03-29 20:12  OHIOT  阅读(30)  评论(0)    收藏  举报