项目作者: RedHat-Israel

项目描述 :
ROSE project car race game
高级语言: Python
项目地址: git://github.com/RedHat-Israel/ROSE.git
创建时间: 2013-12-21T23:47:56Z
项目社区:https://github.com/RedHat-Israel/ROSE

开源协议:GNU General Public License v2.0

下载


ROSE Project

CI WorkFlow

This project is a game that has been developed to assist in teaching
kids python. The students need to code the behavior of a car to achieve
the best score.

Here is a video of a race (running code from students):
(Click on the screenshot to play the video)

ROSE Race Car Game

In this game, two race cars compete to achieve the most points. The
race car must recognize the race track, the obstacles, and the bonus
areas; then calculate the best path where the pitfalls are avoided and
all the bonus points are collected. The cars move autonomously on the
screen within the race track game with no interference from the
students. No joystick or mouse shall be used.

In order to control the car movements, the students needs to implement a
‘driver’. This code controls the car and will decide what the next
action of the car will be.

For each type of obstacles there is a different action and different
points assigned.

See examples/README.md for an explanation on how
to write a driver module.

GitHub pages

Refer to our GitHub pages for the course materials and additional resources:
https://redhat-israel.github.io/ROSE/

Talks and presentations

Getting started

The following commands should be performed only once; after creating the
environment you will be connecting to the same environment each time you
open a new session.

Use venv to create a virtual environment and to install the rest of
the dependencies:

  1. python3 -m venv ~/.venv/rose

After creating the environment, we want to activate and enter our
environment (make sure you’re in the ROSE directory):

  1. source ~/.venv/rose/bin/activate

After entering the virtual enviornment we need to install the project dependencies:

  1. pip install -r requirements.txt

Indication that you are inside the environment, the prompt line will
look like this:

  1. (rose) [username@hostname ROSE]$

Running the server

If you are not in your virtual environment, please activate it:

  1. source ~/.venv/rose/bin/activate

Start the server on some machine:

  1. ./rose-server

For running the same track for all drivers (instead or random) start the
server using:

  1. ./rose-server -t same

Open a browser at http://{server-address}:8880 to view and control the
game.

Running the server in Podman

Build the Docker image:

  1. podman build -t rose_server .

Run the Docker image on port 8880:

  1. podman run -it --rm --name=rose_server -p 8880:8880 rose_server python ./rose-server

If you don’t want to see the log of the run in the current window,
replace -it with -d.

Open a browser at http://{server-address}:8880 to view and control the
game.

Tunneling the UI server to your browser

You can use SSH tunneling when running the server on your remote VM, so
you can view the game in you local browser:

  1. ssh -L 8880:127.0.0.1:8880 {user}@{server-address}

After starting the server (as mentioned above), open a browser at
http://127.0.0.1:8880/ to view and control the game.

Opening firewall ports

You can also open ports 8880 and 8888 on the remote VM running the
server, and browse from a local machine in case port 8880 or 8888 are
blocked by firewalld:

  1. sudo firewall-cmd --add-port=8880/tcp --permanent
  2. sudo firewall-cmd --add-port=8888/tcp --permanent
  3. sudo firewall-cmd --reload

Running a driver

In a new window, open your virtual environment:

  1. source ~/.venv/rose/bin/activate

Create your driver file:

  1. cp examples/none.py mydriver.py

Edit the file mydriver.py and change the driver_name variable to your
name.

Start up the client, using your driver file:

  1. ./rose-client mydriver.py

The server address can be specified that way (Replace ‘10.20.30.44’ with
your server address):

  1. ./rose-client -s 10.20.30.44 mydriver.py

For running the driver on the Docker container use:

  1. docker exec -it rose_server python ./rose-client examples/random-driver.py

For driver modules, see the examples directory.

You can run the game with just 1 driver!

To let 2 drivers compete, repeat these commands in 2 terminals.

Command line interface

You can control the game from the command line using the rose-admin
tool.

To start a race, use the rose-admin tool on any machine:

  1. ./rose-admin {server-address} start

To stop a race, use the rose-admin tool on any machine:

  1. ./rose-admin {server-address} stop

To modify the game rate, you can use the “set-rate” command. The
following command would change game rate to 10 frames per second:

  1. ./rose-admin {server-address} set-rate 10

Using tmux / screen

./rose-server and ./rose-client {driver name} do not return, but
continue running, in order to run both server and drivers a user need to
run them in separate shells, using the same virtual environment.
shell. tmux may be useful in this case.

Example tmux commands:

Command Description
Ctrl+b + c Create a new window
Ctrl+b + n Toggle to next window
Ctrl+b + w List open windows
Ctrl+b + 0 Select Window 0
Ctrl+b + 1 Select Window 1
Ctrl+d Close a window (exit bash)

Creating a tarball

  1. python setup.py sdist

Developing

Should you want to contribute to the project, please read the
Code of Conduct.

To create venv use:

  1. python3 -m venv ~/.venv/rose

To enter the venv:

  1. source ~/.venv/rose/bin/activate

To install development requirements:

  1. pip install -r requirements-dev.txt

For development in docker, use:

  1. docker build --build-arg DEV=True -t rose_dev .

Before submitting patches, please run the tests:

  1. flake8
  2. pytest

Creating coverage report in html format:

  1. pytest --cov-report html
  2. xdg-open htmlcov/index.html