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 a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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