Api
Seeding
- class compLib.Api.Seeding
Class used for communicating with seeding api.
- static getCargo(color: str) Tuple[Dict, int]
Makes the /api/listCargo call to the api.
- Parameters
color – Color parameter which specifies which cargo should be taken. (A string which is either “green”, “red”, “yellow” or “blue”
- Returns
Json Object and status code as returned by the api.
- Return type
Tuple[Dict, int]
- static get_delivery() Tuple[Dict, int]
Makes the /api/getDelivery call to the api.
- Returns
Json Object and status code as returned by the api.
- Return type
Tuple[Dict, int]
- static get_garbage() Tuple[Dict, int]
Makes the /api/getGarbage call to the api.
- Returns
Json Object and status code as returned by the api.
- Return type
Tuple[Dict, int]
- static get_material() Tuple[Dict, int]
Makes the /api/getMaterial call to the api.
- Returns
Json Object and status code as returned by the api.
- Return type
Tuple[Dict, int]
- static list_cargo() Tuple[Dict, int]
Makes the /api/listCargo call to the api.
- Returns
Json Object and status code as returned by the api.
- Return type
Tuple[Dict, int]
Double Elimination
- class compLib.Api.DoubleElim
Class used for communicating with double elimination api
- static get_goal() Tuple[compLib.Api.Position, int]
Get position of the goal.
- Returns
A Position object with x and y coordinates of the goal, rotation is always -1
- Return type
Tuple[Position, int]
- static get_items() Tuple[List[Dict], int]
Get a list with all current items.
- Returns
A list will all items currently on the game field. Items are dictionaries that look like: {“id”: 0, “x”: 0, “y”: 0}
- Return type
Tuple[List[Dict], int]
- static get_opponent() Tuple[compLib.Api.Position, int]
Get position of the opponents robot.
- Returns
A Position object with opponents robot position
- Return type
Tuple[Position, int]
- static get_position() Tuple[compLib.Api.Position, int]
Get position of the robot.
- Returns
A Position object with robot position
- Return type
Tuple[Position, int]
- static get_scores() Tuple[Dict, int]
Get the current scores.
- Returns
A dictionary with all scores included like: {“self”:2,”opponent”:0}
- Return type
Tuple[Dict, int]
Position
- class compLib.Api.Position(x, y, degrees)
Datastructure for holding a position.
Examples
Calling Seeding API
from compLib.Api import Seeding
park, code = Seeding.get_park()
if code == 403:
print(f"I am not in the correct zone to make that request!")
else:
park = park["id"]
print(f"I should move to parking position: {park}")
if park == 0:
print(f"I can't move to this position yet :(")
elif park == 1:
print(f"Moving to position 1!")
# drive to parking position using Motors module...
print(f"Now hopefully at position 1")
# drive back using Motors module...
elif park == 2:
# do something similar to park == 1..
elif park == 3:
# do something similar to park == 1..
success = Seeding.pay_park()
# check which code the api returned
if success == 204:
print(f"We scored some points!")
else:
print(f"We failed :(")
Calling Double Elimination API
from compLib.Api import DoubleElim
position, status = DoubleElim.get_position()
print(f"Position of my robot is: x={position.x}, y={position.y} and rotation is: {position.degrees}, the server responded with status code: {status}")
goal, status = DoubleElim.get_goal()
print(f"Goal is at: x={goal.x}, y={goal.y}, the server responded with status code: {status}")