# Eric Ashworth's Prolog Project

## Description of the Problem

I am looking at this one to do. It may be a bit too complicated, but very interesting. [1]

So I worked on a project for awhile, but thought of a better idea. I thought of this problem as my friends and I were talking at lunch the other day. I felt like this could be a good prolog problem. We were discussing who drove the "better" car.

Here is the breakdown of the problem:

## "Who has the best car"

```Our problem question is: Who drives the "best" car?

My two friends and I were talking about the different features each of us had on our new cars, and was trying to persuade the
other two that our car is the "best" car.

I figured, there is only one way to find out. So I introduced them to my solution, but didn't show them exactly everything! Here is
how I went about the problem:

I created a database of the features each car had, and who drove each car. Then I created this database holding all of our
information:
```

## Description of the Database

My database includes features for each of the three cars that each of the car owners came up with:

```This is an example of what each statement means.
drives(mike, navigator). %%This means mike drives a navigator.

Then the other type of statements mean:
has(navigator, fourDoor). %%The navigator has four doors.
```
```%%Here are the 3 cars that we own
car(bmw).
car(navigator).
car(accord).

%%These are the 3 owners
person(mike).
person(eric).
person(sam).

%%This describes who drives what car.
drives(mike, navigator).
drives(eric, accord).
drives(sam, bmw).

%%** Features for Car A **
has(bmw, twoDoor).
has(bmw, goodBrakes).
has(bmw, leatherInterior).
has(bmw, navSystem).
has(bmw, goodHorsePower).

%%** Features for Car B **
has(navigator, fourDoor).
has(navigator, manual).
has(navigator, navSystem).
has(navigator, goodHorsePower).
has(navigator, leatherInterior).

%%** Features for Car C **
has(accord, twoDoor).
has(accord, waxOn).
has(accord, manual).
has(accord, goodHorsePower).
has(accord, goodBrakes).

```

## The Code

```%%Author: Eric Ashworth
%%Class: MAT385
%%Date: February 20, 2007
%
%	This program will determine who's car is "better" by anylizing
%	the features of each car and then the "program" will decide
%	which car is "better"

car(bmw).
car(navigator).
car(accord).

person(mike).
person(eric).
person(sam).

drives(mike, navigator).
drives(eric, accord).
drives(sam, bmw).

%%** Features for Car A **
has(bmw, twoDoor).
has(bmw, goodBrakes).
has(bmw, leatherInterior).
has(bmw, navSystem).
has(bmw, goodHorsePower).

%%** Features for Car B **
has(navigator, fourDoor).
has(navigator, manual).
has(navigator, navSystem).
has(navigator, goodHorsePower).
has(navigator, leatherInterior).

%%** Features for Car C **
has(accord, twoDoor).
has(accord, waxOn).
has(accord, manual).
has(accord, goodHorsePower).
has(accord, goodBrakes).

%%X represents an expensive car
isExpensive(X) :-
has(X, navSystem), has(X, leatherInterior).

%%X represents a fast car
isFast(X) :-
has(X, goodBrakes), has(X, goodHorsePower).

%%X represents a sporty car
isSporty(X) :-
has(X, twoDoor), has(X, manual).

%%X represents a clean car
isClean(X) :-
has(X, fourDoor), has(X, waxOn).

%%Y is rich if the car they drive is expensive
isRich(Y) :-
drives(Y, X),
isExpensive(X).

%%Y is poor if the car they drive is not expensive
isPoor(Y) :-
drives(Y, X),
\+isExpensive(X).

%%Y represents the person with the best car
hasBestCar(Y) :-
drives(Y, X),
(isPoor(Y), isFast(X)).
hasBestCar(Y) :-
drives(Y, X),
(isRich(X), isSporty(X), isClean(X)).
```

## Example Output

```1 ?- isExpensive(X).
X = bmw ;
X = navigator ;

2 ?- isFast(X).
X = bmw ;
X = accord ;

3 ?- isSporty(X).
X = accord ;

4 ?- isClean(X).
false.

5 ?- isRich(Y).
Y = mike ;
Y = sam ;

6 ?- isRich(eric).
false.

7 ?- isPoor(X).
X = eric ;

8 ?- hasBestCar(Y).
Y = eric ;

9 ?- hasBestCar(mike).
false.
```

## Anyaisis

Now, it is obvious that I have the "better" car!!!