/Kernel-web-server-version

AI-Cup kernel that communicate with client with Rest API

Primary LanguagePython

Kernel-web-server-version

AI-Cup kernel that communicate with clients with Rest API

Description

website This is a game where artificial intelligence programmers can participate and compete with each other by writing code for robots that try to win. The game is based on the Risk and the objective is to create the best robot possible to win against other players.

Requirements

To participate in this game, you need to install python 3.7 or higher. you can download python from here and install it on your system. don't forget to add python to your path by checking the checkbox in the installation wizard. after that you need to install the requirements by running the following command in the terminal or cmd in the project directory

pip install -r requirements.txt

How to run

to run server you just need to run the run.py file

List of APIs

API Type
/ GET
get_owners GET
get_troops_count GET
get_state GET
get_turn_number GET
get_adj GET
next_state GET
put_one_troop POST
put_troop POST
get_player_id GET
attack POST
move_troop POST
get_strategic_nodes GET
get_number_of_troops_to_put GET
get_reachable GET
fort POST
get_number_of_fort_troops GET

APIs description

/get_owners

(GET)

this API returns the owner of each node the key is the node id and the value is the owner id -1 means that the node is not owned by any player

output sample:

{
    "0": 0,
    "1": 2,
    "2": -1,
    "3": 1,
    "4": 2
}

/get_troops_count

(GET)

this API returns the number of troops in each node the key is the node id and the value is the number of troops

if a node has 0 troops it means that the node is not owned by any player.

output sample:

{
    "0": 4,
    "1": 0,
    "2": 5,
    "3": 11,
    "4": 20
}

/get_state

(GET)

this API returns the current state of the turn

1: put troop state
2: attack state
3: move troop state
4: fortification state

output sample:

{
    "state": 2
}

/get_turn_number

(GET)

this API returns the turn number of the game

output sample:

{
    "turn_number": 1
}

/

(GET)

this is API is just for test if the server is running or not

output sample:

{
    "message" : "Welcome, server is running"
}

/get_adj

(GET)

this API returns the list of adjacent nodes for each node

output sample:

{
    "1": [2, 3, 4],
    "2": [1, 3],
    "3": [1, 2, 4],
    "4": [1, 3, 5],
    "5": [4]
}

/next_state

(GET)

This function is used to change the state of the game to the next state 
1: put troop state
2: attack state
3: move troop state
4: fortification state

output sample:

{
"game_state": 2, "message": "success"
}

/get_number_of_troops_to_put

(GET)

this API returns the number of troops that you can put on the map

output sample:

{
    "number_of_troops": 10
}

/put_one_troop

(POST)

at the beginning the game gives you some troops to put on the map, players can put one troop in each turn this is the init state of the game

input sample:

{
    "node_id": 1
}

output sample1:

{
    "message":"troop added successfully"
}

output sample2:

{
    "error":"You can not put more than one troop in a turn"
}

/put_troop

(POST)

at the beginning of each turn you can put some troops on the map, you can use this API to choose the node that you want to put your troops and the number of troops that you want to put on that node

input sample:

{
    "node_id": 1,
    "number_of_troops": 2
}

output sample1:

{
    "message":"troop added successfully"
}

output sample2:

{
    "error":"This node is already owned by another player"
}

/get_player_id

(GET)

this API returns your player id

output sample:

{
    "player_id": 2
}

/attack

(POST)

you can use this API to attack a node with your node

input sample:

{
    "attacking_id": 1,
    "target_id": 2,
    "fraction": 0.5,
    "move_fraction": 0.5
}

rules: - the attacking_id node must be adjacent to the target_id node - the attacking_id node must be owned by you - the target_id node must be owned by another player

output sample1:

{
    "message":"attack is successful"
}

output sample2:

{
    "error":"fraction is not provided"
}

/move_troop

(POST)

you can use this API to move your troops from one node to another node

input sample:

{
    "source": 1,
    "destination": 2,
    "troop_count": 2
}

rules: - between source and destination nodes must be a path that you own all of the nodes in that path - the source node must have enough troops to move - at least one troop must stay in the source node - you should own both of the source and destination nodes - you can just move your troops once in each turn

output sample1:

{
    "message":"troops moved successfully"
}

output sample2:

{
    "error":"troop_count is not provided"
}

/get_strategic_nodes

(GET)

this API returns the strategic nodes id and their score

output sample:

{
    "strategic_nodes": [1, 5, 10, 20, 7, 9],
    "scores": [1, 2, 8, 4, 5, 3]
}

/get_reachable

(POST)

this API returns all nodes that the owner can move troops from the given node to them

input sample:

{
    "node_id": 5
}

output sample:

{
    "reachable": [1, 2, 3, 4]
}

/fort

(POST)

this API used to apply the fortification ability of the player

input sample:

{
    "node_id": 5,
    "troop_count": 15
}

output sample:

{
    "success":"the fortification ability is applied successfully"
}

/get_number_of_fort_troops

(GET)

this API used to get the number of fort troops on each node

output sample:

{
    "0": 4,
    "1": 0,
    "2": 1
}