aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-25 10:36:01 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-25 10:36:01 +0100
commit8a74f856e8878ca77682e75d8ec1ee6fa82cf648 (patch)
tree5d479ee4a6597f7acb964e6fad94024081fbbb02
parent798a1fb4ef44c5c3bd54663b1ad6ba281dca4bc1 (diff)
the big readme update
-rw-r--r--api/readme.md50
-rw-r--r--banner.pngbin9035 -> 29377 bytes
-rwxr-xr-xconfigure4
-rw-r--r--diagram.pngbin0 -> 142990 bytes
-rw-r--r--readme.md124
-rw-r--r--readme_en.md116
-rw-r--r--voerbak/readme.md77
7 files changed, 175 insertions, 196 deletions
diff --git a/api/readme.md b/api/readme.md
new file mode 100644
index 0000000..7d28259
--- /dev/null
+++ b/api/readme.md
@@ -0,0 +1,50 @@
+# API
+
+This is the subdirectory for the API. You can find the API reference in [this](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) Google Docs document.
+
+## How to test API endpoints
+```sh
+# If you're running the standalone flask server:
+curl http://localhost:5000/<endpoint>
+
+# If you're running flask and nginx at the same time:
+curl http://localhost:2080/api/<endpoint>
+```
+
+## How to add new API endpoints
+
+Please follow these rules when creating new API endpoints:
+
+1. Endpoints should always return a valid JSON object and an appropriate [http code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
+2. Endpoints that are in a namespace should get their own directory in this folder, eg. http://localhost:5000/status is defined in api/status.py, http://localhost:5000/auth/signup is defined in api/auth/signup.py etc.
+3. Endpoints that take data should verify that the data is present and valid, and return an empty JSON object with http code 400 (bad request) if the data isn't valid.
+4. Endpoints that require database access should get the cursor/connection object from api/db.py
+
+## Example endpoint
+
+Here's a simple endpoint that returns an empty JSON object:
+
+```py
+# api/tests/example.py
+from flask import Blueprint
+
+example = Blueprint('example', __name__)
+
+@example.route('/example')
+def index():
+ # python dictionaries are automatically converted to JSON by flask
+ return {"hello": "world"}, 200 # flask returns http code 200 by default if no code is explicitly defined
+
+# define a `dynamic_route` variable at the end of your endpoint definition file
+# dynamic_route[0] is the namespace
+# dynamic_route[1] is your flask.Blueprint
+dynamic_route = ["/tests", status]
+
+# this endpoint will be routed to /tests/example
+# \___/ \_____/
+# | |
+# | endpoint (defined by the @Blueprint.route() decorator)
+# |
+# namespace (defined in dynamic_route variable)
+```
+
diff --git a/banner.png b/banner.png
index a35988b..ef213ff 100644
--- a/banner.png
+++ b/banner.png
Binary files differ
diff --git a/configure b/configure
index 9520d8d..9bf3b86 100755
--- a/configure
+++ b/configure
@@ -1,9 +1,9 @@
sudo apt-get install nodejs npm python3 python3-venv python3-pip make gcc sqlite3 nginx
-npm i -g typescript yarn
+sudo npm i -g typescript yarn
yarn
-python -m venv venv
+python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
diff --git a/diagram.png b/diagram.png
new file mode 100644
index 0000000..e63be37
--- /dev/null
+++ b/diagram.png
Binary files differ
diff --git a/readme.md b/readme.md
index 2ea7fd3..0eae900 100644
--- a/readme.md
+++ b/readme.md
@@ -1,114 +1,82 @@
# PO connect-4
-<div style="text-align: center;"><img src="./banner.png"/></div>
+![](./banner.png)
-## Dit is de PO informatica met Python en SQL
+## This is a school project using Python and SQL
-## Dingen die er graag in willes:
+Some of this project's code is in Dutch (commit messages, documents etc.), along with the whole website. I'm planning on adding some form of localization system, and I'll try to maintain this after the assignment deadline because I think this is a pretty cool project. I'll also be fixing issues/merging pr's after the deadline. I think the deadline is ~January 25th~ sometime in March? though I'm not sure about this.
-- Werkend 4 op een rij spel
-- Client-server verbinding met socket.io
-- Accounts aanmaken
-- Anonieme accounts / invite links
-- Veilige wachtwoordauthenticatie
-- Spelen tegen computer
-- Rest API die dit allemaal doet inplaats van jank oplossing
+## Things that we'd like to have working:
-## Misschien:
+- Working connect 4 game
+- Client-server connection with socket.io
+- Account creation
+- Anonymous accounts / invite links
+- Safe password authentication
+- Play against the computer
+- Follow people/add as friend
+- Game rating like on chess.com
+- Rest API that handles all of this instead of some janky solution
-- ~Log in met google / apple / andere~
-- Berichten
-- Mensen kunnen volgen
-- Meerdere game modes
-- Rating net als op chess.com
-- Verschillende thema's (minimalistisch of skeuomorf met realistische stuiter-animaties)
+## Maybe:
-## Dingen die gebruikt worden:
+- ~Log in with google / apple / other~
+- Messages
+- Multiple game modes
+- Different themes (minimalist or skeumorphic with realistic bouncing animation)
-- [Flask](https://flask.palletsprojects.com/) voor de http server en de REST api
-- [ReactJS](https://reactjs.org/) om de website mee te maken
-- [NextJS](https://nextjs.org/) om meerdere pagina's te hebben met reactjs
-- [socket.io](https://socket.io/) voor de communicatie tussen de clients en de server tijdens een potje
-- [SQLite](https://sqlite.org/index.html) voor de database
+## Used libraries and frameworks:
-Een voorbeeld van de database is te vinden op [Google Docs](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) samen met de api endpoints, en een voorbeeld van de website is te vinden op [Figma](https://www.figma.com/file/rTciVQApAe6cwrH1Prl5Wn/4-op-een-rij?node-id=0%3A1)
+- [Flask](https://flask.palletsprojects.com/) for the REST API
+- [ReactJS](https://reactjs.org/) to create the website
+- [NextJS](https://nextjs.org/) for static react pages and html page routing
+- [socket.io](https://socket.io/) for bidirecitonal communication during a game
+- [SQLite](https://sqlite.org/index.html) for the database
+- [nginx](https://nginx.org/en/) for serving static files generated by nextjs, caching and reverse proxy
-## Hoe 'installeren'
+An example database can be found on [Google Docs](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) along with the API endpoints, and the website prototypes can be found on [Figma](https://www.figma.com/file/rTciVQApAe6cwrH1Prl5Wn/4-op-een-rij?node-id=0%3A1)
+
+![](./diagram.png)
+
+## How to set up
+
+> I haven't figured out how to run this project on Windows, so please install [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) if you want to run this yourself on Windows. The distro you choose doesn't matter, though package names in ./configure may vary if your distro doesn't use the apt package manager.
0. `git clone https://github.com/lonkaars/po-4-op-een-rij`
-1. Zorg dat je [python](https://python.org/downloads) hebt geïnstalleerd.
-2. Zorg dat je [nodejs](https://nodejs.org/en/download) hebt geïnstalleerd.
-3. Installeer typescript, react-scripts en yarn:
+1. Make sure you have [python](https://python.org/downloads) (with pip and venv) installed.
+2. Make sure you have [nodejs](https://nodejs.org/en/download) (with npm) installed.
+2. Make sure you have [nginx](https://nginx.org/en/) installed.
+3. Install typescript, react-scripts and yarn:
```sh
- npm i -g typescript yarn react-scripts
+ npm i -g typescript yarn
```
-4. Maak een python virtual environment en installeer pip modules:
+4. Create a new python virtual environment and install pip modules:
```sh
python -m venv venv
-
- # activeer virtual environment (zie volgende alinea)
-
+ source venv/bin/activate
pip install -r requirements.txt
```
-5. Installeer node modules:
+5. Install node modules:
```sh
yarn
```
-## Hoe python virtual environment activeren
-
-### Windows (cmd)
-
-```
-.\venv\Scripts\activate.bat
-```
-
-### Windows (powershell)
-
-```
-.\venv\Scripts\Activate.ps1
-```
-
-### Windows (git bash)
-
-```
-source venv/Scripts/activate
-```
+## How to start
-### Linux (bash/zsh/sh)
-
-```
-source venv/bin/activate
-```
-
-Als je het goed gedaan hebt krijg je een nieuwe prompt te zien met `(venv)` er voor.
-
-## Hoe starten
-
-Om dit project te starten moet je 3 terminals gebruiken die afzonderlijk de flask server en de react server starten:
+In order to start this project you'll need three terminal windows to start the flask server, react server, and nginx seperately:
```sh
# term 1
-
-# activeer virtual environment
-
+source venv/bin/activate
python3 api/main.py
# term 2
-
yarn dev
# term 3
+sudo nginx -c $PWD/nginx.conf
-sudo nginx -c $PWD/nginx.conf # dit werkt alleen op unix (ik moet nog ooit gaan testen op windows)
-```
-
-## Hoe API endpoints testen
-```sh
-# Als je alleen de flask server draait:
-curl http://localhost:5000/<endpoint>
-
-# Als nginx ook draait:
-curl http://localhost:2080/api/<endpoint>
+# if nginx can't run as the user nobody, try running the following command and restart nginx:
+sed "s/user nobody/user $(whoami)/" -i nginx.conf
```
diff --git a/readme_en.md b/readme_en.md
deleted file mode 100644
index 3ae3d3f..0000000
--- a/readme_en.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# PO connect-4
-
-<div style="text-align: center;"><img src="./banner.png"/></div>
-
-## This is a school project using Python and SQL
-
-Note to English spreakers: most of this project is in Dutch (commit messages, documents etc.). I'll try to maintain this after the assignment deadline because I think this is a pretty cool project, and I'll be fixing issues/merging pr's after the deadline aswell. I think the deadline is ~January 25th~ sometime in March? though I'm not sure about this.
-
-## Things that we'd like to have working:
-
-- Working connect 4 game
-- Client-server connection with socket.io
-- Account creation
-- Anonymous accounts / invite links
-- Safe password authentication
-- Play against the computer
-- Rest API that handles all of this instead of some janky solution
-
-## Maybe:
-
-- ~Log in with google / apple / other~
-- Messages
-- Follow people/add as friend
-- Multiple game modes
-- Game rating like on chess.com
-- Different themes (minimalist or skeumorphic with realistic bouncing animation)
-
-## Used libraries:
-
-- [Flask](https://flask.palletsprojects.com/) for the http server and REST API
-- [ReactJS](https://reactjs.org/) to create the website
-- [NextJS](https://nextjs.org/) for static page routing
-- [socket.io](https://socket.io/) for bidirecitonal communication during a game
-- [SQLite](https://sqlite.org/index.html) for the database
-
-An example database can be found on [Google Docs](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) along with the API endpoints, and the website prototypes can be found on [Figma](https://www.figma.com/file/rTciVQApAe6cwrH1Prl5Wn/4-op-een-rij?node-id=0%3A1)
-
-## How to set up
-
-0. `git clone https://github.com/lonkaars/po-4-op-een-rij`
-1. Make sure you have [python](https://python.org/downloads) installed.
-2. Make sure you have [nodejs](https://nodejs.org/en/download) installed.
-3. Install typescript, react-scripts and yarn:
- ```sh
- npm i -g typescript yarn react-scripts
- ```
-4. Create a new python virtual environment and install pip modules:
- ```sh
- python -m venv venv
-
- # activate virtual environment (see next section)
-
- pip install -r requirements.txt
- ```
-5. Install node modules:
- ```sh
- yarn
- ```
-
-## How to activate Python virtual environment
-
-### Windows (cmd)
-
-```
-.\venv\Scripts\activate.bat
-```
-
-### Windows (powershell)
-
-```
-.\venv\Scripts\Activate.ps1
-```
-
-### Windows (git bash)
-
-```
-source venv/Scripts/activate
-```
-
-### Linux (bash/zsh/sh)
-
-```
-source venv/bin/activate
-```
-
-If you did this step correctly you should see `(venv)` prefixed to your prompt.
-
-## How to start
-
-In order to start this project you'll need three terminal windows to start the flask server, react server, and nginx seperately:
-
-```sh
-# term 1
-
-# activate virtual environment
-
-python3 api/main.py
-
-# term 2
-
-yarn dev
-
-# term 3
-
-sudo nginx -c $PWD/nginx.conf # this only works on unix (i'm going to test on windows later)
-```
-
-## How to test API endpoints
-```sh
-# If you're running the standalone flask server:
-curl http://localhost:5000/<endpoint>
-
-# If you're running flask and nginx at the same time:
-curl http://localhost:2080/api/<endpoint>
-```
-
diff --git a/voerbak/readme.md b/voerbak/readme.md
new file mode 100644
index 0000000..6ec0600
--- /dev/null
+++ b/voerbak/readme.md
@@ -0,0 +1,77 @@
+# Voerbak
+
+Here's the source for voerbak, this project's connect 4 engine. The name comes from an abbreviation for the Dutch word for connect 4: Vier Op Een Rij -> VOER + bak = voerbak
+
+Voerbak uses a 1-dimensional array for storing the playfield, and it's printed after every move. The ordering is left to right, then bottom to top:
+
+35|36|37|38|39|40|41
+-|-|-|-|-|-|-
+28|29|30|31|32|33|34
+21|22|23|24|25|26|27
+14|15|16|17|18|19|20
+7|8|9|10|11|12|13
+0|1|2|3|4|5|6
+
+## Building
+
+```sh
+make
+```
+
+## Input
+
+Voerbak takes moves seperated by newlines from stdin. An example game would look like this:
+
+``` sh
+echo "4,3,3,2,1,2,2,7,1,7,1,7,1" | sed "s/,/\n/g" | ./voerbak
+# ^ convert "," to newline
+```
+
+## Output
+
+Voerbak outputs special messages in this format:
+
+```
+e:full
+^ \__/
+| |
+| message (without spaces)
+|
+message type
+```
+
+Message reference:
+
+type|name|messages
+-|-|-
+e|errors|full = column is full
+d|draw|full = board is full
+w|win|int-int = board indices where 4 was connected
+
+## Command-line arguments
+
+```sh
+$ ./voerbak --help
+Usage: voerbak [OPTION...] arguments
+Connect 4 game solver
+
+ -c, --solver=NAME Solver used for computing moves (unset is two
+ humans playing)
+ -h, --height=HEIGHT Field height (rows)
+ -v, --verbosity=LEVEL Verbosity, 0 = none (default), 1 = info, 2 =
+ debug
+ -w, --width=WIDTH Field width (columns)
+ -?, --help Give this help list
+ --usage Give a short usage message
+ -V, --version Print program version
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+Report bugs to https://github.com/lonkaars/po-4-op-een-rij/.
+```
+
+
+
+
+