Write a prolog program to solve the water jugs problem

Assignment Help Programming Languages
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.

2038_game.png

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

Reference no: EM13843687

Questions Cloud

Cumulative effects: : Merle Company has operated for several years and always shows two years of financial statements for users to make better conclusions about trends.  In Year 20, the firm changed one of its accounting methods.  The change was from a GAAP method to a..
Onsider an electric part with two components in series : 2. Consider an electric part with two components in series (component A and componentB). Component A has a reliability of 88%, while component B has a reliability of 94%. Itis known that if the part fails, it will cost the company $1000.a)  What is t..
Write code in vba to determine the row number : Write code in VBA to determine the row number of the last row with data. Are there any precautions/edge cases to be aware of for that code
Contrast differences in accounting processes and procedure : contrast the differences in accounting processes and procedures
Write 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 pou..
Suppose that daily demand for bagels at the local coffee : Suppose that daily demand for bagels at the local coffee shop where you work is found to be Normally distributed with a mean of 250 and a standard deviation of 75 units
Financial analysis measures : Bring together various financial analysis measures and interpret their meaning in order to draw conclusions about various companies. Note that each situation provided is to be considered independently of the others.
Most widely associated with workers'' compensation : Summarize briefly the problems most widely associated with workers' compensation. What does the insurance industry use Experience Modification Rate (EMR) to determine?
Ethical issue: reclassification of receivables : Reclassification of Receivables

Reviews

Write a Review

Programming Languages Questions & Answers

  Write down script to report cumulative size of all files

Write down script which will report cumulative size of all files in and below given directory. Your script will also report name and size (in bytes) of largest file with that directory tree.

  Design program to enter a series of numbers

Design a program that asks the user to enter a series of 20 numbers. The program should determine whether the number is valid by comparing it to the following list of valid charge account numbers.

  Explaining class definition of subclass of square

Write down the class definition of subclass of Square called FancySquare which has a method called getDiagonal. The getDiagonal method gets no arguments.

  Write a vhdl code for soda vending machine

Write a VHDL code that implements the above soda machine. You have to turn in the following: A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

  Create application which gets customer account data

Some interest Credit Company gives loans to customers at 1.5 percent interest per month. Create the application which gets customer account data which includes the account number, customer name, and balance due.

  Print the list of array of numbers

Print the list of array of numbers and then print linked list with the equivalent character side by side to. output file Specifications:

  Write at least two test cases to check for errors

Write a program that accepts a given number an input from the user and prints prime numbers up to that number.

  User-s ability to navigate the web site correctly

This can paralyze a user's ability to navigate the Web site correctly. Examples include opening new browser windows or using meta-refresh to force a page.

  Benefits from the cloud first policy

Cloud computing enables IT systems to be scalable and elastic. End users do not need to determine their exact computing resource requirements upfront. Instead, they provision computing resources as required, on-demand. Using cloud computing services,..

  Write a full program to convert seconds into hours

Write a full program (starting from #include) that takes as input the number of seconds after midnight and displays the time in hours.

  Weka follow the instruction and i will need in 24 hours

follow the instruction and i will need in 24 hours. please please give me on time and i will keep use ur

  Describe how to prepare users for sales organization unit

Describe how you would prepare the users for sales organization unit and how you can set up user groups in particular conditions (global, universal, domain local).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd