Highlights
Artificial Intelligence Fundamentals
Question 1 – A heuristic for Connect-4
Connect-4 is a two-person game played on a board that has seven columns, with six spaces in each column. The board is initially empty. Two players take turns dropping one piece (red or yellow in the diagram below, but X or O in our game) in a column. The piece falls into the lowest unoccupied row. A player cannot place a
piece in a column if the top-most row of that column already has a piece in it. The first player to get four of their counters in a line (either horizontally, vertically, or diagonally) is the winner. Your task for this question is to write a heuristic for the two-player game Connect-4.

You have been provided with the following two files for this problem:
minimax.lisp, which contains lisp code for the minimax algorithm, and
connect-4.lisp, which contains a working LISP implementation of the Connect-4 game.
The following LISP interaction show you how to play a game. Try it.
[1]> (load 'minimax)
;; Loading file C:\CSE2AIF\minimax.lisp ...
;; Loaded file C:\CSE2AIF\minimax.lisp T
[2]> (load connect-4)
;; Loading file C:\CSE2AIF\connect-4.lisp ...
;; Loaded file C:\CSE2AIF\connect-4.lisp
T
[3]> (play)
The program plays poorly because it has a poor-quality heuristic. The function static, which evaluates a position from the point of view of a particular player, is currently defined as follows: (defun static (board player) 0)
This means that each board configuration receives exactly the same evaluation; i.e., 0. Your task for this question is to develop and implement a better heuristic for the Connect-4 game.'
Instructions
You are required to write various LISP functions which will be used to define the heuristic. Parts (i) to (iv) ask you to define various helper functions. You will define the actual heuristic in part (v). The code that you write should be in a file named q1.lisp. Do not include any other code in this file other than any helper functions
required by the functions below.
Part (i)
Write a function get-element (board coords) that takes a board and a pair of coords representing a board position as input. The first element of the pair represents the column number and the second represents the row number (indexing starts from 0). The function returns the contents of that board position, which can
be either X, O or NIL. Using the following test board state (defparameter *test-board*
'((nil nil nil nil nil nil)
(O nil nil nil nil nil)
(X nil nil nil nil nil)
(X X O nil nil nil)
(O O X nil nil nil)
(nil nil nil nil nil nil)
(nil nil nil nil nil nil)))
the function should behave as follows: [1]> (get-element *test-board* ‘(0 0)) NIL (column 1, row 1 contains NIL) [2]> (get-element *test-board* ‘(1 0))
O (column 2, row 1 contains O) [3]> (get-element *test-board* ‘(2 0)) X (column 3, row 1 contains X) [4]> (get-element *test-board* ‘(4 2))
O (column 4, row 3 contains O)
Part (ii)
Write a function getline (board player line) that takes a board, a player and a line as input, and returns a list of length 3, where the first element of the list is the number of empty places in the line, the second element is the number of pieces that player has in the line, and the third element is the number of pieces that the opponent has in the line. You should find it useful to use get-element as a helper function. Using the same test board state as defined above, the function should behave as follows:
[5]> (getline *test-board* ‘X ‘((3 0) (3 1) (3 2) (3 3))) (1 2 1) (line contains 1 NIL, player has 2 pieces in line, and opponent has 1)
[6]> (getline *test-board* ‘O ‘((3 0) (3 1) (3 2) (3 3))) (1 1 2) (line contains 1 NIL, player has 1 piece in line, and opponent has 2)
You may wish to use the built in function count that takes and element and a list as arguments, and returns the number of occurrences of the element in the list; e.g.,
[7]> (count 1 ‘(3 2 1 4 3 1 1 3)) 3 [8]> (count ‘a ‘( c a a a b a))
Part (iii)
Write a function line-score (board player) that takes a board and player as input, and returns the line score for player. The line score is determined as follows:
if there are no pieces in the line the line score is 0;
if player has 1 piece in the line and the opponent has no pieces in the lines, the line score is 1;
if player has 2 pieces in the line and the opponent has no pieces in the lines, the line score is 2;
if player has 3 pieces in the line and the opponent has no pieces in the lines, the line score is 4;
if player has 4 pieces in the line, the line score is 1000.
You should find it useful to use getline as a helper function. Using the same test board state as defined above, the function should behave as follows:
[9]> (line-score *test-board* ‘X ‘((3 0) (3 1) (3 2) (3 3))) 0 (both players have a pieces in the line) [10]> (line-score *test-board* ‘O ‘((3 0) (3 1) (3 2) (3 3)))
0 (both players have a pieces in the line) [11]> (line-score *test-board* ‘X ‘((2 0) (3 1) (4 2) (5 3))) 4 (player has three pieces in the line and opponent doesn’t have any)
Part (iv)
Write a function board-value (board player, which takes a board and player as input, and returns the sum of line scores for player, summed over all 69 possible winning lines. To assist you, the code you have been supplied with contains a parameter *all-c4-lines* which is a list of all of the 69 possible ways to win in Connect-4. You should find it useful to use line-score as a helper function.
Part (v) – the actual heuristic function
Finally, write the function static (board player, which accepts a board and player as input arguments, and returns the board value of player, minus the board value for opponent. This is the function that will be used as the heuristic. You should find it useful to use board-value as a helper function.
Part (vi)
Play some games against the algorithm, experimenting with how the parameter *max-depth* affects the quality of the game play. Make sure that you include a *max-depth* value of 1 as one of your cases. What is the smallest value of *max-depth* for which it is difficult to beat the algorithm? Write a short paragraph summarising your findings, and include it as a commented section at the top of your source code.
Question 2 – LISP functions for a simple IR system
Your task for this question is to write LISP functions for a simple Information Retrieval (IR) system. Background – a crash course in Information Retrieval (IR)
Information retrieval is most commonly carried out using the vector space model—a common method of representing text documents. Under this model, a document dj is represented as a vector d w w w j j j jt ? ? 1 2 , ,..., where each of the t dimensions of the vector corresponds to a separate term (i.e., word). The dimensionality of
this vector is usually very high, since most languages contain a large number of words. The components of the vector indicate the weight that the word has in the document. For example, wj1 represents the weight of the word 1 in document dj, wj2 represents the weight of the word 2 in document dj, and so on. There are many
different ways of computing the weights, most of which are based on term frequency; i.e., the frequency with which that word appears in the document. Since a query is just a collection of terms, queries can be represented in the same way as documents; i.e., q w w w ? ? q q qt 1 2 , ,..., ? Since we now have two vectors represented in the same space, we can try to come up with some measure of the similarity between these vectors. A widely used measure is cosine similarity. The cosine similarity
between the above two vectors is defined as

So, to find which, of a collection of documents, is most similar to some query, we simply need to calculate the similarity between the query and each of the documents, and then rank the documents according to this similarity (i.e., most-similar to least-similar). Suppose that we had a very small vector space comprising just the three words apple, banana and carrot. Following are examples of how three documents and a query could be represented in this space. Document Vector space representation
d1: “apple banana carrot” (1, 1, 1)
d2: “apple carrot carrot” (1, 0, 2)
d3: “carrot apple carrot” (1, 0, 2)
Query Vector space representation
q: “apple” (1, 0, 0) The cosine similarity between d2 and q would be calculated as

The Task
You are required to write the following LISP functions, together with any helper functions that they require.
create-word-list (corpus)
Function create-word-list takes a list containing lists of words as input. It returns the list resulting from appending these lists together.
[1]> (create-word-list ‘((the ides of march) (the big game))) (THE IDES OF MARCH THE BIG GAME)
filter(word-list words-to-filter)
Function filter should take two lists as input: word-list and words-to-filter. The function should return the list containing all members of word-list, excluding those contained in words-to-filter. For example:
[2]> (filter '(fred barney wilma betty bambam) '(barney betty)) (FRED WILMA BAMBAM)
create-dictionary (corpus stopwords)
Function create-dictionary takes two parameters as input: corpus, which is a list of lists of words, and stopwords, which is a list of words. It should return a sorted list of all of the words appearing in corpus, omitting those that appear in stopwords. Each word should appear only once. For example:
[3]> (create-dictionary '((flintstones meet the flintstones) (a midsummer nights dream)) '(a the in at)) (DREAM FLINTSTONES MEET MIDSUMMER NIGHTS)
Note: You might find it useful to use the built-in functions sort and remove-duplicates, which are described below.
create-vector (doc) The function create-vector takes one input parameter, doc, which is assumed to be a list of words. It should return a vector (represented as a list) of the same length as *dictionary*. The returned vector should contain the term frequencies with which each word in *dictionary* appears in doc. For example, suppose that the global parameter *dictionary* evaluates to (apple banana carrot), then create-vector should behave as follows: [4]> (create-vector '(apple)) (1 0 0) [5]> (create-vector '(apple banana carrot)) (1 1 1) [6]> (create-vector '(carrot apple carrot)) (1 0 2) create-docword-index (corpus) The function create-docword-index takes one input parameter, corpus, which is assumed to be a list of lists of words. It should return a list of vectors created using create-vector (see above). For example, suppose again that the global parameter *dictionary* evaluates to (apple banana carrot), then create-docword-index should behave as follows:
[7]> (create-docword-index '((apple) (apple banana carrot) (carrot apple carrot)))
((1 0 0) (1 1 1) (1 0 2)) cos-similarity(v1 v2) Function cos-similarity should take as input two equal-length vectors (represented as lists), and should return the cosine similarity between those vectors. For example: [8]> (cos-similarity '(1 0 0) '(1 0 0))
1
[9]> (cos-similarity '(1 0 0) '(1 0 2)) 0.4472136
[10]> (cos-similarity '(1 0 0) '(0 1 1)) 0
? query (query-terms)
The function query takes one input parameter, query-terms, which is assumed to be a list of words (i.e., query terms). It should return the titles appearing in *corpus* (a global parameter containing a list of titles of AI-related books), sorted according to their cosine similarity to the query, with best-matching titles appearing first. The results returned should also show the values of the cosine similarity for each of the titles. For example, assuming *corpus* and *stopwords* are defined as below (see section on Testing your code on a simple IR task):
[10]> (query '(lisp and prolog)) (((ARTIFICIAL INTELLIGENCE PROGRAMMING USING PROLOG AND LISP) 0.57735026) ((COMMON LISP A UNIFIED APPROACH TO LISP) 0.5345225) ((PROLOG FOR BEGINNERS) 0.50000006) ((PROLOG FOR DUMMIES) 0.50000006) ((ESSENTIAL LISP) 0.50000006) ((THE ART OF LISP PROGRAMMING) 0.4082483) ((COMMON LISP FOR DUMMIES) 0.4082483) ((LOGIC PROGRAMMING IN PROLOG) 0.4082483) ((COMMON LISP THE LANGUAGE) 0.4082483) ((ARTIFICIAL INTELLIGENCE IN COMMON LISP) 0.35355338) ((FUNCTIONAL PROGRAMMING IN COMMON LISP) 0.35355338) ((ARTIFICIAL INTELLIGENCE A MODERN APPROACH) 0) ((A FIRST BOOK OF C++) 0))
Some useful built-in functions
There are a number of useful built-in LISP functions which you may find useful for this assignment. sort (lst predicate)
The function sort takes a list and a predicate as input. It returns a list containing the items of lst sorted according to the predicate. For example:
[1]> (sort '(2 1 3 5 4 6 5) #'<)(1 2 3 4 5 5 6)
[2]> (sort '(apple carrot bananas) #'string-lessp)(APPLE BANANAS CARROT)
The function sort can also deal with sorting more complex objects such as lists. In this case, we need to specify the key according to which we wish to sort. For example:
Question 3 – Resolution Refutation
Consider the following information:
"Pepe is a trained poodle and George is Pepe's master. If the temperature is warm, George always goes to the park. On cold weekdays George always goes to the
Museum. Trained dogs are obedient, and all obedient dogs will be with their master. It is Tuesday and it is cold."
(a) Represent the above information, as well as any relevant background information, in full predicate form (i.e., you must show any existential or universal quantifiers). You must use ONLY the following predicates and constants:
poodle (X) X is a poodle
trained (X) X is trained
master (X,Y) The master of X is Y
location (X,Y,Z) The location of X on day Y is Z
conditions (X,Y) The weather conditions on day X is Y e.g., conditions(mon, cold)
dog (X) X is a dog
obedient (X) X is obedient
weekday(X) X is a weekday
george George
pepe Pepe
cold cold (assumed to be a weather condition)
warm warm (assumed to be a weather condition)
mon Monday (a day)
tue Tuesday (a day)
wed Wednesday (a day)
thur Thursday (a day)
fri Friday (a day)
park park (a location)
museum museum (a location)
(b) Convert the predicate calculus expression you wrote in part (a) to clause form. This means that each
individual clause in the database must be a disjunction of literals, where a literal is an atomic
expression or the negation of an atomic expression.
(c) Using your database of clauses from part (b), manually use resolution refutation to extract the answer
to the question "Where is Pepe?". Make sure that you show all steps, and show clearly the
substitutions required in order to answer the question.
Submit the following:
Electronic copy of a file q3.doc that contains your answers to parts (a), (b) and (c). (Handwritten and
scanned is OK, but make sure that it is easy to read). Make sure that your name and student number
appear in the header documentation.
Your submission will be marked according to the following criteria:
Correctness and completeness of the expressions in part (a) and part (b).
Correctness and completeness of the proof.
Question 4 – Match-making in Prolog
Suppose that you are working for a match-making agency that seeks to match people to each other based on their desires and interests. You have the following customers:
Alice is a woman of average height, has fair hair, and is of average age. She likes rock music, adventure books, and swimming. She would like to marry a tall, dark-haired man of average age.
Kelvin is a male of average height, has fair hair, and is young. He likes rock music, science fiction books, and tennis. He is looking for a wife who is fair-haired, young, and small.
Lynne is a tall woman, who is fair-haired and young. She likes classical music, adventure books and swimming. She seeks a dark-haired, tall man of mature age.
Dennis is a small male, has dark hair, and is of mature age. He likes jazz, detective novels and tennis. He is looking for a small, fair-haired woman of average age.
Eva is a female of small height, has red hair, and is young. She likes rock music, science fiction, and tennis. She's looking for a young, fair-haired man of average height.
Peter is tall man, has dark hair, and is of mature age. He likes classical music, adventure books, and swimming. He is looking for a wife who is young, tall, and has fair hair.
(a) Choose a suitable set of predicates, and express the above facts in PROLOG.
(b) Two people X and Y are considered to be matched if X is appropriate to Y and Y is appropriate to X.
X is considered to be appropriate to Y if:
(i) X is physically appropriate to Y (i.e., height, hair colour, age and sex of X are those which Y seeks) and,
(ii) X and Y have exactly the same tastes regarding music, literature and sport.
Choose suitable predicates, and express this information in PROLOG. Your program should be designed so that when called with the goal matched(X,Y) PROLOG returns all of the matchedn couples.
1 ?- consult('match.pl'). % load PROLOG source file
Yes % source loads correctly
2 ?- matched(X,Y). % find matched couples
X = ,
Y = ;
X = ,
Y = ;
X = ,
Y = ;
Remember to enter a ";" in order to instruct PROLOG to search for additional matches. Alternatively, you could use the built-in Prolog predicate findall. For example, given the following clause: solve(List) :- findall([X,Y], matched(X,Y), List). the query ?- findall(List). will bind List to a list of all matched pairs.
(c) Use Prolog to determine all of the matched couples.
Question 5 – An expert system rule base
Your task for this question is to develop a small rulebase that can be used in the CLIPS expert system shell. You may choose any appropriate domain for your system; however, it should be in an area in which you have some expertise. Suitable domains may include:
recommending a movie to watch (you might want to focus on a particular genre);
recommending a suitable pet (e.g., you might want to focus on a specific breed of dog);
real estate advisor; etc.
but there are hundreds of others. Hopefully you will develop something that is both useful and fun! The system that you develop should be engineered to return a single result (e.g., which restaurant to dine at, which movie to watch). As a rough guide, there should be approximately 3 or 4 outcomes (e.g., restaurants or movies to recommend) but this will depend on your particular domain. Remember that the expert system approach is most appropriate when using ‘deep’ knowledge, and inferencing involves several layers of intermediate-level hypotheses. While many real expert systems can contain hundreds of rules, for the purpose of this exercise, approximately 15 to 20 rules (not counting helper rules, whose purpose, for example, might be solely to obtain input) should be sufficient. It is usually a good idea to
use some rules which are more general (i.e., only one or two conditions in the antecedent), and some which are more specific (e.g., three or more conditions in the antecedent. Obviously, with such a small number of rules, the expert system will not work well in all consultations. Try to engineer your system so that it performs
well in a couple of particular cases (i.e., one or two particular restaurants; one or two particular movies). Testing the system Create at least three test scenarios, each corresponding to a different set of facts to be presented to the system when prompted. The scenarios should be carefully selected to test your system and to demonstrate the quality of its inferencing. Select two scenarios to demonstrate when your system works well, and at least one scenario to show when your system works poorly (i.e., gives bad advice). You will need to submit runs of these test scenarios, so you must capture the sessions to a text file. Instructions on how to capture input into a text file in CLIPS, see the Appendix).
What to submit:
Electronic copy of the file q5.clp that contains your CLIPS code. The documentation in the header section should describe the problem domain that you have selected (e.g., pet recommendation), with a justification for why you believe that an expert system approach is appropriate for this problem (it should rely on intermediate hypotheses – see above). Make sure that your name and student number appear in the header documentation.
Electronic copy of the file q5_run.txt that contains a run of your CLIPS code, demonstrating performance on three different scenarios. (See instructions at end of this document for capturing asession using CLIPS). Make sure that your name and student number appear in the header documentation.
This CSE2AIF: IT Assignment has been solved by our IT experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.