.. _lib_api: Api **** Seeding ======== .. autoclass:: compLib.Api.Seeding :members: Double Elimination =================== .. autoclass:: compLib.Api.DoubleElim :members: Position ======== .. autoclass:: compLib.Api.Position :members: Examples ======== Calling Seeding API --------------------- .. code-block:: python 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!") .. code-block:: python 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 ---------------------------------- .. code-block:: python 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}") .. code-block:: python 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_meteoroid() 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!