### Install and Watch Client Source: https://github.com/battlecode/battlecode26/blob/master/README.md Navigate to the client directory and run these commands to install dependencies and start the development server. The client will be available at http://localhost:8080. ```bash npm run install-all ``` ```bash npm run watch ``` -------------------------------- ### Install Dependencies Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Install project dependencies and prettier before running the client. ```bash npm i ``` -------------------------------- ### Porting Git Repository Example Source: https://github.com/battlecode/battlecode26/blob/master/README.md Example steps for porting a Git repository using git-filter-repo. This involves cloning a new repository, renaming tags, and pulling with unrelated histories. ```bash cd .. git clone https://github.com/battlecode/battlehack20 battlehack20-export cd battlehack20-export git filter-repo --tag-rename '':'bh20-' cd .. cd battlecode21 git pull ../battlehack20-export —allow-unrelated-histories ``` -------------------------------- ### Install git-filter-repo Source: https://github.com/battlecode/battlecode26/blob/master/README.md Install the git-filter-repo tool using pip. This tool is used for advanced Git repository manipulation, such as porting codebases. ```bash pip3 install git-filter-repo ``` -------------------------------- ### Run Web App Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Start the web application in watch mode for local development. ```bash npm run watch ``` -------------------------------- ### Run Headless Game Source: https://github.com/battlecode/battlecode26/blob/master/README.md Use this command to run a headless game. The replay file will be saved in the /matches directory. Ensure you have Gradle installed. ```bash ./gradlew headless ``` -------------------------------- ### Run Tauri Desktop App Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Build and run the desktop version of the application using Tauri. Ensure the Rust compiler is installed first. ```bash npm run tauri-watch ``` -------------------------------- ### get_type Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the type of the robot. ```APIDOC ## get_type ### Description Gets the type of the robot. ### Method N/A (Function Call) ### Returns - UnitType - The type of the robot. ``` -------------------------------- ### get_team Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the team the robot belongs to. ```APIDOC ## get_team ### Description Gets the team the robot belongs to. ### Method N/A (Function Call) ### Returns - Team - The team the robot is on. ``` -------------------------------- ### get_location Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the current location of the robot on the map. ```APIDOC ## get_location ### Description Gets the current location of the robot on the map. ### Method N/A (Function Call) ### Returns - MapLocation - The current location of the robot. ``` -------------------------------- ### get_raw_cheese Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the amount of raw cheese the robot is currently holding. ```APIDOC ## get_raw_cheese ### Description Gets the amount of raw cheese the robot is currently holding. ### Method N/A (Function Call) ### Returns - int - The amount of raw cheese held. ``` -------------------------------- ### get_dirt Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the amount of dirt the robot is currently holding. ```APIDOC ## get_dirt ### Description Gets the amount of dirt the robot is currently holding. ### Method N/A (Function Call) ### Returns - int - The amount of dirt held. ``` -------------------------------- ### get_health Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the current health of the robot. ```APIDOC ## get_health ### Description Gets the current health of the robot. ### Method N/A (Function Call) ### Returns - int - The current health. ``` -------------------------------- ### get_direction Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the current direction the robot is facing. ```APIDOC ## get_direction ### Description Gets the current direction the robot is facing. ### Method N/A (Function Call) ### Returns - Direction - The current direction. ``` -------------------------------- ### get_id Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the unique ID of the robot. ```APIDOC ## get_id ### Description Gets the unique ID of the robot. ### Method N/A (Function Call) ### Returns - int - The robot's ID. ``` -------------------------------- ### get_global_cheese Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the total amount of cheese currently on the map. ```APIDOC ## get_global_cheese ### Description Gets the total amount of cheese currently on the map. ### Method N/A (Function Call) ### Returns - int - The total amount of cheese on the map. ``` -------------------------------- ### get_current_rat_cost Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the current cost to place a rat trap. ```APIDOC ## get_current_rat_cost ### Description Gets the current cost to place a rat trap. ### Method N/A (Function Call) ### Returns - int - The current cost of a rat trap. ``` -------------------------------- ### get_turning_cooldown_turns Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the number of turns remaining before the robot can turn again. ```APIDOC ## get_turning_cooldown_turns ### Description Gets the number of turns remaining before the robot can turn again. ### Method N/A (Function Call) ### Returns - int - The number of turns until the next turn is possible. ``` -------------------------------- ### Getting All Unit Locations Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Retrieves a list of all map locations occupied by units of a specific type within a given radius. ```python def get_all_type_locations(unit_type: UnitType, center: MapLocation) -> list[MapLocation]: pass ``` -------------------------------- ### get_movement_cooldown_turns Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the number of turns remaining before the robot can move again. ```APIDOC ## get_movement_cooldown_turns ### Description Gets the number of turns remaining before the robot can move again. ### Method N/A (Function Call) ### Returns - int - The number of turns until the next move is possible. ``` -------------------------------- ### Map Location Utilities Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions related to map locations, including getting all locations within a radius and checking if a location is occupied. ```python def get_all_part_locations() -> list[MapLocation]: pass def is_location_occupied(loc: MapLocation) -> bool: pass ``` -------------------------------- ### get_number_cat_traps Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the number of cat traps the robot is currently holding. ```APIDOC ## get_number_cat_traps ### Description Gets the number of cat traps the robot is currently holding. ### Method N/A (Function Call) ### Returns - int - The number of cat traps held. ``` -------------------------------- ### Robot Property Accessors Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions to get specific properties of the current robot, including health, ID, movement cooldowns, and carrying status. ```python def get_carrying() -> RobotInfo: pass def get_dirt() -> int: pass def get_health() -> int: pass def get_id() -> int: pass def get_movement_cooldown_turns() -> int: pass def get_turning_cooldown_turns() -> int: pass def is_being_carried() -> bool: pass def is_being_thrown() -> bool: pass ``` -------------------------------- ### get_number_rat_traps Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Gets the number of rat traps the robot is currently holding. ```APIDOC ## get_number_rat_traps ### Description Gets the number of rat traps the robot is currently holding. ### Method N/A (Function Call) ### Returns - int - The number of rat traps held. ``` -------------------------------- ### Run Electron Desktop App Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Alternative command to run the desktop version using Electron if Tauri fails. ```bash npm run electron-watch ``` -------------------------------- ### Build Battlecode Engine Source: https://github.com/battlecode/battlecode26/blob/master/engine/README.md Commands to build the Battlecode engine, generate Javadocs, and run tests. Ensure Java 1.8 and JAVA_HOME are set correctly. ```bash ./gradlew build ``` ```bash ./gradlew javadoc ``` ```bash ./gradlew test ``` -------------------------------- ### Format Files with Prettier Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Standardize code formatting across changed files using Prettier. ```bash npx prettier [file].tsx --write ``` -------------------------------- ### Run Headless Game with Specific Maps and Teams Source: https://github.com/battlecode/battlecode26/blob/master/README.md Customize the game run by specifying maps and teams. This command allows you to test specific configurations. Ensure the specified teams and maps exist. ```bash ./gradlew headless -Pmaps=maptestsmall -PteamA=examplefuncsplayer -PteamB=examplefuncsplayer ``` -------------------------------- ### is_action_ready Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Checks if the robot is ready to perform an action. ```APIDOC ## is_action_ready ### Description Checks if the robot is ready to perform an action. ### Method N/A (Function Call) ### Returns - bool - True if the robot can perform an action, False otherwise. ``` -------------------------------- ### is_movement_ready Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Checks if the robot is ready to move. ```APIDOC ## is_movement_ready ### Description Checks if the robot is ready to move. ### Method N/A (Function Call) ### Returns - bool - True if the robot can move, False otherwise. ``` -------------------------------- ### is_turning_ready Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Checks if the robot is ready to turn. ```APIDOC ## is_turning_ready ### Description Checks if the robot is ready to turn. ### Method N/A (Function Call) ### Returns - bool - True if the robot can turn, False otherwise. ``` -------------------------------- ### RobotController Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt Costs for methods providing information about the robot and its environment. ```APIDOC ## RobotController Methods ### `getRoundNum()` - **Cost**: 1 - **Description**: Returns the current round number. ### `getMapWidth()` - **Cost**: 1 - **Description**: Returns the width of the game map. ### `getMapHeight()` - **Cost**: 1 - **Description**: Returns the height of the game map. ### `isCooperation()` - **Cost**: 1 - **Description**: Checks if the game mode is cooperation. ### `getID()` - **Cost**: 1 - **Description**: Returns the unique ID of this robot. ### `getTeam()` - **Cost**: 1 - **Description**: Returns the team this robot belongs to. ### `getLocation()` - **Cost**: 1 - **Description**: Returns the current location of this robot. ### `getAllPartLocations()` - **Cost**: 5 - **Description**: Returns a list of all part locations on the map. ### `getDirection()` - **Cost**: 1 - **Description**: Returns the current direction this robot is facing. ### `getHealth()` - **Cost**: 1 - **Description**: Returns the current health of this robot. ### `getRawCheese()` - **Cost**: 1 - **Description**: Returns the amount of raw cheese this robot is carrying. ### `getGlobalCheese()` - **Cost**: 1 - **Description**: Returns the total amount of global cheese collected by the team. ### `getAllCheese()` - **Cost**: 1 - **Description**: Returns the total amount of cheese this robot is carrying. ### `getDirt()` - **Cost**: 1 - **Description**: Returns the amount of dirt this robot is carrying. ### `getType()` - **Cost**: 1 - **Description**: Returns the type of this robot. ### `getCarrying()` - **Cost**: 1 - **Description**: Returns the type of object this robot is carrying. ### `isBeingThrown()` - **Cost**: 1 - **Description**: Checks if this robot is currently being thrown. ### `isBeingCarried()` - **Cost**: 1 - **Description**: Checks if this robot is currently being carried. ### `onTheMap(MapLocation loc)` - **Cost**: 5 - **Description**: Checks if a given location is on the map. ### `canSenseLocation(MapLocation loc)` - **Cost**: 5 - **Description**: Checks if the robot can sense a given location. ### `isLocationOccupied(MapLocation loc)` - **Cost**: 5 - **Description**: Checks if a given location is occupied by another robot. ### `canSenseRobotAtLocation(MapLocation loc)` - **Cost**: 5 - **Description**: Checks if the robot can sense another robot at a specific location. ### `senseRobotAtLocation(MapLocation loc)` - **Cost**: 15 - **Description**: Senses the robot at a specific location. ### `canSenseRobot(int robotID)` - **Cost**: 5 - **Description**: Checks if the robot can sense another robot by its ID. ### `senseRobot(int robotID)` - **Cost**: 25 - **Description**: Senses a robot by its ID. ### `senseNearbyRobots()` - **Cost**: 100 - **Description**: Senses all robots within the robot's sensor range. ### `sensePassability(MapLocation loc)` - **Cost**: 5 - **Description**: Senses the passability of a given location. ### `senseMapInfo(MapLocation loc)` - **Cost**: 5 - **Description**: Senses information about a specific map location. ### `senseNearbyMapInfos()` - **Cost**: 100 - **Description**: Senses information about all map locations within the robot's sensor range. ### `adjacentLocation(Direction dir)` - **Cost**: 1 - **Description**: Returns the location adjacent to the current location in the given direction. ### `getAllLocationsWithinRadiusSquared(int radiusSquared)` - **Cost**: 100 - **Description**: Returns all map locations within a specified squared radius. ### `isActionReady(Action action)` - **Cost**: 1 - **Description**: Checks if a specific action is ready to be performed. ``` -------------------------------- ### Team Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt This section lists methods available on the `Team` interface and their associated costs. ```APIDOC ## Team Methods ### Description Provides a list of methods available on the `Team` interface, along with their associated turn costs. ### Methods - **opponent** (1 turn) - Callable by player: false - **isPlayer** (1 turn) - Callable by player: false ``` -------------------------------- ### MapInfo Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt This section lists methods available on the `MapInfo` interface and their associated costs. ```APIDOC ## MapInfo Methods ### Description Provides a list of methods available on the `MapInfo` interface, along with their associated turn costs. ### Methods - **getMapLocation** (1 turn) - Callable by player: false - **isPassable** (2 turns) - Callable by player: false - **toString** (15 turns) - Callable by player: false - **isWall** (2 turns) - Callable by player: false - **isDirt** (2 turns) - Callable by player: false - **hasCheeseMine** (2 turns) - Callable by player: false - **getTrap** (2 turns) - Callable by player: false - **getCheeseAmount** (2 turns) - Callable by player: false ``` -------------------------------- ### RobotController Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md These are methods available through the RobotController (aliased as `rc`) for controlling your units. ```APIDOC ## RobotController Methods (rc) ### `rc.get_round_num()` Returns the current round number. ### `rc.get_map_width()` Returns the width of the game map. ### `rc.get_map_height()` Returns the height of the game map. ### `rc.adjacent_location(dir: Direction)` Returns the MapLocation adjacent to the current unit in the given `Direction`. ### `rc.attack(loc: MapLocation, cheese_amount: int = 0)` Attacks the target location, optionally with a specified amount of cheese. ### `rc.become_rat_king()` Attempts to make the current unit the rat king. ### `rc.build_rat(loc: MapLocation)` Builds a rat at the specified location. ### `rc.can_attack(loc: MapLocation, cheese_amount: int = 0)` Checks if the unit can attack the target location with the specified cheese amount. ### `rc.can_become_rat_king()` Checks if the unit can become the rat king. ### `rc.can_build_rat(loc: MapLocation)` Checks if a rat can be built at the specified location. ### `rc.can_carry_rat(loc: MapLocation)` Checks if the unit can carry a rat from the specified location. ### `rc.can_drop_rat(dir: Direction)` Checks if the unit can drop a rat in the specified direction. ### `rc.can_move(dir: Direction)` Checks if the unit can move in the specified direction. ### `rc.can_move_forward()` Checks if the unit can move forward. ### `rc.can_pick_up_cheese(loc: MapLocation)` Checks if the unit can pick up cheese at the specified location. ### `rc.can_place_cat_trap(loc: MapLocation)` Checks if a cat trap can be placed at the specified location. ### `rc.can_place_dirt(loc: MapLocation)` Checks if dirt can be placed at the specified location. ### `rc.can_place_rat_trap(loc: MapLocation)` Checks if a rat trap can be placed at the specified location. ### `rc.can_remove_cat_trap(loc: MapLocation)` Checks if a cat trap can be removed from the specified location. ### `rc.can_remove_dirt(loc: MapLocation)` Checks if dirt can be removed from the specified location. ### `rc.can_remove_rat_trap(loc: MapLocation)` Checks if a rat trap can be removed from the specified location. ### `rc.can_sense_location(loc: MapLocation)` Checks if the unit can sense the specified location. ### `rc.can_sense_robot(id: int)` Checks if the unit can sense the robot with the given ID. ### `rc.can_sense_robot_at_location(loc: MapLocation)` Checks if the unit can sense a robot at the specified location. ### `rc.can_throw_rat()` Checks if the unit can throw a rat. ### `rc.can_transfer_cheese(loc: MapLocation, cheese_amount: int)` Checks if the unit can transfer the specified amount of cheese to the given location. ### `rc.can_turn(dir: Direction = ...)` Checks if the unit can turn in the specified direction. Can be called with or without a direction. ### `rc.carry_rat(loc: MapLocation)` Attempts to carry a rat from the specified location. ### `rc.disintegrate()` Disintegrates the current unit. ### `rc.drop_rat(dir: Direction)` Drops a carried rat in the specified direction. ### `rc.get_action_cooldown_turns()` Returns the number of turns remaining in the action cooldown. ### `rc.get_all_cheese()` Returns the total amount of cheese available on the map. ``` -------------------------------- ### RobotController Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt This section lists the methods available on the RobotController interface and their associated costs in turns. The boolean indicates if the method is callable by the player. ```APIDOC ## RobotController Methods ### Description Provides a list of methods available on the `RobotController` interface, along with their associated turn costs and whether they are directly callable by the player. ### Methods - **getActionCooldownTurns** (1 turn) - Callable by player: true - **isMovementReady** (1 turn) - Callable by player: true - **isTurningReady** (1 turn) - Callable by player: true - **getMovementCooldownTurns** (1 turn) - Callable by player: true - **getTurningCooldownTurns** (1 turn) - Callable by player: true - **canMoveForward** (10 turns) - Callable by player: true - **canMove** (10 turns) - Callable by player: true - **moveForward** (1 turn) - Callable by player: true - **move** (1 turn) - Callable by player: true - **canTurn** (1 turn) - Callable by player: true - **turn** (1 turn) - Callable by player: true - **getCurrentRatCost** (1 turn) - Callable by player: true - **canBuildRat** (10 turns) - Callable by player: true - **buildRat** (20 turns) - Callable by player: true - **canBecomeRatKing** (10 turns) - Callable by player: true - **becomeRatKing** (20 turns) - Callable by player: true - **canPlaceDirt** (5 turns) - Callable by player: true - **placeDirt** (5 turns) - Callable by player: true - **canRemoveDirt** (5 turns) - Callable by player: true - **removeDirt** (5 turns) - Callable by player: true - **canPlaceRatTrap** (5 turns) - Callable by player: true - **placeRatTrap** (5 turns) - Callable by player: true - **canRemoveRatTrap** (5 turns) - Callable by player: true - **removeRatTrap** (5 turns) - Callable by player: true - **canPlaceCatTrap** (5 turns) - Callable by player: true - **placeCatTrap** (5 turns) - Callable by player: true - **canRemoveCatTrap** (5 turns) - Callable by player: true - **removeCatTrap** (5 turns) - Callable by player: true - **canPickUpCheese** (5 turns) - Callable by player: true - **pickUpCheese** (5 turns) - Callable by player: true - **canAttack** (10 turns) - Callable by player: true - **attack** (10 turns) - Callable by player: true - **squeak** (50 turns) - Callable by player: true - **readSqueaks** (10 turns) - Callable by player: true - **writeSharedArray** (50 turns) - Callable by player: true - **readSharedArray** (10 turns) - Callable by player: true - **canTransferCheese** (5 turns) - Callable by player: true - **transferCheese** (5 turns) - Callable by player: true - **throwRat** (25 turns) - Callable by player: true - **canThrowRat** (10 turns) - Callable by player: true - **dropRat** (10 turns) - Callable by player: true - **canDropRat** (10 turns) - Callable by player: true - **canCarryRat** (5 turns) - Callable by player: true - **carryRat** (10 turns) - Callable by player: true - **disintegrate** (0 turns) - Callable by player: true - **resign** (0 turns) - Callable by player: true - **setIndicatorDot** (1 turn) - Callable by player: true - **setIndicatorLine** (1 turn) - Callable by player: true - **setIndicatorString** (1 turn) - Callable by player: true - **setTimelineMarker** (1 turn) - Callable by player: true ``` -------------------------------- ### Clock Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt Costs for methods related to time and bytecode management. ```APIDOC ## Clock Methods ### `yield()` - **Cost**: 0 - **Description**: Allows a robot to yield control, useful for managing turn-based execution. ### `getBytecodesLeft()` - **Cost**: 0 - **Description**: Returns the number of bytecodes remaining in the current turn. ### `getBytecodeNum()` - **Cost**: 0 - **Description**: Returns the current bytecode number within the turn. ### `getTimeLeft()` - **Cost**: 0 - **Description**: Returns the time remaining in the current turn in milliseconds. ### `getTimeElapsed()` - **Cost**: 0 - **Description**: Returns the time elapsed in the current turn in milliseconds. ``` -------------------------------- ### Robot Actions: Status and State Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions to check robot status and manage actions. Use `is_action_ready` and `is_movement_ready` to ensure robots can perform tasks. ```python def is_action_ready() -> bool: pass def is_movement_ready() -> bool: pass def is_turning_ready() -> bool: pass ``` -------------------------------- ### Robot Actions: Indicators and Debugging Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions for setting visual indicators on the map and for debugging. Use `set_indicator_dot`, `set_indicator_string`, `set_indicator_line`, and `set_timeline_marker`. ```python def set_indicator_dot(loc: MapLocation, r: int, g: int, b: int) -> None: pass def set_indicator_string(text: str) -> None: pass def set_indicator_line(startLoc: MapLocation, endLoc: MapLocation, r: int, g: int, b: int) -> None: pass def set_timeline_marker(text: str, r: int, g: int, b: int) -> None: pass ``` -------------------------------- ### Robot Controller - Unit Actions Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Enables actions such as attacking, building, and carrying rats. Some actions have associated cheese costs. ```python class RobotController: def attack(loc: MapLocation, cheese_amount: int = 0) -> None: pass def become_rat_king() -> None: pass def build_rat(loc: MapLocation) -> None: pass def can_attack(loc: MapLocation, cheese_amount: int = 0) -> bool: pass def can_become_rat_king() -> bool: pass def can_build_rat(loc: MapLocation) -> bool: pass def can_carry_rat(loc: MapLocation) -> bool: pass def can_drop_rat(dir: Direction) -> bool: pass def can_pick_up_cheese(loc: MapLocation) -> bool: pass def can_place_cat_trap(loc: MapLocation) -> bool: pass def can_place_dirt(loc: MapLocation) -> bool: pass def can_place_rat_trap(loc: MapLocation) -> bool: pass def can_remove_cat_trap(loc: MapLocation) -> bool: pass def can_remove_dirt(loc: MapLocation) -> bool: pass def can_remove_rat_trap(loc: MapLocation) -> bool: pass def can_throw_rat() -> bool: pass def can_transfer_cheese(loc: MapLocation, cheese_amount: int) -> bool: pass def carry_rat(loc: MapLocation) -> None: pass def disintegrate() -> None: pass def drop_rat(dir: Direction) -> None: pass ``` -------------------------------- ### move_forward Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Moves the robot one step forward in its current direction. ```APIDOC ## move_forward ### Description Moves the robot one step forward in its current direction. ### Method N/A (Function Call) ### Returns - None ``` -------------------------------- ### Team.opponent Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Returns the opposing team. ```APIDOC ## Team.opponent ### Description Returns the opposing team. ### Method N/A (Function Call) ### Returns - Team - The opposing team. ``` -------------------------------- ### pick_up_cheese Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Attempts to pick up cheese from a specified location. ```APIDOC ## pick_up_cheese ### Description Attempts to pick up cheese from a specified location. Calling this function with only the first argument makes the rat pick up the maximum amount of cheese possible. ### Method N/A (Function Call) ### Parameters - **loc** (MapLocation) - The location to pick up cheese from. - **amount** (int, optional) - The amount of cheese to pick up. Defaults to maximum possible. ``` -------------------------------- ### Robot Controller - Cheese Management Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions related to managing cheese, including picking it up and transferring it. ```python class RobotController: def get_all_cheese() -> int: pass ``` -------------------------------- ### Fix Flatbuffers Schema Source: https://github.com/battlecode/battlecode26/blob/master/client/README.md Run this command to resolve issues with flatbuffers type declarations. ```bash npm run fix-schema ``` -------------------------------- ### Robot Actions: Miscellaneous Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Other robot actions including `get_type`, `get_location`, `get_direction`, `throw_rat`, and `resign`. ```python def get_direction() -> Direction: pass def get_location() -> MapLocation: pass def get_type() -> UnitType: pass def throw_rat() -> None: pass def resign() -> None: pass ``` -------------------------------- ### set_timeline_marker Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Sets a marker on the game timeline with a specified text and color. ```APIDOC ## set_timeline_marker ### Description Sets a marker on the game timeline with a specified text and color. ### Method N/A (Function Call) ### Parameters - **text** (str) - The text for the timeline marker. - **r** (int) - The red component of the color (0-255). - **g** (int) - The green component of the color (0-255). - **b** (int) - The blue component of the color (0-255). ``` -------------------------------- ### Robot Controller - Sensing and Cooldowns Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Check if the robot can sense specific locations or robots, and retrieve action cooldown information. ```python class RobotController: def can_sense_location(loc: MapLocation) -> bool: pass def can_sense_robot(id: int) -> bool: pass def can_sense_robot_at_location(loc: MapLocation) -> bool: pass def get_action_cooldown_turns() -> int: pass ``` -------------------------------- ### Logging Function Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Use the `log` function for printing debug messages from your bot. It accepts a variable number of arguments. ```python def log(*messages) -> None: pass ``` -------------------------------- ### Robot Actions: Movement Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions for controlling robot movement. Use `move` for directional movement and `move_forward` for simple forward motion. Ensure movement actions are ready before calling. ```python def move(dir: Direction) -> None: pass def move_forward() -> None: pass ``` -------------------------------- ### Robot Controller - Movement and Location Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Provides methods for calculating adjacent locations and checking movement capabilities. ```python class RobotController: def adjacent_location(dir: Direction) -> MapLocation: pass def can_move(dir: Direction) -> bool: pass def can_move_forward() -> bool: pass ``` -------------------------------- ### move Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Attempts to move the robot in a specified direction. ```APIDOC ## move ### Description Attempts to move the robot in a specified direction. ### Method N/A (Function Call) ### Parameters - **dir** (Direction) - The direction to move. ### Returns - None ``` -------------------------------- ### Global Functions Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md These are global functions available for use in your Battlecode 2026 Python bot. ```APIDOC ## Global Functions ### `log(*messages)` Logs messages for debugging purposes. Use this instead of `print`. ### `bottom_left_distance_squared_to(loc1: MapLocation, loc2: MapLocation)` Calculates the squared distance between two MapLocations, considering the bottom-left origin. ### `direction_to(loc1: MapLocation, loc2: MapLocation)` Determines the direction from `loc1` to `loc2`. ### `distance_squared_to(loc1: MapLocation, loc2: MapLocation)` Calculates the squared Euclidean distance between two MapLocations. ### `is_adjacent_to(loc1: MapLocation, loc2: MapLocation)` Checks if two MapLocations are adjacent to each other. ### `is_within_distance_squared(loc1: MapLocation, loc2: MapLocation, distance_squared: int, theta: float = 360, use_bottom_left: bool = False)` Checks if `loc2` is within a specified squared distance from `loc1`, with optional angle and origin considerations. ### `get_all_type_locations(unit_type: UnitType, center: MapLocation)` Retrieves all locations of a specific `UnitType` near a given `center` MapLocation. ``` -------------------------------- ### place_dirt Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Places dirt at the specified location. ```APIDOC ## place_dirt ### Description Places dirt at the specified location. ### Method N/A (Function Call) ### Parameters - **loc** (MapLocation) - The location to place dirt. ``` -------------------------------- ### MapLocation Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt Costs for methods related to map coordinate manipulation and comparison. ```APIDOC ## MapLocation Methods ### `add(MapLocation other)` - **Cost**: 2 - **Description**: Adds another MapLocation to this one. ### `compareTo(MapLocation other)` - **Cost**: 2 - **Description**: Compares this MapLocation with another. ### `directionTo(MapLocation other)` - **Cost**: 2 - **Description**: Returns the direction from this location to another. ### `distanceSquaredTo(MapLocation other)` - **Cost**: 2 - **Description**: Calculates the squared distance between two locations. ### `equals(MapLocation other)` - **Cost**: 2 - **Description**: Checks if two MapLocations are equal. ### `hashCode()` - **Cost**: 2 - **Description**: Returns the hash code for this MapLocation. ### `isWithinDistanceSquared(MapLocation other, int distSq)` - **Cost**: 2 - **Description**: Checks if another location is within a specified squared distance. ### `isAdjacentTo(MapLocation other)` - **Cost**: 2 - **Description**: Checks if another location is adjacent to this one. ### `isWithinSensorRadius(MapLocation other)` - **Cost**: 2 - **Description**: Checks if another location is within the sensor radius. ### `subtract(MapLocation other)` - **Cost**: 2 - **Description**: Subtracts another MapLocation from this one. ### `toString()` - **Cost**: 2 - **Description**: Returns a string representation of the MapLocation. ### `translate(Direction dir)` - **Cost**: 2 - **Description**: Translates this location by a given direction. ### `valueOf()` - **Cost**: 25 - **Description**: Creates a MapLocation from a string representation. ``` -------------------------------- ### get_carrying Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Returns information about the robot being carried, if any. ```APIDOC ## get_carrying ### Description Returns information about the robot being carried, if any. ### Method N/A (Function Call) ### Returns - RobotInfo - Information about the carried robot, or an empty value if none. ``` -------------------------------- ### set_indicator_string Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Sets a string indicator for the robot. ```APIDOC ## set_indicator_string ### Description Sets a string indicator for the robot. ### Method N/A (Function Call) ### Parameters - **text** (str) - The string to display as an indicator. ``` -------------------------------- ### Direction Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt Costs for methods related to directional calculations and manipulation. ```APIDOC ## Direction Methods ### `equals(Direction other)` - **Cost**: 1 - **Description**: Checks if two directions are equal. ### `getDeltaX()` - **Cost**: 1 - **Description**: Returns the change in the x-coordinate for this direction. ### `getDeltaY()` - **Cost**: 1 - **Description**: Returns the change in the y-coordinate for this direction. ### `rotateLeft()` - **Cost**: 1 - **Description**: Returns the direction rotated 45 degrees to the left. ### `rotateRight()` - **Cost**: 1 - **Description**: Returns the direction rotated 45 degrees to the right. ### `opposite()` - **Cost**: 1 - **Description**: Returns the opposite direction. ### `allDirections()` - **Cost**: 1 - **Description**: Returns an array of all possible directions. ### `cardinalDirections()` - **Cost**: 1 - **Description**: Returns an array of the four cardinal directions. ### `getDirectionOrderNum()` - **Cost**: 1 - **Description**: Returns a numerical representation of the direction's order. ### `fromDelta(int dx, int dy)` - **Cost**: 1 - **Description**: Creates a Direction object from delta x and y values. ``` -------------------------------- ### Map Sensing: Location-based Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions to sense information about specific map locations. Use `is_location_occupied`, `on_the_map`, `sense_passability`, and `sense_map_info`. ```python def is_location_occupied(loc: MapLocation) -> bool: pass def on_the_map(loc: MapLocation) -> bool: pass def sense_passability(loc: MapLocation) -> int: pass def sense_map_info(loc: MapLocation) -> MapInfo: pass ``` -------------------------------- ### RobotInfo Class Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Contains information about a robot on the map. ```APIDOC class RobotInfo: """ Fields: - id: int - team: Team - type: UnitType - health: int - location: MapLocation - direction: Direction - chirality: int - cheese_amount: int - carrying_robot: RobotInfo """ pass ``` -------------------------------- ### transfer_cheese Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Transfers a specified amount of cheese to another robot at a given location. ```APIDOC ## transfer_cheese ### Description Transfers a specified amount of cheese to another robot at a given location. ### Method N/A (Function Call) ### Parameters - **loc** (MapLocation) - The location of the robot to transfer cheese to. - **cheese_amount** (int) - The amount of cheese to transfer. ``` -------------------------------- ### GameActionException Classes Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Defines custom exceptions for game actions. `GameActionExceptionType` enumerates error types, and `GameActionException` provides details about the error. ```python class GameActionExceptionType(Enum): INTERNAL_ERROR = 0 NOT_ENOUGH_RESOURCE = 1 CANT_MOVE_THERE = 2 IS_NOT_READY = 3 CANT_SENSE_THAT = 4 OUT_OF_RANGE = 5 CANT_DO_THAT = 6 NO_ROBOT_THERE = 7 ROUND_OUT_OF_RANGE = 8 class GameActionException(Exception): """ Fields: - type: GameActionExceptionType - message: str (cannot use e.message, must use str(e) to get the message) """ pass ``` -------------------------------- ### Update FlatBuffers Schema Generation Command Source: https://github.com/battlecode/battlecode26/blob/master/schema/README.md Command to regenerate TypeScript and Java files from the FlatBuffers schema definition. ```bash flatc --ts -o ts battlecode.fbs ``` ```bash flatc --java -o java battlecode.fbs ``` -------------------------------- ### Robot Actions: Interaction Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions for interacting with game elements like cheese, traps, and dirt. Note that `pick_up_cheese` can pick up the maximum amount if only the location is provided. ```python def pick_up_cheese(loc: MapLocation, amount: int = ...) -> None: """ Calling this function with only the first argument makes the rat pick up the maximum amount of cheese possible. """ pass def place_cat_trap(loc: MapLocation) -> None: pass def place_dirt(loc: MapLocation) -> None: pass def place_rat_trap(loc: MapLocation) -> None: pass def remove_cat_trap(loc: MapLocation) -> None: pass def remove_dirt(loc: MapLocation) -> None: pass def remove_rat_trap(loc: MapLocation) -> None: pass def transfer_cheese(loc: MapLocation, cheese_amount: int) -> None: pass ``` -------------------------------- ### throw_rat Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Throws a rat. ```APIDOC ## throw_rat ### Description Throws a rat. ### Method N/A (Function Call) ``` -------------------------------- ### UnitType Enum Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Defines the different types of units available in the game. ```APIDOC class UnitType(Enum): """ Fields: - health: int - size: int - vision_cone_radius_squared: int - vision_cone_angle: int - action_cooldown: int - movement_cooldown: int - bytecode_limit: int """ BABY_RAT = (100, 1, 20, 90, 10, 10, 17500) RAT_KING = (500, 3, 25, 360, 10, 40, 20000) CAT = (10_000, 2, 17, 180, 15, 20, 17500) def uses_bottom_left_location_for_distance(self) -> bool: """Checks if this unit type uses bottom-left location for distance calculations.""" pass def is_robot_type(self) -> bool: """Checks if this is a robot unit type.""" pass def is_throwable_type(self) -> bool: """Checks if this unit type is throwable.""" pass def is_throwing_type(self) -> bool: """Checks if this unit type is a throwing unit.""" pass def is_baby_rat_type(self) -> bool: """Checks if this is a Baby Rat unit type.""" pass def is_rat_king_type(self) -> bool: """Checks if this is a Rat King unit type.""" pass def is_cat_type(self) -> bool: """Checks if this is a Cat unit type.""" pass def ordinal(self) -> int: """Converts UnitTypes into unique ints for use in the shared array and squeaks.""" pass ``` -------------------------------- ### Game State Information Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions to retrieve global game state information, such as cheese amounts, rat trap counts, and team details. ```python def get_current_rat_cost() -> int: pass def get_global_cheese() -> int: pass def get_number_rat_traps() -> int: pass def get_number_cat_traps() -> int: pass def get_raw_cheese() -> int: pass ``` -------------------------------- ### squeak Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Sends a numerical message (squeak) to other robots. ```APIDOC ## squeak ### Description Sends a numerical message (squeak) to other robots. ### Method N/A (Function Call) ### Parameters - **squeak** (int) - The numerical message to send. ``` -------------------------------- ### Map Sensing: Robot-based Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions to sense information about robots. `sense_robot` uses an ID, `sense_robot_at_location` uses a map location, and `sense_nearby_robots` senses robots within a radius, optionally filtering by team. ```python def sense_robot(id: int) -> RobotInfo: pass def sense_robot_at_location(loc: MapLocation) -> RobotInfo: pass def sense_nearby_robots(center: MapLocation = ..., radius_squared: int = ..., team: Team = ...) -> list[RobotInfo]: """ Possible parameter combinations: - sense_nearby_robots() - sense_nearby_robots(radius_squared=[value]) - sense_nearby_robots(radius_squared=[value], team=[value]) - sense_nearby_robots(center=[value], radius_squared=[value], team=[value]) """ pass ``` -------------------------------- ### Message Class Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Represents a message sent between robots. ```APIDOC class Message: """ Fields: - bytes: int - sender_id: int - round: int - source_loc: MapLocation """ pass ``` -------------------------------- ### place_cat_trap Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Places a cat trap at the specified location. ```APIDOC ## place_cat_trap ### Description Places a cat trap at the specified location. ### Method N/A (Function Call) ### Parameters - **loc** (MapLocation) - The location to place the cat trap. ``` -------------------------------- ### Robot Actions: Communication Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Functions for robot communication using squeaks and shared arrays. `squeak` sends a message, while `read_shared_array` and `write_shared_array` allow for persistent data storage. ```python def read_shared_array(index: int) -> int: pass def read_squeaks(roundNum: int) -> list[Message]: pass def squeak(squeak: int) -> None: pass def write_shared_array(index: int, value: int) -> None: pass ``` -------------------------------- ### Manual Java Code Modification: Object Array Fields Source: https://github.com/battlecode/battlecode26/blob/master/schema/README.md Manual changes for generated Java files to replace `__assign` with `__init` when accessing object array fields, ensuring correct initialization. ```java public BodyTypeMetadata bodyTypeMetadata(int j) { return bodyTypeMetadata(new BodyTypeMetadata(), j); } public BodyTypeMetadata bodyTypeMetadata(BodyTypeMetadata obj, int j) { int o = __offset(8); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; } ``` -------------------------------- ### is_being_thrown Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Checks if the robot is currently being thrown by another robot. ```APIDOC ## is_being_thrown ### Description Checks if the robot is currently being thrown by another robot. ### Method N/A (Function Call) ### Returns - bool - True if the robot is being thrown, False otherwise. ``` -------------------------------- ### Team Class and Methods Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md The `Team` enum represents game teams. The `opponent` method returns the opposing team, and `ordinal` provides a unique integer representation. ```python class Team(Enum): A = 0 B = 1 NEUTRAL = 2 # for cats def opponent(self) -> Team: pass def ordinal(self) -> int: """ Converts Teams into unique ints for use in the shared array and squeaks. """ pass ``` -------------------------------- ### get_backstabbing_team Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Returns the opposing team. ```APIDOC ## get_backstabbing_team ### Description Returns the opposing team. ### Method N/A (Function Call) ### Returns - Team - The opposing team. ``` -------------------------------- ### is_cooperation Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Checks if the game is in cooperation mode. ```APIDOC ## is_cooperation ### Description Checks if the game is in cooperation mode. ### Method N/A (Function Call) ### Returns - bool - True if cooperation mode is active, False otherwise. ``` -------------------------------- ### turn Source: https://github.com/battlecode/battlecode26/blob/master/engine/src/crossplay_python/python_docs.md Turns the robot in a specified direction. ```APIDOC ## turn ### Description Turns the robot in a specified direction. ### Method N/A (Function Call) ### Parameters - **dir** (Direction) - The direction to turn. ``` -------------------------------- ### Manual Java Code Modification: getRootAsTeamData Source: https://github.com/battlecode/battlecode26/blob/master/schema/README.md Manual changes required for generated Java files to adapt to FlatBuffers version upgrades. This specific change modifies the `getRootAsTeamData` method. ```java public static TeamData getRootAsTeamData(ByteBuffer _bb) { return getRootAsTeamData(_bb, new TeamData()); } public static TeamData getRootAsTeamData(ByteBuffer _bb, TeamData obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } public TeamData __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } ```