Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
6 changes: 4 additions & 2 deletions src/blueprints/attack.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from flask import Blueprint , jsonify , current_app
from flask import request
import random
from src.tools.check_token import token_required
from src.tools.check_player import check_player

attack = Blueprint('attack',__name__)

main_game = current_app.config['main_game']

@attack.route('/attack',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def attack_func(player_id):
# this API used to attack a node from another node

Expand Down
6 changes: 4 additions & 2 deletions src/blueprints/fort.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from flask import Blueprint , jsonify , current_app
from flask import request
from src.tools.check_token import token_required
from src.tools.check_player import check_player

fort = Blueprint('fort',__name__)

main_game = current_app.config['main_game']

@fort.route('/fort',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def fort_func(player_id):
# this API used to apply the fortification ability of the player

Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_adj.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_adj = Blueprint('get_adj',__name__)

main_game = current_app.config['main_game']

@get_adj.route('/get_adj',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_adj_func(player_id):
# this API used to the list of the adjacent nodes of each node
output_dict = {}
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_number_of_fort_troops.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_number_of_fort_troops = Blueprint('get_number_of_fort_troops',__name__)

main_game = current_app.config['main_game']

@get_number_of_fort_troops.route('/get_number_of_fort_troops',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_number_of_fort_troops_func(player_id):
# this API used to get the number of fort troops on each node
output_dict = {}
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_number_of_troops_to_put.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player


get_number_of_troops_to_put = Blueprint('get_number_of_troops_to_put',__name__)

main_game = current_app.config['main_game']

@get_number_of_troops_to_put.route('/get_number_of_troops_to_put',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_number_of_troops_to_put_func(player_id):
# return the number of troops that the player can put on the map
output_dict={"number_of_troops": main_game.player_turn.number_of_troops_to_place}
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_owners.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_owners = Blueprint('get_owners',__name__)

main_game = current_app.config['main_game']

@get_owners.route('/get_owners',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_owners_func(player_id):
output_dict = {}
for node in main_game.nodes.values():
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_player_id.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player


get_player_id = Blueprint('get_player_id',__name__)

main_game = current_app.config['main_game']

@get_player_id.route('/get_player_id',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_player_number_func(player_id):
output_dict={'player_id': player_id}
return jsonify(output_dict),200
6 changes: 4 additions & 2 deletions src/blueprints/get_reachable.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from flask import Blueprint , jsonify , current_app
from flask import request
from src.tools.find_reachable import find_reachable
from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_reachable = Blueprint('get_reachable',__name__)

main_game = current_app.config['main_game']

@get_reachable.route('/get_reachable',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_reachable_func(player_id):
# this API used to find all the nodes that the owner can move it's troops from node_id to them
# body of the request should be like this:
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_state.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player


get_state = Blueprint('get_state',__name__)

main_game = current_app.config['main_game']

@get_state.route('/get_state',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_state_func(player_id):
output_dict={'state': main_game.state}
return jsonify(output_dict),200
7 changes: 4 additions & 3 deletions src/blueprints/get_strategic_nodes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_strategic_nodes = Blueprint('get_strategic_nodes',__name__)

main_game = current_app.config['main_game']

@get_strategic_nodes.route('/get_strategic_nodes',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_strategic_nodes_func(player_id):
output_dict={'strategic_nodes': [i.id for i in main_game.nodes.values() if i.is_strategic],
'score': [i.score_of_strategic for i in main_game.nodes.values() if i.is_strategic]}
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_troops_count.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_troops_count = Blueprint('get_troops_count',__name__)

main_game = current_app.config['main_game']

@get_troops_count.route('/get_troops_count',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_troops_count_func(player_id):
output_dict = {}
for node in main_game.nodes.values():
Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/get_turn_number.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

get_turn_number = Blueprint('get_turn_number',__name__)

main_game = current_app.config['main_game']

@get_turn_number.route('/get_turn_number',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def get_turn_number_func(player_id):
output_dict={'turn_number': main_game.turn_number}
return jsonify(output_dict),200
6 changes: 4 additions & 2 deletions src/blueprints/move_troop.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from flask import Blueprint , jsonify , current_app
from flask import request
from src.tools.find_path import find_path
from src.tools.check_token import token_required
from src.tools.check_player import check_player

move_troop = Blueprint('move_troop',__name__)

main_game = current_app.config['main_game']

@move_troop.route('/move_troop',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def move_troop_func(player_id):
# this API used to move troops from source to destination

Expand Down
7 changes: 4 additions & 3 deletions src/blueprints/next_state.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from flask import Blueprint , jsonify , current_app

from src.tools.check_token import token_required
from src.tools.check_player import check_player

next_state = Blueprint('next_state',__name__)

main_game = current_app.config['main_game']

@next_state.route('/next_state',methods=['GET'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def next_state_func(player_id):
'''
This function is used to change the state of the game to the next state
Expand Down
6 changes: 4 additions & 2 deletions src/blueprints/put_one_troop.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from flask import Blueprint , jsonify , current_app
from flask import request
from src.tools.check_token import token_required
from src.tools.check_player import check_player

put_one_troop = Blueprint('put_one_troop',__name__)

main_game = current_app.config['main_game']

@put_one_troop.route('/put_one_troop',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def put_one_troop_func(player_id):
# this API is used to put one troop on the map in the initial troop state of the game

Expand Down
6 changes: 4 additions & 2 deletions src/blueprints/put_troop.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from flask import Blueprint , jsonify , current_app
from flask import request
from src.tools.check_token import token_required
from src.tools.check_player import check_player

put_troop = Blueprint('put_troop',__name__)

main_game = current_app.config['main_game']

@put_troop.route('/put_troop',methods=['POST'])
@current_app.config['token_required']
@current_app.config['check_player']
@token_required
@check_player
def put_troop_func(player_id):
# this API used to put troops in the map in the put troop state

Expand Down
3 changes: 2 additions & 1 deletion src/blueprints/ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flask import current_app
from flask import jsonify
import os
from src.tools.check_token import token_required

# get the main_game instance from the flask global variable
main_game = current_app.config['main_game']
Expand All @@ -17,7 +18,7 @@


@ready.route('/ready', methods=['GET'])
@current_app.config['token_required']
@token_required
def ready_func(player_id):
try:
main_game.players[player_id].is_ready = True
Expand Down