Api¶
Seeding¶
-
class
compLib.Api.
Seeding
¶ Class used for communicating with seeding api
-
static
get_cargo
(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]
-
static
Double Elimination¶
-
class
compLib.Api.
DoubleElim
¶ Class used for communicating with double elimination api
-
static
get_goal
() → Tuple[compLib.Api.Position, int]¶ Makes the /api/getGoal call to the api.
- 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]¶ Makes the /api/getItems call to the api.
- 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_meteoroids
() → Tuple[List[Dict], int]¶ Makes the /api/getMeteoroids call to the api.
- Returns
A list will all meteoroids currently on the game field. Meteoroids are dictionaries that look like: {“x”: 0, “y”: 0}
- Return type
Tuple[List[Dict], int]
-
static
get_opponent
() → Tuple[compLib.Api.Position, int]¶ Makes the /api/getOp call to the api.
- Returns
A Position object with opponents robot position
- Return type
Tuple[Position, int]
-
static
get_position
() → Tuple[compLib.Api.Position, int]¶ Makes the /api/getPos call to the api.
- Returns
A Position object with robot position
- Return type
Tuple[Position, int]
-
static
get_scores
() → Tuple[Dict, int]¶ Makes the /api/getScores call to the api.
- Returns
A dictionary with all scores included like: {“self”:2,”opponent”:0}
- Return type
Tuple[Dict, int]
-
static
Examples¶
Calling Seeding API¶
from compLib.Api import Seeding
zones, code = Seeding.get_delivery()
if code == 403:
print(f"I am not in the correct zone to make that request!")
else:
print(f"First we need to go to zone {zone[0]}")
# put code here to follow line and drive to the zone
print(f"Now we need to go to zone {zone[1]}")
# put code here to follow line and drive to the next zone
print(f"Now we need to go to zone {zone[2]}")
# put code here to follow line and drive to the last zone
print(f"We delivered all packages, hopefully we scored some points!")
from compLib.Api import Seeding
package, code = Seeding.get_cargo("yellow")
if code == 403:
print(f"I am not in the correct zone to make that request!")
elif code == 404:
print(f"I am in the correct zone, but there is no yellow package here.")
elif code == 413:
print(f"I am in the correct zone, but I already have two packages loaded.")
else code == 200:
print(f"The {package['color']} has been picked up!")
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}")
from compLib.Api import DoubleElim
import time
# function which waits for the game to be started (you should include this in your double elimination program)
def wait_for_start():
_, status = DoubleElim.get_position()
while status == 503:
time.sleep(0.1)
_, status = DoubleElim.get_position()
wait_for_start()
print(f"Game has started, lets score some points!!")
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}")
opponent_position, status = DoubleElim.get_opponent()
print(f"Position of the opponents robot is: x={opponent_position.x}, y={opponent_position.y} and rotation is: {opponent_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}")
items, status = DoubleElim.get_items()
print(f"There are currently {len(items)} on the gameboard: {items}, the server responded with status code: {status}")
score, status = DoubleElim.get_score()
print(f"The current score of the game is {score}, the server responded with status code: {status}")
meteoroids, status = DoubleElim.get_meteoroids()
print(f"The current meteoroids in the game are {meteoroids}, the server responded with status code: {status}")
In this second example we wait until the game is started by the judges and then make all possible requests once. You should use the wait_for_start function in your double elimination program. If your robot starts too soon your run will not count!