├── README.md ├── LICENSE ├── .gitignore └── MyBot.py /README.md: -------------------------------------------------------------------------------- 1 | # Halite-ll-Challenge 2 | This is my repo of Season 2 of @twosigma's artificial intelligence programming challenge https://halite.io 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /MyBot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Welcome to your first Halite-II bot! 3 | 4 | This bot's name is Settler. It's purpose is simple (don't expect it to win complex games :) ): 5 | 1. Initialize game 6 | 2. If a ship is not docked and there are unowned planets 7 | 2.a. Try to Dock in the planet if close enough 8 | 2.b If not, go towards the planet 9 | 10 | Note: Please do not place print statements here as they are used to communicate with the Halite engine. If you need 11 | to log anything use the logging module. 12 | """ 13 | # Let's start by importing the Halite Starter Kit so we can interface with the Halite engine 14 | import hlt 15 | # Then let's import the logging module so we can print out information 16 | import logging 17 | 18 | # GAME START 19 | # Here we define the bot's name as Settler and initialize the game, including communication with the Halite engine. 20 | game = hlt.Game("Settler") 21 | # Then we print our start message to the logs 22 | logging.info("Starting my Settler bot!") 23 | 24 | while True: 25 | # TURN START 26 | # Update the map for the new turn and get the latest version 27 | game_map = game.update_map() 28 | 29 | # Here we define the set of commands to be sent to the Halite engine at the end of the turn 30 | command_queue = [] 31 | # For every ship that I control 32 | for ship in game_map.get_me().all_ships(): 33 | # If the ship is docked 34 | if ship.docking_status != ship.DockingStatus.UNDOCKED: 35 | # Skip this ship 36 | continue 37 | 38 | # For each planet in the game (only non-destroyed planets are included) 39 | for planet in game_map.all_planets(): 40 | # If the planet is owned 41 | if planet.is_owned(): 42 | # Skip this planet 43 | continue 44 | 45 | # If we can dock, let's (try to) dock. If two ships try to dock at once, neither will be able to. 46 | if ship.can_dock(planet): 47 | # We add the command by appending it to the command_queue 48 | command_queue.append(ship.dock(planet)) 49 | else: 50 | # If we can't dock, we move towards the closest empty point near this planet (by using closest_point_to) 51 | # with constant speed. Don't worry about pathfinding for now, as the command will do it for you. 52 | # We run this navigate command each turn until we arrive to get the latest move. 53 | # Here we move at half our maximum speed to better control the ships 54 | # In order to execute faster we also choose to ignore ship collision calculations during navigation. 55 | # This will mean that you have a higher probability of crashing into ships, but it also means you will 56 | # make move decisions much quicker. As your skill progresses and your moves turn more optimal you may 57 | # wish to turn that option off. 58 | navigate_command = ship.navigate( 59 | ship.closest_point_to(planet), 60 | game_map, 61 | speed=int(hlt.constants.MAX_SPEED/2), 62 | ignore_ships=True) 63 | # If the move is possible, add it to the command_queue (if there are too many obstacles on the way 64 | # or we are trapped (or we reached our destination!), navigate_command will return null; 65 | # don't fret though, we can run the command again the next turn) 66 | if navigate_command: 67 | command_queue.append(navigate_command) 68 | break 69 | 70 | # Send our set of commands to the Halite engine for this turn 71 | game.send_command_queue(command_queue) 72 | # TURN END 73 | # GAME END 74 | --------------------------------------------------------------------------------