Api

Seeding

class compLib.Api.Seeding

Class used for communicating with seeding api

static get_park() → Tuple[Dict, int]

Get a parkingsapce from the api.

Returns

Json Object and status code as returned by the api.

Return type

Tuple[Dict, int]

static pay_park() → int

Pay for parking.

Returns

Status code as returned by the api.

Return type

int

static simon_says() → Tuple[Dict, int]

Get next simon says zone from 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()compLib.Api.Position

Get position of the goal

Returns

A Position object with x and y coordinates of the goal, rotation is always -1

Return type

Position

static get_items() → list

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}

Return type

list

static get_opponent()compLib.Api.Position

Get position of the opponents robot

Returns

A Position object with opponents robot position

Return type

Position

static get_position()compLib.Api.Position

Get position of the robot

Returns

A Position object with robot position

Return type

Position

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 = DoubleElim.get_position()
print(f"Position of my robot is: x={position.x}, y={position.y} and rotation is: {position.degrees}")

goal = DoubleElim.get_goal()
print(f"Goal is at: x={goal.x}, y={goal.y}")