Second project of Artificial Intelligence class @ PUC-Rio
The project instructions are located at ENUNCIADO.pdf.
First, install the dependencies:
- Ruby
- SWI-Prolog
- Python 2.7
- Pyswip
- Node.js
Make sure the binaries of these tools are available on your PATH.
Also, make sure all of [SWI-Prolog, Python, Pyswip] are the same architechture (x86 or x64).
Run these commands at src/visualization
:
npm install --global gulp bower
npm install
bower install
Also, download
Then, at the project root, run the following commands:
cd src
echo "Generating random items"
ruby generator/item-generator.rb > items.txt
cp items.txt visualization/app/items.txt
echo "Generating facts"
ruby generator/fact-generator.rb > facts.pl
echo "Generating action log... May take a while"
python logic/logic.py > action-log.json
cp action-log.json visualization/app/action-log.json
echo "Running gulp"
cd visualization
gulp
gulp watch
However, if you want to use a custom items-custom.txt
, place it in src
and run this one instead:
cd src
echo "Skipping random items, copying from src/items.txt"
cp items-custom.txt visualization/app/items.txt
echo "Generating facts"
ruby generator/fact-generator.rb > facts.pl
echo "Generating action log... May take a while"
python logic/logic.py > action-log.json
cp action-log.json visualization/app/action-log.json
echo "Running gulp"
cd visualization
gulp
gulp watch
The project is separated in three main applications:
-
Fact Generator: reads src/map.txt and generates simple Prolog facts. Implemented in Ruby.
-
Item Generator: reads src/map.txt and generates a list of item positions, following the specifications set by the instructions. Implemented in Ruby.
-
Logic Agent: reads the map and uses logic to walk through the forest, while facing enemies, gathering valuables, and (hopefully) achieving the objective. Implemented in Prolog (logical decisions) and Python (consequences, path-finding, etc).
-
Path Visualizer: reads the map and path that were generated and draws the forest, illustrating the hero's journey. Implemented in web technologies.
The main script is src/generator/item-generator.rb
. You can run it like this, if you have Ruby installed:
ruby src/generator/item-generator.rb > src/items.txt
It outputs the list of items to stdout, so we'll be redirecting it to a file.
It is important that the file src/map.txt
is accessible and in the correct format.
The main script is src/generator/fact-generator.rb
. You can run it like this, if you have Ruby installed:
ruby src/generator/fact-generator.rb > src/facts.pl
It outputs the facts to stdout, so we'll be redirecting it to a file.
It is important that the files src/map.txt
and src/items.txt
are accessible and in the correct format.
The main script is src/logic/logic.py
, but you must execute it from src
. You should run it like this, if you have Python installed:
cd src
python logic/logic.py > action-log.json
It outputs an array of strings to stdout, so we'll be redirecting it to a file.
It is important that the file src/facts.pl
is accessible and up to date.
Copy the necessary files:
cd src
cp items.txt /visualization/app/items.txt
cp actions-log.json /visualization/app/action-log.json
If you want to change some files in this step, like the map, for instance, please read Development; otherwise just read Release.
Install the dependencies:
cd visualization
npm install -g gulp bower
npm install
bower install
And then run it:
gulp
gulp watch
A new browser window should be now open at http://loclhost:9000.
Download Node Webkit and extract it into src/visualization
.
Then, run nw.exe
.
Each line corresponds to one row in the map.
Each line must contain a space-separated list of 'f' and 'g' characters, indicating whether the tile is a forest or a grass tile.
Each line corresponds to an item placement.
Each line is formatted like Y X ITEM
, where Y and X are the coordinates of a tile in map.txt, and ITEM is either:
B
holeE
enemyV
vortexM
master swordF
fake master swordC
heartR
rupee
Coordinates follow these rules:
- Begin on the top-left corner
- Are 0-indexed
- X is horizontal
- Y is vertical
It's an array of strings.