Reference no: EM13843687
Question 1 - Game Playing
The game Connect-4 is played on a board that has seven columns. There are six spaces on each column. The board is initially empty. Two players take turns dropping one piece (black or grey 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 move 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 (horizontally, vertically, or diagonally) is the winner.
You have been provided with two files for this problem: minimax.lisp, which contains lisp code for the minimax algorithm, and fourinarow.lisp, which contains a working LISP implementation of the Connect-4 game.
As the Connect-4 implementation currently stands, you should have absolutely no problem beating the program. Try it:
[1]> (load 'minimax)
;; Loading file C:\CSE2AIF\minimax.lisp ...
;; Loaded file C:\CSE2AIF\minimax.lisp
T
[3]> (load fourinarow)
;; Loading file C:\CSE2AIF\fourinarow.lisp ...
;; Loaded file C:\CSE2AIF\fourinarow.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 good heuristic for the Connect-4 game.
The only LISP code that you are required to write is a LISP function static, which accepts a board and player as input arguments, and returns an evaluation of the board state from the point of view of player. You can, of course, write as many helper functions as you like.
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. Each element of this list is a list of length four, such as
((1 0) (2 1) (3 2) (4 3))
Each element of this list is a sublist in which the first number represents column position and the second number represents row position. For example, the list above indicates that there is a line of length four that includes a piece at the 1st row of the 2nd column, the 2nd row of the 3rd column, the 3rd row of the 4th column, and the 4th row of the 5th column. (Row and Column indexing starts at 0).
Question 2 - A Prolog Program to Solve the Water Jugs Problem
Write a Prolog program to solve the water jugs problem:
There are two jugs, one holding 3 and the other 5 litres of water. A number of things can be done with the jugs: they can be filled, emptied, and dumped one into the other either until the poured-into jug is full or until the poured-out-of jug is empty. Devise a sequence of actions that will produce 4 litres of water in the larger jug. (Hint: use only integers.)
You are advised to base your code on the Prolog code for the farmer, wolf, goat and cabbage problem that you used in Week 8 labs. The program should output the sequence of states on the path to the goal. (i.e., it does not need to output the operators - but you are welcome to also include this in the program output if you so desire.)
Attachment:- LISP programming.rar