Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

%Define constants for the width and height #const max_width=12. #const max_height=10. %Define the domain for the terrain type terrain_type(grass;tree;flower;water;bridge). %define X and Y coordinates width(1..max_width).

%Define constants for the width and height #const max_width=12. #const max_height=10.

%Define the domain for the terrain type terrain_type(grass;tree;flower;water;bridge).

%define X and Y coordinates width(1..max_width). height(1..max_height).

%For each X,Y pair, we choose 1 and only terrain type at that location 1 {terrain(XX,YY,TERRAIN_TYPE) : terrain_type(TERRAIN_TYPE)} 1 :- width(XX), height(YY).

%For each point, determine how many of each kind of neighbor it has (3x3 window) neighbors(XX,YY,TYPE, COUNT) :- COUNT = {terrain(XX-1,YY-1,TYPE); terrain(XX,YY-1,TYPE); terrain(XX+1,YY-1,TYPE); terrain(XX-1,YY,TYPE); terrain(XX+1,YY,TYPE); terrain(XX-1,YY+1,TYPE); terrain(XX,YY+1,TYPE); terrain(XX+1,YY+1,TYPE)}, terrain(XX,YY,_), terrain_type(TYPE).

%For each point, determine how many of each kind of neighbor it has cardinal directions only immediate_neighbors(XX,YY,TYPE, COUNT) :- COUNT = {terrain(XX,YY-1,TYPE); terrain(XX-1,YY,TYPE); terrain(XX+1,YY,TYPE); terrain(XX,YY+1,TYPE)}, terrain(XX,YY,_), terrain_type(TYPE).

%Bridges can only be horizontal or vertical and they must connect two pieces of land %Determine if a point is part of a horizontal -- a horizontal bridge end has grass to the left or right horizontal(XX,YY,start) :- terrain(XX,YY,bridge), terrain(XX-1,YY,grass). horizontal(XX,YY,start) :- terrain(XX,YY,bridge), terrain(XX+1,YY,grass). %A horizontal bridge middle has a horizontal bridge to the left or right horizontal(XX,YY,mid) :- terrain(XX,YY,bridge), horizontal(XX-1,YY,_). horizontal(XX,YY,mid) :- terrain(XX,YY,bridge), horizontal(XX+1,YY,_).

%Determine if a point is part of a horizontal -- a horizontal bridge end has grass to the left or right vertical(XX,YY,start) :- terrain(XX,YY,bridge), terrain(XX,YY+1,grass). vertical(XX,YY,start) :- terrain(XX,YY,bridge), terrain(XX,YY-1,grass). %A horizontal bridge middle has a horizontal bridge to the left or right vertical(XX,YY,mid) :- terrain(XX,YY,bridge), vertical(XX,YY-1,_). vertical(XX,YY,mid) :- terrain(XX,YY,bridge), vertical(XX,YY+1,_).

%If a piece is a bridge, it must be a horizontal or vertical bridge :- terrain(XX,YY,bridge), not horizontal(XX,YY,_), not vertical(XX,YY,_).

%If a piece is a bridge, it must be either horizontal or vertical, but not both :- terrain(XX,YY,bridge), horizontal(XX,YY,_), vertical(XX,YY,_).

%A bridge should not start and end immediately :- horizontal(X1,YY,start), horizontal(X2,YY,start), X1-X2=1. :- vertical(XX,Y1,start), vertical(XX,Y2,start), Y1-Y2=1. :- horizontal(XX,Y1,start), horizontal(XX,Y2,start), Y1-Y2=1. :- vertical(X1,YY,start), vertical(X2,YY,start), X1-X2=1.

%Grass should make up at least half of the map :- {terrain(XX,YY,grass)} max_width*max_height*1/2 .

%Water should make up at least 1/6 of the map :- {terrain(XX,YY,water)} max_width*max_height*1/6 .

%There should be at least 5 pieces of bridge :- {terrain(XX,YY,bridge)} 5 .

%A flower should not be surrounded by more than 2 flowers :- terrain(XX,YY,flower), neighbors(XX,YY,flower, COUNT), COUNT > 3.

%Water must touch at least 4 other pieces of water :- terrain(XX,YY,water), neighbors(XX,YY,water, COUNT), COUNT < 4.

%A bridge must touch at least 4 pieces of water :- terrain(XX,YY,bridge), neighbors(XX,YY,water, COUNT), COUNT < 4.

%A bridge can only touch a (B+G) = 2 where B is the number of bridge pieces and G is the number of grass pieces :- terrain(XX,YY,bridge), immediate_neighbors(XX,YY,bridge, B_COUNT), terrain(XX,YY,bridge), immediate_neighbors(XX,YY,grass, G_COUNT), B_COUNT + G_COUNT != 2.

%A location is surrounded by water if it has water on the right and left surrounded_by_water(XX,YY) :- terrain(XX+1,YY,water),terrain(XX-1,YY,water). %or on the top and bottom surrounded_by_water(XX,YY) :- terrain(XX,YY-1,water),terrain(XX,YY-1,water).

%A bridge should be surrounded by water :- terrain(XX,YY,bridge), not surrounded_by_water(XX,YY).

%Every piece of bridge should touch at least another bridge :- terrain(XX,YY,bridge), immediate_neighbors(XX,YY,bridge, B_COUNT), B_COUNT < 1.

% Every type of terrain should be represented in the map :- {terrain(XX,YY,TERRAIN_TYPE)} 0, terrain_type(TERRAIN_TYPE).

%A piece of grass is connected to grass connected(XX,YY) :- terrain(XX,YY,grass). %A bridge is connected to grass if it is connected to something that is connected to grass connected(XX,YY) :- terrain(XX,YY,bridge), 1 {connected(XX,YY-1); connected(XX-1,YY); connected(XX+1,YY); connected(XX,YY+1)}. %All bridges must be connected :- terrain(XX,YY,bridge), not connected(XX,YY).

%Every non-water spot on the map should be reachable from every other spot

%First we randomly pick 1 spot 1 {reachable(XX,YY,original) : width(XX), height(YY)} 1.

%The randomly picked spot should be grass :- reachable(XX,YY,original), not terrain(XX,YY,grass).

%The randomly picked spot is reachable reachable(XX,YY) :- reachable(XX,YY,original).

%A spot is reachable if it is within a cardinal move from a reachable spot reachable(XX,YY) :- reachable(XX+1,YY), not terrain(XX,YY,water), width(XX), height(YY). reachable(XX,YY) :- reachable(XX-1,YY), not terrain(XX,YY,water), width(XX), height(YY). reachable(XX,YY) :- reachable(XX,YY+1), not terrain(XX,YY,water), width(XX), height(YY). reachable(XX,YY) :- reachable(XX,YY-1), not terrain(XX,YY,water), width(XX), height(YY).

%All of the non-water terrain must be reachable :- terrain(XX,YY,TERRAIN), TERRAIN != water, not reachable(XX,YY).

Create a house swi file that works with above.

generate the terrain(above) at the same time as your house is generated (guaranteeing that the terrain that is generated is capable of supporting your house).

Your code will create a `construction` predicate of the form:

`construction(X_Position, Y_Position, Construction_Type)`

where `Construction_Type` is one of `door, wall, floor, bed`.

This is free-form, there are a few constraints that need to be met:

* house should contain at least 1 door, 1 bed, all non-bed tiles should be floor, and the perimeter of the house should be walls * It should not place 2 doors side by side * Doors shouldn't be placed in corners, but should be able to face out to any cardinal direction * Doors should open to grass or flowers, not water, bridges, or trees * All pieces of your house should be on top of grass or flowers, not water, bridges, or trees * The position of your house shouldn't be hardcoded * A wall piece must touch (in cardinal directions) only 2 doors or walls

* houses can be of variable width and height * houses can be in shapes that aren't just rectangles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

6. Who pays the inflation tax?

Answered: 1 week ago