TC2008B

Course material for the Multi-agents and computer graphics course.

Setup instructions

  • Strongly recommend using a custom conda environment.
  • Install python 3.8 in the environment: conda install python=3.8 Using 3.8 for compatibility reasons. Maybe 3.9 or 3.10 are compatible with all the packages, but will have to check.
  • Installing mesa: pip install mesa
  • Installing flask to mount the service: pip install flask
  • By this moment, the environment will have all the packages needed for the project to run.

Instructions to run the local server and the Unity application

  • Run either the python web server: Server/tc2008B_server.py, or the flask server: Server/tc2008B_flask.py. Flask is considerably easier to setup and use, and I strongly recommend its use over python’s http.server module. Additionally, IBM cloud example used flask.
  • To run the python web server:

python tc2008B_server.py
  • To run a flask app:

export FLASK_APP=tc_2008B_flash.py
flask run
  • You can change the name of the app you want to run by changing the environment variable FLASK_APP.

  • Alternatively, if you used the following code in your flask server:

if __name__=='__main__':
    app.run(host="localhost", port=8585, debug=True)

you can run it using:

python tc2008B_flask.py
  • To run a flask app on a different host or port:

flask run --host=0.0.0.0 --port=8585
  • Either of these servers is what will run on the cloud.
  • Once the server is running, launch the Unity scene TC2008B that is in the folder: IntegrationTest.
  • The scene has two game objects: AgentController and AgentControllerUpdate. I left both so that different functionality can be tested: AgentController works with the response of the python web server, while AgentControllerUpdate works with the reponse from the flask server.
  • I updated the AgentController.cs code, and introduced AgentControllerUpdate.cs. Each script parses data differently, depending on the response from either the python web server, or from the flask server. The AgentController.cs script parses text data, while AgentControllerUpdate.cs parses JSON data. I strongly recommend that we use JSON data.
  • The scripts are listening to port 8585 (http://localhost:8585). Double check that your server is launching on that port; specially if you are using a flask server.
  • If the Unity application is not running, or has import issues, I included the Unity package that has the scene Sergio Ruiz provided.

Instruction to run the cloud server and Unity application

Installing dependencies, and locally running the sample

# ...first add the Cloud Foundry Foundation public key and package repository to your system
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
# ...then, update your local package index, then finally install the cf CLI
sudo apt update
sudo apt install cf8-cli
  • To get the sample app running:

git clone https://github.com/IBM-Cloud/get-started-python
cd get-started-python
  • To run locally:

pip install -r requirements.txt
python hello.py

To deply the sample to the cloud

  • All the requiered files for the sample app to run are inside the IBMCloud folder.
  • We first need a manifest.yml file. The one provided in the example repository contains the following:

applications:
 - name: GetStartedPython
   random-route: true
   memory: 128M
  • You can use the Cloud Foundry CLI to deploy apps. Choose your API endpoint:

<div class="snippet-clipboard-content position-relative overflow-auto" data-snippet-clipboard-copy-content="cf api
“>

cf api