From e68e8cb6450fc5be7b62eda65afa13e996af9abc Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 29 Oct 2017 10:48:19 -0700 Subject: [PATCH 001/117] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7c92ee1dc..20f3137c6 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ You can also view liveserver logs with the heroku logs command: heroku logs --tail ``` + ### Questions? [Email](mailto:battlesnake@sendwithus.com), [Twitter](http://twitter.com/send_with_us) From d1f748005f1153a9d76cef512a1c16cb1fac6bb5 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 12 Nov 2017 00:05:53 -0800 Subject: [PATCH 002/117] test hooks From 887a2d8c65cc5fa892c08796d4ecfc7715e94054 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 12 Nov 2017 00:06:37 -0800 Subject: [PATCH 003/117] test hooks From 6b5bb6f3b54e8e092ecb9fb785db22e19629b108 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 12 Nov 2017 00:20:37 -0800 Subject: [PATCH 004/117] test hooks From bed119908753aa1959873ef4481eee774bcc33c9 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 12 Nov 2017 00:21:05 -0800 Subject: [PATCH 005/117] test hooks 2 From a9e22bfc6711fefe9413c793902389cb5e74d7f6 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 28 Jan 2018 18:03:42 -0800 Subject: [PATCH 006/117] tested with 2018 server --- .gitignore | 3 +++ app/main.py | 10 +++++++--- requirements.txt | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index dbfb78d4e..0a2dcab92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.log *.pyc + +# editors +.idea* \ No newline at end of file diff --git a/app/main.py b/app/main.py index a7ff4b786..8c124f69a 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,4 @@ +import pprint import bottle import json @@ -14,6 +15,7 @@ def index(): @bottle.post('/start') def start(): data = bottle.request.json + pprint.pprint(data) return json.dumps({ 'name': 'battlesnake-python', @@ -26,19 +28,21 @@ def start(): @bottle.post('/move') def move(): data = bottle.request.json - + pprint.pprint(data) return json.dumps({ 'move': 'left', - 'taunt': 'battlesnake-python!' }) @bottle.post('/end') def end(): data = bottle.request.json - + pprint.pprint(data) return json.dumps({}) # Expose WSGI app application = bottle.default_app() + +if __name__ == "__main__": + bottle.run(host='0.0.0.0', port=8080, debug=True) diff --git a/requirements.txt b/requirements.txt index e35a59355..3674c159c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ bottle==0.12.8 gevent==1.0.1 greenlet==0.4.5 gunicorn==19.2.1 +pprint \ No newline at end of file From 0a0b2a272e6c04ccde628b8a4f57aefa18970b7a Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 28 Jan 2018 20:38:59 -0800 Subject: [PATCH 007/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92b3c4922..3b905c8b7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,6 @@ or visit [http://APP_NAME.herokuapp.com](http://APP_NAME.herokuapp.com). heroku logs --tail ``` -### Questions? +## Questions? Email [battlesnake@sendwithus.com](mailto:battlesnake@sendwithus.com), or tweet [@send_with_us](http://twitter.com/send_with_us). From b9c36428ab5d1de59796c19bb2b7f7ff8bfd50e9 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 28 Jan 2018 20:39:19 -0800 Subject: [PATCH 008/117] Update main.py --- app/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/main.py b/app/main.py index 37842f7d9..f2ef98bda 100755 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,3 @@ -import pprint import bottle import os import random From b08e192e787fe06655d4e256f9074634d2dc9a94 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 28 Jan 2018 20:39:43 -0800 Subject: [PATCH 009/117] Update .gitignore --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2a299d49d..89ba3a277 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ *.DS_Store *.pyc battlesnake - -# editors -.idea* +.idea From 9c55e1ce018bf936969271d7f3b6ee543c1fc396 Mon Sep 17 00:00:00 2001 From: John Oram Date: Sun, 28 Jan 2018 20:39:59 -0800 Subject: [PATCH 010/117] Update .gitignore From ef2541780f58f0c0f757d18786255f5edb341b49 Mon Sep 17 00:00:00 2001 From: John Oram Date: Wed, 14 Feb 2018 13:10:53 -0800 Subject: [PATCH 011/117] testing --- app/main.py | 13 ++++++++++--- cloud9/run.sh | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) delete mode 100644 cloud9/run.sh diff --git a/app/main.py b/app/main.py index f2ef98bda..dd53e9d6a 100755 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,12 @@ import random + +@bottle.route('/') +def static(): + return "the server is running" + + @bottle.route('/static/') def static(path): return bottle.static_file(path, root='static/') @@ -11,9 +17,10 @@ def static(path): @bottle.post('/start') def start(): data = bottle.request.json - game_id = data['game_id'] - board_width = data['width'] - board_height = data['height'] + print data + game_id = data.get('game_id') + board_width = data.get('width') + board_height = data.get('height') head_url = '%s://%s/static/head.png' % ( bottle.request.urlparts.scheme, diff --git a/cloud9/run.sh b/cloud9/run.sh deleted file mode 100644 index 70f7cf78b..000000000 --- a/cloud9/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -cd .. -echo -e "\n===== https://$C9_HOSTNAME =====\n" -gunicorn app.main:application --access-logfile - --worker-class gevent --bind "$IP:$PORT" From 7c324624d2a476c1b0c9a8abd2553dd320498ba5 Mon Sep 17 00:00:00 2001 From: John Oram Date: Wed, 14 Feb 2018 13:12:56 -0800 Subject: [PATCH 012/117] testing --- app/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index dd53e9d6a..9fc11a18f 100755 --- a/app/main.py +++ b/app/main.py @@ -17,7 +17,6 @@ def static(path): @bottle.post('/start') def start(): data = bottle.request.json - print data game_id = data.get('game_id') board_width = data.get('width') board_height = data.get('height') @@ -42,10 +41,12 @@ def move(): data = bottle.request.json # TODO: Do things with data + directions = ['up', 'down', 'left', 'right'] - + direction = random.choice(directions) + print direction return { - 'move': random.choice(directions), + 'move': direction, 'taunt': 'battlesnake-python!' } From 0b03aafb80cfff9c77c4115e8087c1b9d4e95f18 Mon Sep 17 00:00:00 2001 From: John Oram <32964081+john-swu@users.noreply.github.com> Date: Thu, 22 Feb 2018 21:34:45 -0800 Subject: [PATCH 013/117] Update runtime.txt --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index fdf79660d..538568204 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-2.7.12 +python-2.7.14 From 5562aa29aef3f74af262a056feef38febc50115b Mon Sep 17 00:00:00 2001 From: John Oram <32964081+john-swu@users.noreply.github.com> Date: Mon, 26 Feb 2018 15:40:15 -0800 Subject: [PATCH 014/117] Update main.py --- app/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 9fc11a18f..2e68354cd 100755 --- a/app/main.py +++ b/app/main.py @@ -31,8 +31,7 @@ def start(): return { 'color': '#00FF00', 'taunt': '{} ({}x{})'.format(game_id, board_width, board_height), - 'head_url': head_url, - 'name': 'battlesnake-python' + 'head_url': head_url } From 517a454eaf157433617aef486021c1387de299d3 Mon Sep 17 00:00:00 2001 From: Charlie Friend Date: Fri, 13 Apr 2018 22:46:40 -0700 Subject: [PATCH 015/117] Implement models for 2019 API spec. --- app/api.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ app/main.py | 25 +++++++++-------- 2 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 app/api.py diff --git a/app/api.py b/app/api.py new file mode 100644 index 000000000..23dda5e0c --- /dev/null +++ b/app/api.py @@ -0,0 +1,79 @@ +import json +from bottle import HTTPResponse + + +class Coords: + def __init__(self, json): + self.x = json.get('x') + self.y = json.get('y') + + +class Snake: + def __init__(self, json): + self.id = json.get('id') + self.name = json.get('name') + self.health = json.get('health') + + if type(json.get('body')) == list: + self.body = [Coords(x) for x in json['body']] + + def head(self): + if getattr(self, 'body'): + return self.body[0] + + +class Board: + def __init__(self, json): + self.height = json.get('height') + self.width = json.get('width') + + if type(json.get('food')) == list: + self.food = [Coords(x) for x in json['food']] + + if type(json.get('snakes')) == list: + self.snakes = [Snake(x) for x in json['snakes']] + + +class Game: + def __init__(self, json): + self.id = json.get('id') + + +class SnakeRequest: + def __init__(self, json): + self.turn = json.get('turn') + + if type(json.get('game')) == dict: + self.game = Game(json['game']) + + if type(json.get('board')) == dict: + self.board = Board(json['board']) + + if type(json.get('you')) == dict: + self.you = Snake(json['you']) + + +class MoveResponse(HTTPResponse): + def __init__(self, move): + assert move in ['up', 'down', 'left', 'right'], \ + "Move must be one of [up, down, left, right]" + + self.move = move + + super(HTTPResponse, self).__init__( + status=200, + body=json.dumps({"move": self.move}), + headers={"Content-Type": "application/json"} + ) + + +class StartResponse(HTTPResponse): + def __init__(self, color): + assert type(color) is str, "Color value must be string" + self.color = color + + super(HTTPResponse, self).__init__( + status=200, + body=json.dumps({"color": self.color}), + headers={"Content-Type": "application/json"} + ) diff --git a/app/main.py b/app/main.py index 2e68354cd..375024b0d 100755 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ import os import random +from api import * @bottle.route('/') @@ -17,9 +18,7 @@ def static(path): @bottle.post('/start') def start(): data = bottle.request.json - game_id = data.get('game_id') - board_width = data.get('width') - board_height = data.get('height') + req = SnakeRequest(data) head_url = '%s://%s/static/head.png' % ( bottle.request.urlparts.scheme, @@ -28,26 +27,28 @@ def start(): # TODO: Do things with data - return { - 'color': '#00FF00', - 'taunt': '{} ({}x{})'.format(game_id, board_width, board_height), - 'head_url': head_url - } + return StartResponse("#00ff00") @bottle.post('/move') def move(): data = bottle.request.json + req = SnakeRequest(data) # TODO: Do things with data directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) print direction - return { - 'move': direction, - 'taunt': 'battlesnake-python!' - } + return MoveResponse(direction) + + +@bottle.post('/end') +def end(): + data = bottle.request.json + req = SnakeRequest(data) + + # TODO: Do things with data # Expose WSGI app (so gunicorn can find it) From e350ccc3b31961c15ac8d8780b3af452bf78a426 Mon Sep 17 00:00:00 2001 From: Charlie Friend Date: Fri, 13 Apr 2018 23:10:58 -0700 Subject: [PATCH 016/117] Add AGPL-3.0 license. --- LICENSE | 661 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 661 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..1ce875873 --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file From cabc9779c3b86e2c49a28d596bcef6c474f60b8f Mon Sep 17 00:00:00 2001 From: Charlie Friend Date: Fri, 20 Apr 2018 08:52:42 -0700 Subject: [PATCH 017/117] Update license to MIT. --- LICENSE | 682 ++------------------------------------------------------ 1 file changed, 21 insertions(+), 661 deletions(-) diff --git a/LICENSE b/LICENSE index 1ce875873..30b8f9259 100644 --- a/LICENSE +++ b/LICENSE @@ -1,661 +1,21 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. \ No newline at end of file +MIT License + +Copyright (c) 2018 Techdrop Labs Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 88a8d04f8b00c86f42f94c3e24624d36e835f4fd Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sat, 21 Apr 2018 15:42:50 -0700 Subject: [PATCH 018/117] battlesnake changes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b905c8b7..260ff0b42 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# battlesnake-python +# starter-snake-python -A simple [BattleSnake AI](http://battlesnake.io) written in Python. +A simple [Battlesnake AI](http://battlesnake.io) written in Python. -Visit [battlesnake.io/readme](http://battlesnake.io/readme) for API documentation and instructions for running your AI. +Visit [https://github.com/battlesnakeio/community/blob/master/starter-snakes.md](https://github.com/battlesnakeio/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/index.html) to serve requests and the [gunicorn web server](http://gunicorn.org/) for running bottle on Heroku. Dependencies are listed in [requirements.txt](requirements.txt). From 6b0922a60bab3de68f682767a5aafee5ac1290a5 Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sat, 12 May 2018 16:09:32 -0700 Subject: [PATCH 019/117] Create CONTRIBUTING.md --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..65a10515f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing + +Please see [community/CONTRIBUTING.md](https://github.com/battlesnakeio/community/blob/master/CONTRIBUTING.md) From 55dd198bd0af94a5b9ef39f4a8691e13589181df Mon Sep 17 00:00:00 2001 From: Charlie Friend Date: Mon, 14 May 2018 20:20:51 -0700 Subject: [PATCH 020/117] Remove request processing classes from api.py. --- app/api.py | 51 --------------------------------------------------- app/main.py | 11 ++++++----- 2 files changed, 6 insertions(+), 56 deletions(-) diff --git a/app/api.py b/app/api.py index 23dda5e0c..cea8f9165 100644 --- a/app/api.py +++ b/app/api.py @@ -2,57 +2,6 @@ from bottle import HTTPResponse -class Coords: - def __init__(self, json): - self.x = json.get('x') - self.y = json.get('y') - - -class Snake: - def __init__(self, json): - self.id = json.get('id') - self.name = json.get('name') - self.health = json.get('health') - - if type(json.get('body')) == list: - self.body = [Coords(x) for x in json['body']] - - def head(self): - if getattr(self, 'body'): - return self.body[0] - - -class Board: - def __init__(self, json): - self.height = json.get('height') - self.width = json.get('width') - - if type(json.get('food')) == list: - self.food = [Coords(x) for x in json['food']] - - if type(json.get('snakes')) == list: - self.snakes = [Snake(x) for x in json['snakes']] - - -class Game: - def __init__(self, json): - self.id = json.get('id') - - -class SnakeRequest: - def __init__(self, json): - self.turn = json.get('turn') - - if type(json.get('game')) == dict: - self.game = Game(json['game']) - - if type(json.get('board')) == dict: - self.board = Board(json['board']) - - if type(json.get('you')) == dict: - self.you = Snake(json['you']) - - class MoveResponse(HTTPResponse): def __init__(self, move): assert move in ['up', 'down', 'left', 'right'], \ diff --git a/app/main.py b/app/main.py index 375024b0d..69ac5ef28 100755 --- a/app/main.py +++ b/app/main.py @@ -18,7 +18,6 @@ def static(path): @bottle.post('/start') def start(): data = bottle.request.json - req = SnakeRequest(data) head_url = '%s://%s/static/head.png' % ( bottle.request.urlparts.scheme, @@ -27,29 +26,31 @@ def start(): # TODO: Do things with data + print "Starting game %s" % data["game"]["id"] return StartResponse("#00ff00") @bottle.post('/move') def move(): data = bottle.request.json - req = SnakeRequest(data) # TODO: Do things with data directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) - print direction + + print "Moving %s" % direction return MoveResponse(direction) @bottle.post('/end') def end(): data = bottle.request.json - req = SnakeRequest(data) # TODO: Do things with data + print "Game %s ended" % data["game"]["id"] + # Expose WSGI app (so gunicorn can find it) application = bottle.default_app() @@ -59,4 +60,4 @@ def end(): application, host=os.getenv('IP', '0.0.0.0'), port=os.getenv('PORT', '8080'), - debug = True) + debug=True) From d9bf57c7de5033b2868721477bea73da0c2d9053 Mon Sep 17 00:00:00 2001 From: Brandon Brown Date: Tue, 4 Sep 2018 13:47:48 -0700 Subject: [PATCH 021/117] Upgrade packages --- requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index e24b73d21..7e5840db6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -bottle==0.12.9 -gevent==1.0.2 -greenlet==0.4.9 -gunicorn==19.4.5 +bottle==0.12.13 +gevent==1.3.6 +greenlet==0.4.14 +gunicorn==19.9.0 From d0d2c7629f07d6292e6f473b9d106770ca26be0e Mon Sep 17 00:00:00 2001 From: Brandon Brown Date: Tue, 4 Sep 2018 13:28:56 -0700 Subject: [PATCH 022/117] Update the version of heroku to 2.7.15 --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 538568204..f27f1cc5c 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-2.7.14 +python-2.7.15 From f4c19ef1eda413d02af4cb57ede7c42141fec604 Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sat, 17 Nov 2018 10:01:26 -0800 Subject: [PATCH 023/117] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 30b8f9259..94ec72e7c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Techdrop Labs Inc. +Copyright (c) 2018 Battlesnake Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 716dc08e4923ac04f92ec6114d37494eb810b478 Mon Sep 17 00:00:00 2001 From: Will Warren Date: Sat, 17 Nov 2018 17:05:42 -0800 Subject: [PATCH 024/117] added ping. removed code that caused stack traces on start --- .gitignore | 1 + README.md | 9 ++++++--- app/main.py | 15 ++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 89ba3a277..58b6a3960 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pyc battlesnake .idea +.vscode diff --git a/README.md b/README.md index 260ff0b42..6ecc40054 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/inde ## Running the Snake Locally -1) [Fork this repo](https://github.com/sendwithus/battlesnake-python/fork). +1) [Fork this repo](https://github.com/battlesnakeio/starter-snake-python/fork). 2) Clone repo to your development environment: ``` -git clone git@github.com:username/battlesnake-python.git +git clone git@github.com:/starter-snake-python.git ``` 3) Install dependencies using [pip](https://pip.pypa.io/en/latest/installing.html): @@ -33,7 +33,10 @@ pip install -r requirements.txt python app/main.py ``` -5) Test client in your browser: [http://localhost:8080](http://localhost:8080). +5) Test your snake by sending a curl to the running snake +``` +curl -XPOST -H 'Content-Type: application/json' -d '{ "hello": "world"}' http://localhost:8080/start +``` ## Deploying to Heroku diff --git a/app/main.py b/app/main.py index 69ac5ef28..f630cc405 100755 --- a/app/main.py +++ b/app/main.py @@ -19,14 +19,9 @@ def static(path): def start(): data = bottle.request.json - head_url = '%s://%s/static/head.png' % ( - bottle.request.urlparts.scheme, - bottle.request.urlparts.netloc - ) - # TODO: Do things with data + print json.dumps(data) - print "Starting game %s" % data["game"]["id"] return StartResponse("#00ff00") @@ -35,6 +30,7 @@ def move(): data = bottle.request.json # TODO: Do things with data + print json.dumps(data) directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) @@ -48,8 +44,13 @@ def end(): data = bottle.request.json # TODO: Do things with data + print json.dumps(data) + + print "Game ended" - print "Game %s ended" % data["game"]["id"] +@bottle.post('/ping') +def ping(): + return "Alive" # Expose WSGI app (so gunicorn can find it) From 116db0c1e8771b36197cdd421a1bfcbe4c1d2160 Mon Sep 17 00:00:00 2001 From: Will Warren Date: Sat, 17 Nov 2018 17:08:15 -0800 Subject: [PATCH 025/117] changed comments --- app/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index f630cc405..c54c32fb2 100755 --- a/app/main.py +++ b/app/main.py @@ -35,7 +35,6 @@ def move(): directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) - print "Moving %s" % direction return MoveResponse(direction) @@ -43,10 +42,9 @@ def move(): def end(): data = bottle.request.json - # TODO: Do things with data + # TODO: Any cleanup that needs to be done. print json.dumps(data) - print "Game ended" @bottle.post('/ping') def ping(): From 934150dd5e0abbf4da01094c8050e8406f419c98 Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sun, 18 Nov 2018 14:41:20 -0800 Subject: [PATCH 026/117] Update app/main.py --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index c54c32fb2..0a6d1f362 100755 --- a/app/main.py +++ b/app/main.py @@ -30,7 +30,7 @@ def move(): data = bottle.request.json # TODO: Do things with data - print json.dumps(data) + print(json.dumps(data)) directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) From eb3e4b682fd656aef09f87fdc075c63616b2304e Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sun, 18 Nov 2018 14:42:10 -0800 Subject: [PATCH 027/117] Update app/main.py --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 0a6d1f362..0669e4a9a 100755 --- a/app/main.py +++ b/app/main.py @@ -20,7 +20,7 @@ def start(): data = bottle.request.json # TODO: Do things with data - print json.dumps(data) + print(json.dumps(data)) return StartResponse("#00ff00") From ee1e27dce830d7829fe3e0794efe7a688a7b58dd Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Sun, 18 Nov 2018 14:44:49 -0800 Subject: [PATCH 028/117] Update app/main.py --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 0669e4a9a..b9bfb99df 100755 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,7 @@ def move(): def end(): data = bottle.request.json - # TODO: Any cleanup that needs to be done. + # TODO: Any cleanup that needs to be done for this game based on the data print json.dumps(data) From eb2fb31396fea0b6dff3de37e3377f0161c50a6a Mon Sep 17 00:00:00 2001 From: SynthesizedSoul Date: Sun, 16 Dec 2018 18:08:21 -0800 Subject: [PATCH 029/117] Update documentation to routes, move all route HTTPResponses to API file. The motivation for this commit is to address some potential confusion to newcomers on how this Python application behaves. I've moved and updated the HTTPResponse code for the /ping, /start, /move, and /end endpoints to the API file. Additionally, I've added documentation to the routing to make it easier to jump in and understand each endpoints purpose. --- app/api.py | 52 ++++++++++++++++++++++++++++------------------ app/main.py | 59 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 69 insertions(+), 42 deletions(-) diff --git a/app/api.py b/app/api.py index cea8f9165..538c06039 100644 --- a/app/api.py +++ b/app/api.py @@ -1,28 +1,40 @@ import json from bottle import HTTPResponse +def ping_response(): + return HTTPResponse( + status=200 + ) -class MoveResponse(HTTPResponse): - def __init__(self, move): - assert move in ['up', 'down', 'left', 'right'], \ - "Move must be one of [up, down, left, right]" +def start_response(color): + assert type(color) is str, \ + "Color value must be string" - self.move = move + return HTTPResponse( + status=200, + headers={ + "Content-Type": "application/json" + }, + body=json.dumps({ + "color": color + }) + ) - super(HTTPResponse, self).__init__( - status=200, - body=json.dumps({"move": self.move}), - headers={"Content-Type": "application/json"} - ) +def move_response(move): + assert move in ['up', 'down', 'left', 'right'], \ + "Move must be one of [up, down, left, right]" + return HTTPResponse( + status=200, + headers={ + "Content-Type": "application/json" + }, + body=json.dumps({ + "move": move + }) + ) -class StartResponse(HTTPResponse): - def __init__(self, color): - assert type(color) is str, "Color value must be string" - self.color = color - - super(HTTPResponse, self).__init__( - status=200, - body=json.dumps({"color": self.color}), - headers={"Content-Type": "application/json"} - ) +def end_response(): + return HTTPResponse( + status=200 + ) diff --git a/app/main.py b/app/main.py index b9bfb99df..9edfe1269 100755 --- a/app/main.py +++ b/app/main.py @@ -1,55 +1,69 @@ -import bottle +import json import os import random +import bottle -from api import * - - -@bottle.route('/') -def static(): - return "the server is running" - +from api import ping_response, start_response, move_response, end_response @bottle.route('/static/') def static(path): + """ + Given a path, return the static file located relative + to the static folder. + + This can be used to return the snake head URL in an API response. + """ return bottle.static_file(path, root='static/') +@bottle.post('/ping') +def ping(): + """ + A keep-alive endpoint used to prevent cloud application platforms, + such as Heroku, from sleeping the application instance. + """ + return ping_response() @bottle.post('/start') def start(): data = bottle.request.json - # TODO: Do things with data + """ + TODO: If you intend to have a stateful snake AI, + initialize your snake state here using the + requests data if necessary. + """ print(json.dumps(data)) - return StartResponse("#00ff00") + color = "#00FF00" + + return start_response(color) @bottle.post('/move') def move(): data = bottle.request.json - # TODO: Do things with data + """ + TODO: Using the data from the endpoint request object, your + snake AI must choose a direction to move in. + """ print(json.dumps(data)) - + directions = ['up', 'down', 'left', 'right'] direction = random.choice(directions) - return MoveResponse(direction) + return move_response(direction) @bottle.post('/end') def end(): - data = bottle.request.json - - # TODO: Any cleanup that needs to be done for this game based on the data - print json.dumps(data) + """ + TODO: If your snake AI was stateful, + clean up any stateful objects here. + """ -@bottle.post('/ping') -def ping(): - return "Alive" - + return end_response() # Expose WSGI app (so gunicorn can find it) application = bottle.default_app() @@ -59,4 +73,5 @@ def ping(): application, host=os.getenv('IP', '0.0.0.0'), port=os.getenv('PORT', '8080'), - debug=True) + debug=os.getenv('DEBUG', True) + ) From cd67ea75dd559d176036929197cb21fac33a4c3c Mon Sep 17 00:00:00 2001 From: SynthesizedSoul Date: Sun, 16 Dec 2018 21:14:44 -0800 Subject: [PATCH 030/117] Add back data variable to /end endpoint. --- app/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 9edfe1269..e6e0caace 100755 --- a/app/main.py +++ b/app/main.py @@ -30,7 +30,7 @@ def start(): """ TODO: If you intend to have a stateful snake AI, initialize your snake state here using the - requests data if necessary. + request's data if necessary. """ print(json.dumps(data)) @@ -57,11 +57,13 @@ def move(): @bottle.post('/end') def end(): + data = bottle.request.json """ TODO: If your snake AI was stateful, clean up any stateful objects here. """ + print(json.dumps(data)) return end_response() From 1fd8456ea0277e5d90081fcfa10020c39a49c470 Mon Sep 17 00:00:00 2001 From: SynthesizedSoul Date: Mon, 17 Dec 2018 01:58:47 -0800 Subject: [PATCH 031/117] Reintroduce the '/' route, using a SimpleEngine template to render a better landing page. --- app/main.py | 5 +++++ app/views/index.tpl | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 app/views/index.tpl diff --git a/app/main.py b/app/main.py index e6e0caace..b6e7210c6 100755 --- a/app/main.py +++ b/app/main.py @@ -3,8 +3,13 @@ import random import bottle +from bottle import template from api import ping_response, start_response, move_response, end_response +@bottle.route('/') +def index(): + return template('index') + @bottle.route('/static/') def static(path): """ diff --git a/app/views/index.tpl b/app/views/index.tpl new file mode 100644 index 000000000..dc75882dd --- /dev/null +++ b/app/views/index.tpl @@ -0,0 +1,14 @@ + + + Battlesnake: Starter Snake Python + + +

Starter Snake Python

+
+

Your snake is online!

+

+ Battlesnake documentation can be found at https://github.com/battlesnakeio/docs. +

+
+ + From d14beabd5cb9ce97fe3838c132de9204359ef053 Mon Sep 17 00:00:00 2001 From: SynthesizedSoul Date: Mon, 17 Dec 2018 10:35:09 -0800 Subject: [PATCH 032/117] Remove unecessary bloating from adding templates directory. Instead return HTML string directly. --- app/main.py | 12 ++++++++++-- app/views/index.tpl | 14 -------------- 2 files changed, 10 insertions(+), 16 deletions(-) delete mode 100644 app/views/index.tpl diff --git a/app/main.py b/app/main.py index b6e7210c6..9a957a5ce 100755 --- a/app/main.py +++ b/app/main.py @@ -3,12 +3,20 @@ import random import bottle -from bottle import template from api import ping_response, start_response, move_response, end_response @bottle.route('/') def index(): - return template('index') + return """ +

Starter Snake Python

+
+

Your snake is online!

+

+ Battlesnake documentation can be found at + https://github.com/battlesnakeio/docs. +

+
+ """ @bottle.route('/static/') def static(path): diff --git a/app/views/index.tpl b/app/views/index.tpl deleted file mode 100644 index dc75882dd..000000000 --- a/app/views/index.tpl +++ /dev/null @@ -1,14 +0,0 @@ - - - Battlesnake: Starter Snake Python - - -

Starter Snake Python

-
-

Your snake is online!

-

- Battlesnake documentation can be found at https://github.com/battlesnakeio/docs. -

-
- - From d192a5ab54c2d99ae6612fd626ba6e263a88e162 Mon Sep 17 00:00:00 2001 From: Brandon Brown Date: Tue, 18 Dec 2018 18:21:42 -0800 Subject: [PATCH 033/117] As per https://github.com/battlesnakeio/roadmap/issues/186 --- app/main.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index 9a957a5ce..9c638e69d 100755 --- a/app/main.py +++ b/app/main.py @@ -7,16 +7,10 @@ @bottle.route('/') def index(): - return """ -

Starter Snake Python

-
-

Your snake is online!

-

- Battlesnake documentation can be found at - https://github.com/battlesnakeio/docs. -

-
- """ + return ''' + Battlesnake documentation can be found at + https://battlesnake.io/docs. + ''' @bottle.route('/static/') def static(path): From 7628c3a95a1f06684d06b87881e86293d00d2043 Mon Sep 17 00:00:00 2001 From: Will <1261268+codeallthethingz@users.noreply.github.com> Date: Fri, 21 Dec 2018 08:56:53 -0800 Subject: [PATCH 034/117] Update app/main.py Co-Authored-By: brandonb927 --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 9c638e69d..e711297f8 100755 --- a/app/main.py +++ b/app/main.py @@ -9,7 +9,7 @@ def index(): return ''' Battlesnake documentation can be found at - https://battlesnake.io/docs. + https://docs.battlesnake.io. ''' @bottle.route('/static/') From 3f03095e4d6030ba74df2b394ad1fe178ce7ec16 Mon Sep 17 00:00:00 2001 From: John Oram Date: Thu, 19 Dec 2019 19:59:53 -0800 Subject: [PATCH 035/117] update docs link. cleaned up whitespace (#63) --- app/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index e711297f8..f828220de 100755 --- a/app/main.py +++ b/app/main.py @@ -5,13 +5,15 @@ from api import ping_response, start_response, move_response, end_response + @bottle.route('/') def index(): return ''' Battlesnake documentation can be found at - https://docs.battlesnake.io. + https://docs.battlesnake.com. ''' + @bottle.route('/static/') def static(path): """ @@ -22,6 +24,7 @@ def static(path): """ return bottle.static_file(path, root='static/') + @bottle.post('/ping') def ping(): """ @@ -30,6 +33,7 @@ def ping(): """ return ping_response() + @bottle.post('/start') def start(): data = bottle.request.json @@ -74,6 +78,7 @@ def end(): return end_response() + # Expose WSGI app (so gunicorn can find it) application = bottle.default_app() From 598c18d4ec85ac16565a595b1431beb88337f71d Mon Sep 17 00:00:00 2001 From: Chris Hoefgen <53871533+chris-bsnake@users.noreply.github.com> Date: Wed, 8 Jan 2020 14:05:46 -0800 Subject: [PATCH 036/117] Updating contact info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ecc40054..6d878afee 100644 --- a/README.md +++ b/README.md @@ -63,4 +63,4 @@ heroku logs --tail ## Questions? -Email [battlesnake@sendwithus.com](mailto:battlesnake@sendwithus.com), or tweet [@send_with_us](http://twitter.com/send_with_us). +Email [hello@battlesnake.com](mailto:hello@battlesnake.com), or tweet [@battlesnakeio](http://twitter.com/battlesnakeio). From 728a7c4928ed68e6274fdfc1374b514110e6d3e9 Mon Sep 17 00:00:00 2001 From: Brandon Brown Date: Tue, 18 Feb 2020 22:55:59 -0800 Subject: [PATCH 037/117] Documentation updates (#6) * Docs updates * Revert some changes made inadvertently * Update to HTTPS --- CONTRIBUTING.md | 2 +- README.md | 87 +++++++++++++++++++++++++++---------------------- app.json | 6 ++-- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65a10515f..5a5d7073d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,3 @@ # Contributing -Please see [community/CONTRIBUTING.md](https://github.com/battlesnakeio/community/blob/master/CONTRIBUTING.md) +Please see [community/CONTRIBUTING.md](https://github.com/BattlesnakeOfficial/community/blob/master/CONTRIBUTING.md) diff --git a/README.md b/README.md index 6d878afee..98152edd6 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,74 @@ # starter-snake-python -A simple [Battlesnake AI](http://battlesnake.io) written in Python. +A simple [Battlesnake AI](http://play.battlesnake.com) written in Python. -Visit [https://github.com/battlesnakeio/community/blob/master/starter-snakes.md](https://github.com/battlesnakeio/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. +Visit [https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md](https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/index.html) to serve requests and the [gunicorn web server](http://gunicorn.org/) for running bottle on Heroku. Dependencies are listed in [requirements.txt](requirements.txt). [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) -#### You will need... +## Prerequisites -* a working Python 2.7 development environment ([getting started guide](http://hackercodex.com/guide/python-development-environment-on-mac-osx/)) -* experience [deploying Python apps to Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) -* [pip](https://pip.pypa.io/en/latest/installing.html) to install Python dependencies +- a working Python 2.7 development environment ([getting started guide](http://hackercodex.com/guide/python-development-environment-on-mac-osx/)) +- [pip](https://pip.pypa.io/en/latest/installing.html) to install Python dependencies +- experience [deploying Python apps to Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) ## Running the Snake Locally -1) [Fork this repo](https://github.com/battlesnakeio/starter-snake-python/fork). +1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork). -2) Clone repo to your development environment: -``` -git clone git@github.com:/starter-snake-python.git -``` +2. Clone repo to your development environment: -3) Install dependencies using [pip](https://pip.pypa.io/en/latest/installing.html): -``` -pip install -r requirements.txt -``` + ```shell + git clone git@github.com:/starter-snake-python.git + ``` -4) Run local server: -``` -python app/main.py -``` +3. Install dependencies using [pip](https://pip.pypa.io/en/latest/installing.html): -5) Test your snake by sending a curl to the running snake -``` -curl -XPOST -H 'Content-Type: application/json' -d '{ "hello": "world"}' http://localhost:8080/start -``` + ```shell + pip install -r requirements.txt + ``` + +4. Run local server: + + ```shell + python app/main.py + ``` + +5. Test your snake by sending a curl to the running snake + + ```shell + curl -XPOST -H 'Content-Type: application/json' -d '{ "hello": "world"}' http://localhost:8080/start + ``` ## Deploying to Heroku -1) Create a new Heroku app: -``` -heroku create [APP_NAME] -``` +1. Create a new Heroku app: + + ```shell + heroku create [APP_NAME] + ``` -2) Deploy code to Heroku servers: -``` -git push heroku master -``` +2. Deploy code to Heroku servers: + + ```shell + git push heroku master + ``` + +3. Open Heroku app in browser: + + ```shell + heroku open + ``` -3) Open Heroku app in browser: -``` -heroku open -``` or visit [http://APP_NAME.herokuapp.com](http://APP_NAME.herokuapp.com). -4) View server logs with the `heroku logs` command: -``` -heroku logs --tail -``` +4. View server logs with the `heroku logs` command: + + ```shell + heroku logs --tail + ``` ## Questions? diff --git a/app.json b/app.json index e5bd04c36..1acf875b6 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "name": "BattleSnake Python", "description": "A simple BattleSnake AI written in Python.", - "repository": "https://github.com/sendwithus/battlesnake-python", - "website": "http://battlesnake.io", - "keywords": ["battlesnake","sendwithus"] + "repository": "https://github.com/BattlesnakeOfficial/starter-snake-python", + "website": "https://play.battlesnake.com", + "keywords": ["battlesnake"] } From 5a9a53ad3f6eff0d7551542b7e0923071ef9be24 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 21 Feb 2020 16:50:38 -0800 Subject: [PATCH 038/117] Create ci.yml --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..e54d08bc6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Run a one-line script + run: echo Hello, world! + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. From 9c6ce1062401e53b824d038edab2c03d48b38b7a Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 21 Feb 2020 16:56:58 -0800 Subject: [PATCH 039/117] Update ci.yml --- .github/workflows/ci.yml | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e54d08bc6..2397f56d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,15 +3,33 @@ name: CI on: [push] jobs: - build: + format: + name: Format (Black) runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@master + with: + python-version: 3.7.6 + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install black + - name: Run Black + run: black app/ --check + lint: + name: Lint (Flake8) + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run a one-line script - run: echo Hello, world! - - name: Run a multi-line script + - uses: actions/checkout@master + - uses: actions/setup-python@master + with: + python-version: 3.7.6 + - name: Install Dependencies run: | - echo Add other actions to build, - echo test, and deploy your project. + pip install --upgrade pip + pip install flake8 + - name: Run Flake8 + run: flake8 app/ From fb8a68e4144570cf454b5e00e18fa3db2a883dc5 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 21 Feb 2020 19:41:01 -0800 Subject: [PATCH 040/117] Update for Python 3.7.6 (among other things). * Remove static. Apply black and flake8. Update to Python 3.7.6 * Update naming to match latest documentation. * Update docs, runtime, procfile. --- .github/ci.yml | 35 ++++++++++++++++++ .gitignore | 2 +- Procfile | 2 +- README.md | 14 ++++---- app.json | 6 ++-- app/api.py | 40 --------------------- app/main.py | 91 ----------------------------------------------- app/server.py | 88 +++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 8 ++--- runtime.txt | 2 +- static/head.png | Bin 15842 -> 0 bytes 11 files changed, 142 insertions(+), 146 deletions(-) create mode 100644 .github/ci.yml delete mode 100644 app/api.py delete mode 100755 app/main.py create mode 100755 app/server.py delete mode 100644 static/head.png diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 000000000..2397f56d4 --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: [push] + +jobs: + + format: + name: Format (Black) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@master + with: + python-version: 3.7.6 + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install black + - name: Run Black + run: black app/ --check + + lint: + name: Lint (Flake8) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@master + with: + python-version: 3.7.6 + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install flake8 + - name: Run Flake8 + run: flake8 app/ diff --git a/.gitignore b/.gitignore index 58b6a3960..9bd6368cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.DS_Store *.pyc -battlesnake +.cmd .idea .vscode diff --git a/Procfile b/Procfile index b671479df..cfeefd8e0 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn app.main:application --worker-class gevent +web: gunicorn app.server --worker-class gevent diff --git a/README.md b/README.md index 98152edd6..32c947e8e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # starter-snake-python -A simple [Battlesnake AI](http://play.battlesnake.com) written in Python. +A simple [Battlesnake](http://play.battlesnake.com) written in Python. Visit [https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md](https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. @@ -10,9 +10,11 @@ This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/inde ## Prerequisites -- a working Python 2.7 development environment ([getting started guide](http://hackercodex.com/guide/python-development-environment-on-mac-osx/)) +- A working [Python 3.7](https://www.python.org/downloads/) development environment + - [MacOS](http://hackercodex.com/guide/python-development-environment-on-mac-osx/) + - [Windows](https://docs.battlesnake.com/tutorials/python) - [pip](https://pip.pypa.io/en/latest/installing.html) to install Python dependencies -- experience [deploying Python apps to Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) +- Experience [deploying Python apps to Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) ## Running the Snake Locally @@ -33,13 +35,13 @@ This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/inde 4. Run local server: ```shell - python app/main.py + python app/server.py ``` -5. Test your snake by sending a curl to the running snake +5. Test your snake by opening your snake server in your browser ```shell - curl -XPOST -H 'Content-Type: application/json' -d '{ "hello": "world"}' http://localhost:8080/start + open http://127.0.0.1:8080/ ``` ## Deploying to Heroku diff --git a/app.json b/app.json index 1acf875b6..1178cc6b2 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,9 @@ { "name": "BattleSnake Python", - "description": "A simple BattleSnake AI written in Python.", + "description": "A simple BattleSnake written in Python.", "repository": "https://github.com/BattlesnakeOfficial/starter-snake-python", "website": "https://play.battlesnake.com", - "keywords": ["battlesnake"] + "keywords": [ + "battlesnake" + ] } diff --git a/app/api.py b/app/api.py deleted file mode 100644 index 538c06039..000000000 --- a/app/api.py +++ /dev/null @@ -1,40 +0,0 @@ -import json -from bottle import HTTPResponse - -def ping_response(): - return HTTPResponse( - status=200 - ) - -def start_response(color): - assert type(color) is str, \ - "Color value must be string" - - return HTTPResponse( - status=200, - headers={ - "Content-Type": "application/json" - }, - body=json.dumps({ - "color": color - }) - ) - -def move_response(move): - assert move in ['up', 'down', 'left', 'right'], \ - "Move must be one of [up, down, left, right]" - - return HTTPResponse( - status=200, - headers={ - "Content-Type": "application/json" - }, - body=json.dumps({ - "move": move - }) - ) - -def end_response(): - return HTTPResponse( - status=200 - ) diff --git a/app/main.py b/app/main.py deleted file mode 100755 index f828220de..000000000 --- a/app/main.py +++ /dev/null @@ -1,91 +0,0 @@ -import json -import os -import random -import bottle - -from api import ping_response, start_response, move_response, end_response - - -@bottle.route('/') -def index(): - return ''' - Battlesnake documentation can be found at - https://docs.battlesnake.com. - ''' - - -@bottle.route('/static/') -def static(path): - """ - Given a path, return the static file located relative - to the static folder. - - This can be used to return the snake head URL in an API response. - """ - return bottle.static_file(path, root='static/') - - -@bottle.post('/ping') -def ping(): - """ - A keep-alive endpoint used to prevent cloud application platforms, - such as Heroku, from sleeping the application instance. - """ - return ping_response() - - -@bottle.post('/start') -def start(): - data = bottle.request.json - - """ - TODO: If you intend to have a stateful snake AI, - initialize your snake state here using the - request's data if necessary. - """ - print(json.dumps(data)) - - color = "#00FF00" - - return start_response(color) - - -@bottle.post('/move') -def move(): - data = bottle.request.json - - """ - TODO: Using the data from the endpoint request object, your - snake AI must choose a direction to move in. - """ - print(json.dumps(data)) - - directions = ['up', 'down', 'left', 'right'] - direction = random.choice(directions) - - return move_response(direction) - - -@bottle.post('/end') -def end(): - data = bottle.request.json - - """ - TODO: If your snake AI was stateful, - clean up any stateful objects here. - """ - print(json.dumps(data)) - - return end_response() - - -# Expose WSGI app (so gunicorn can find it) -application = bottle.default_app() - -if __name__ == '__main__': - bottle.run( - application, - host=os.getenv('IP', '0.0.0.0'), - port=os.getenv('PORT', '8080'), - debug=os.getenv('DEBUG', True) - ) diff --git a/app/server.py b/app/server.py new file mode 100755 index 000000000..6abbc4a01 --- /dev/null +++ b/app/server.py @@ -0,0 +1,88 @@ +import json +import os +import random + +import bottle +from bottle import HTTPResponse + + +@bottle.route("/") +def index(): + return "Your Battlesnake is alive!" + + +@bottle.post("/ping") +def ping(): + """ + Used by the Battlesnake Engine to make sure your snake is still working. + """ + return HTTPResponse(status=200) + + +@bottle.post("/start") +def start(): + """ + Called every time a new Battlesnake game starts and your snake is in it. + Your response will control how your snake is displayed on the board. + """ + data = bottle.request.json + print("START:", json.dumps(data)) + + response = {"color": "#00FF00", "headType": "regular", "tailType": "regular"} + return HTTPResponse( + status=200, + headers={"Content-Type": "application/json"}, + body=json.dumps(response), + ) + + +@bottle.post("/move") +def move(): + """ + Called when the Battlesnake Engine needs to know your next move. + The data parameter will contain information about the board. + Your response must include your move of up, down, left, or right. + """ + data = bottle.request.json + print("MOVE:", json.dumps(data)) + + # Choose a random direction to move in + directions = ["up", "down", "left", "right"] + move = random.choice(directions) + + # Shouts are messages sent to all the other snakes in the game. + # Shouts are not displayed on the game board. + shout = "I am a python snake!" + + response = {"move": move, "shout": shout} + return HTTPResponse( + status=200, + headers={"Content-Type": "application/json"}, + body=json.dumps(response), + ) + + +@bottle.post("/end") +def end(): + """ + Called every time a game with your snake in it ends. + """ + data = bottle.request.json + print("END:", json.dumps(data)) + return HTTPResponse(status=200) + + +def main(): + bottle.run( + application, + host=os.getenv("IP", "0.0.0.0"), + port=os.getenv("PORT", "8080"), + debug=os.getenv("DEBUG", True), + ) + + +# Expose WSGI app (so gunicorn can find it) +application = bottle.default_app() + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt index 7e5840db6..aa1d9874d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -bottle==0.12.13 -gevent==1.3.6 -greenlet==0.4.14 -gunicorn==19.9.0 +bottle==0.12.18 +gevent==1.4.0 +greenlet==0.4.15 +gunicorn==20.0.4 diff --git a/runtime.txt b/runtime.txt index f27f1cc5c..6919bf9ed 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-2.7.15 +python-3.7.6 diff --git a/static/head.png b/static/head.png deleted file mode 100644 index 5ee3456aced7e9c28529c432b559428bf485e1b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15842 zcmbVzWmH^Q7A_v#-6@4i;OwSrjPVRQj z#%@e@PLzL;{KX>yaxw*5IXGL{+mZj|H8!z#aTWvsej57M>rX#z9sXs=&gsuxJ@1dj z&Dep3jhU6@e}O=5R{wVIKTtnc{t@;ZAq9p1yER+e|7p<4S@P}k2L24le^~s>PbYPE z2M~)Y$jROXYzmTm3$k;j{9nGCnf{B%!3AvdE39UwEFc?@?K8yb*?G4A>4LMB`9JLW z=gL3s*}>A@+1|<0{vV?JujPLvFagkU(3p|G$s96eKGl^ekYuvN8j5i-~b_@^bKUOR$Scva+#>N{Wh$@^SI7@^G+oaEtyC zDg}k#q5nlIW99T5TKC^->A9kQ4JkE{<9|y3TClPDHEbM=!A_u`%_s=?s~dkW$$!ls zfnQAxbh0;hb~OfrL@l1%Pe}CVR3%sbt7*u^)wswtt?bO~U7ZA2{ukiij{lw5)Y90_ z0%Rt{@)z(g!9PP>EkSlad*okL{Hqf!18nY+gSZ)zW$K@XBvNX&vQxqciMjrf#(GYdsCO61M<%@Gy8uiv)`cq zcJNPHC9su+m7TH8Z#qA#`2U6ee^C5p#>^CGZV!H*6GB$D#ugwJYX^{p0L#Cn|EcQa zVqy(4b^cqteg^S5Tr9tde^LCmw!qJ`0I2=5?rmItrHO}KfaSl0zZw0tCT?%*00uez znlH}-`M+d;*Z(*FYdb4vp}$Q0P5gJ%udaH276DtC%Gx=Dz|SU~jej}$7r{Sk{GIDL z=+DLQ2l{!Q{POsB+28fG{_UI4ze4i6@HfD}&P3p^x%Yg0frK~&SpJvzH`Mbv2^6(? zKCH~#MI9V$te!hx9qa-UVEG>lf5QG~gx?;PekJ%1>GPwQ5aM%J{PkETgqVI8)d~T@ z;V&y8s_q7P+8&ulPiPb26=XlZ>bjsGF=e6N z#w+X{T_tVy_5&h);o~4gW71+`0%NjdQ&Y`6I@%hpAG6Za<-4iU&CD^EFR2k8@$M3SuDuMktp#J_tg&}j7cKNF z#l$>)n}Oybw^grAgB)utt|8STVy~wpd#dzzW&M1-qok8DhH9^~MPRhCb?j@oa*u^s zlGq-{scQ!X~^cxvg&qCzX*&wmzeS$rFR-!_e(iEMhHjpGUOkk1ijr%!}2p@ zj+5^IuE6s){BVU8tMO>#A$)HrESg>3=A@YF>E=<&SPF(u1h*|A=cE_n1Nvbcr%2_8 zI0iz@9P9O0px0vWXqptzxg1lqt#O#pQ=s~U>x!kh$;c9p9rRWXk%y*Di0-~H1jde- zCunV_uu$kOKAd-1Ng}RClMu$}e|hzNIJ2gzyP7+7rf4akdTtzc(e0`I4t|0_2$Zng zL-xT{;oi-(I$Ib*1kYC*LiLL5#TQrCknKmc@IF(v!H$!oMCq$*s77u!arMNd z2ssvkz)kV$2tCc+*dYUcoKG;F3M1rk^LRvk>LeG#_P#JI&cn^`?NZgulTF3hZnxV> zhwwkD?tZB#`;^`seV5nLk=S9oyjuBEEQhD=hYiPG`}fq_*GZQUq>0=Y2mEQM`8IG| zu5j_^D;||MgdOTcilF-m^ryR5KDJm*b*Zdo&O&B;P~N89^l_lJip3hf*P0)!om9_^bCJaI`d5FLafs5BhsofV3X0pcZwNt#Wi z2YoQF_C@UFM;8T(AKG1HxJi$aN%Xx7_ta8bXC(U!EUl_W))vPUKr4K6bV8XEHeRS&D!Kx;*4n&s z3=(u{(51TA8%C&jBh1#KPAv5Z8{4HFpC^dU+&k6++U`ETGNu)K#=#QQ>4zDHfh;+^QpV(?5-6PJ~#Bv%rx}??|QT> zMahr?n$J15vGXGzo9{#R8`8M`CT8vVwFCf7t8KIaYF+=@>3gj;Ve}HOr@G#Cu68SqU_4mb-e2pW zcgFrS>&(Vt(D*Q$9a>|$;Z^yLK3TT@<=QIa$21XZ{*SGY2*amSkp)1psU8z+Q8x(z zp!U)p?B$z+`9iEt%U6`IqRlaLodu6~5j0bY*nVp{TJIO(viGLe?49OigSsAFS_ zhsxscU8o|mJUZygqq+u?CoN-&YZZRkdr-+nm&K07wtcgUJ5*%KniA{?<)>($9cu{R z+0w(s3;1YwYT{txCo%|+C!!>3~m|K z-%W5o(Azl0FDT=qxODoc$~{EuMH3gs9-qKboCdjr^AVs{s6t3H?6^-!WW!JXHep0qC1hN=f;ryFAFi{>?9!ogM(3a1k*Cjq~A zKov~K!_;r&A6l@@jQ}|6cQ5quGU;&{i59$1rfPMxGBv;A7OcygH2G3FxK%Sn?rl!Q znMOdU@2bE&vR9@#WScNHD55EMXB4NXYlfv%YM@9QC`&jt_}&OAPZW(@MOj=lL~W9u zt_imKqx?%stYP#KCHpNb5=k z*|j;Nnqwz_t^OoNx;Xzbe!aNyOg`8Wzpf5?3VMP{?ECF03dU=W&o3zqRlx&JsweDv zSSTR|4Hj2q0@dq9nrbFbw_8g-&$)iP;}`V8aA!Bg5#Gop`*XSbsL7Wn5{L^6Rx69% z4FYlE9r|q^noNIiP{&I(KV;YUqHw^;$#()2FJ9zNz8Lt7G$9rXi5frmqPxb9MM=Xilfsc1HGES*-Pn16Tlo1vPsx{eCH`eZ8hKZ9SGc zlJvGKiW!E8fFPJzJR1vxPiQ@Q-SugVSi)NAmHfWNQbA1@G84@#I3m1ZI4DaF%)1@oWT7m#qjM#;MQhjp^0Q2H#EuVO{{3D&;Zk`;?8O31M(k{ zh--upJopMDu~#Vq4Nl754~!-JA7lAv6T%S2jOZp??sf9dzkL5XIZX=N$!^lmafI8Z zC9gvse|&^A4t zN{wimhYySiG!5>E$DS$zPCT6JMw1Pjo-MyO+^~-Vk1jrCw|9(MBihsvg2VIHptzyL z&^|mpDrVbwnaY?qmFEb26mTyfD=JnL0_IETLEx93PZW8lvQJSrFw*(Cz&K%9Ny z9nSfj(Y6}P4{DAmO&{A>P}aKN!weh>6C`EZ?#Jk2$Y!DJ#u#IPbRc_C$;FV`k|K7^ z&OOujY`2s@h9UMk6>So{T38%v5SnDu5Fu6zbWnchbJ?X@jQqqvyd1qH60A&izShr7 z5cs+;5Hnsf9o^95hgl`#M?dQK7mN%t-gAfXd`@3$z`?pY=sUbCII*@0-d0D7w7V7f zFYUa7aLnJZJ)pHcH?j zEhLQHHP2eMlwHlz==38J99oQG8RcJ+KgO3Zby&!!+Z&Y=HM1H3ya=pXyRTXK}EY;elH>)i2pBf)f6r!F2E;WYF|sW`nR)bUuT^CFxwi z#YDzVPnS8oc%H&Q88Qy{8|k2!dMB`Z4{no-v)GAv( z)hIYCCnzBVzRgQG;|t9daC_={nUV{~U@xp3`9|!#`%Mezpv)(xe==v9qWKN$R>7y~ z65`Li{f?L!eGkKGOZR5qlMHV6KOhX|cS2aK?lqtVeqYX|aK9`t+|X8N7}#{1JaF+T zYieq;M?Rx4Et+Pdz2kg!ATayGYm;icLvL6PpEl_S#j zdgND(s+FifPYcU14}M6{N~2Mx`ivsnuGzE~cew1%Xga-A{HrW)XfDSlh*3+*QAZ&x z6C4#NEYC#rMvzCn!rM&bA-^lu^E*X!)B<`JgqYfrNl3PE)24_`%SxYE7JN^8ZL4p( z>kjyS1JzbA8{3?boSgXEZqj^{(rRnEAA^hEeN~Tk?>fXR`vl2nm%czd;jBg1iR%Nk z{++SLNf9SK5AO*;Yuj&=T<%+JD|wSqukt7}Q52`M;K<21m5e>|RHX4c&!Xn(caEibd_--M&|MFCUtnP934v&lGk7B z0DOMf6BU#;sj*LeW-pt4X-t1fOxdFyq=l>wH$C0V+&clSqlz zelpdBO@ax_SLknIf}r6(g5G5K~yP^f$!vj7iAIzzKH(x9ZAH1y$>>Y7foaH=_}eJTFZ-LqtnI2m$b!7PSRo<1?IOc>qBM23o>LL~N6nvg8Fw;}>FQ zMQdXX*L@Us-QaSLmyeJaXk}yJ)nl1kf#1?Kgg!sOg(P%_(-5(0%tAY543+ zHSh3r{YsViAlGU1#W(yTe38mBxPnpqZs?eK;Y8_rER7p9lO^~rN*@Yey7i()0(T26 zEV7z022wb49wU$``sh_%SAn#0#TGamfN#mvYJhjXqF>^(k4m!!n_fuR9H22ndJo4*$ha8VW3Z$_lM9HTU01Y?uL*95j>9(( zI(cEeZK|1`Gi?rrx93cw*NDCiH&u9ndc?xR?5&_P_GAmi)^5NA_MKyQ&x>m3J}Oid zZEdp{BbX*U2~3l<44njQ+vTq;@P@CTReQ1Z@9(-XyYO(uS*1568bKan- zrK>lKnm&)i43%rcBlZ^NPPbl-4hJy!d!QA-oTjx?t_zPmc!U!>hi&j0xApX^ps2R; zx^f>f38!cqL6fmnZ0k*u(n`lP!$-kTQ$A<*`o#~l>7?9G0RR0I%WUe*FH=P_-p?aJSLtK);5+i5UVnwgD?#7Lo71N?& zq7_jq)s^|U2(D!eBsIE7GGO6&Cm?Oj+=|bz4?W4<#z*^opGg%Z@GR|>trYD(yu{=! zp)w3iD0UON6&%W0!;2MO{}-yrFba~FLk6K*JMxOb8>-RtNoWdwhJl;-j8vc2j~fD- zo5r(FeQ08b67CTkfE*E^T*kfvTUEVO}-XoOx8xJuhzN|mZ#f7LpNh&VrY@7 zoYS2v?*b-{*yKxx8gwjLe|flNq}As}8x>PsIF)jAnc4!phO_pIly^7y0-dlcPb{f& zN8ndjs9JQ&vOgSgK5US!7ch_O(zzgrdh*!4ieL$h#&+2Pg4cowD_y(6>Gku>_fW>7 zbaV?+uM1BNGz!t_W>{4#DnW^1MYy^5(#cG^J4bta^JMTar1+60WP)Oo3-64d_Vsey zD6uJ-$W<2|zKNykK@zmuCFvp$%A$9|hD61ian8O+=XWAjKh}64g|KiYZyk#u$KXzr za$1C}#t%*%t&W)HMU~O*OYQKe);Tr@7$L=>WiJq}<`wY`nEJ|Lg<> zRjKa#R=;AXS5Uml6+^u5VL88wz(+()nQjJR4GIaiZn^;Ce%D$ zB;NQ(IpY@JAYazN8#@8OgWHByc#9Y zTWbc>7sdk?OQ_=1|@l0k_+?>t%I1qK4~{-4kIzWd{y~rqwp9 ze_kJ}x?Q?TIdVLQ6BMM0kzG20c{Ks4z>emo8LW0UIe+Pz-!c34SwtKx)2{oC|5hhFg`S|7>F5UpWzIZZfb`A#GH7-m1fEa8E*0!h<{a(Krd};M=sTrvo4mCeAFX{o&Yh>>xBrWU$fC& zw(}Vz?rn7EzQfZHRoBJ{9+16A_V*g|KYZXghcSVe%_JWN^7bfS1^fB=-R=@C^%0X% zi;+tkzjmw}&pb6%k;h!&WyI)>3r=t61gS&75ki8Ax0+Q-RfvI#4)|&rt_iLeQ$lMcLQ&KnvB@lw zHw-q)&q)^!Fo{IN7Dh`|1~~dcomd4RP*y0Ks+|sG{(e+LlA<;~8s&-Wb{$*zMg zWD6`xf{jW=l+MC0R2F4R%!(&3yPM2j1Hx(Gv9~JLM$G!61w4Gn>5d)|_yRNfpJvJ1 zrMJ(>yks-_65}A)I@2JaZv9CiFqIXkqHT|3z2F-(n;6*%WIgP7MI?;ziw8`D7%IWn zdz6S#2Ym!^Y^BQt;~T_}LuQ{#b(s%L)#2Ijorkz@kj^%A9D!Wy6OduuFt?SgI8d{} z?^zE;?bc43SbfAZX#)?!Ms%4dWb-~aFspuWQklseV$YO2A*n7fiS|63B8zEhck4J5 z02UbFa+Gt(mT^!S4dvXO}eeyP2tXl4XTxe%C))UKv&J8j(^Xv$)Ws52#t;dnv} z_JA8D#N;q2+HvU2mXLt%p01Swi2AOAh@=$*NyKI?P>vJCG+$he>l2CEF}b;v$0Nk3 z)CL@JScX4+h+XJa`b@VnE_`mXIzC^7_imu-AZNJvvac59c=9~^)`MTOyrhnT(L_bA zO+>pjV;27H2E|;D$K-Gh3$^gOQt7NEK`J%$^)`}?H*Yh=7nNVLhnDNR^ypE??dgxF zu!}ANn?bAVSm#fd;oI5mSB~23_GuY=sDtgMnQOtky;@>?aeSGw$E}aRTf=Klk)+Sr z^ek=FWVwVb5Br84R5OW%h(m-9Qow1-^-mw^^&b%P28G|{sdal1Fvfn8rG(0Pi$3T? z+idv)+?4X7M>A4HDL@&HA}!k*p@di&p%J>L09&2G&x_B?W`8S~O!(<$(_*yo;Rx?i zh(5407OB9cInwK^K3CPJS?1orF!EQQS>J_F22vVtC1NdwZ+tU6I_lAJ2w3(~Xwvhs zt)>dlc0Vr^;)@8J?Dn9_2rJHKCk=8s)xV&1(Q9%GuFE=%yL*pwo|PD>s;@%DQ;`}{ zS0;N!Z1dVTi>J(>{fEzS9FfL2MgvwE7_!7m!S-)?^%o@zmUvqQ!5A&3iqJ@^M1XRaqbb|#k#-qa z(N@Nr>LL9yCoVcKtklRPZnlOgVZ$NT% z$K&ZjpF?5`miK+oh34E5d8f*4OORm8Bzik}#DyuB8{7cSonP-`ljutRY@Wz9VlJz+ z3L&t8UlWY`{EI`OT_wowi^(Oj7_wE@X!RrjJVNy1Zpbn3^2_X}@9AbUHMhmFU659} z!i!5w5<~(YE<{KCN)m9=3vo^C_&+FWHHChqQa&?@0b|dQ_%)GAiyA;jP4H3}h{<$L zZ14+UizWmF5tr{OXNu1f= zmrw~=D3&GxqM@rpP;qNNEh<@K#pA@ zp}qdpP4gLL!k9lY;B*m^n}e|)x%-LEAsA_fuD05}6J1_s=W}L>2W`mA>u429-!6EOAA%LJK$NkPBb8urwVL z1!@al8!UPwug8XJQEcG5la^vszb)2BCGB6lIHEwvzsapi^A)cYVe-X=K17<36OTj8 zjiukiX22Gd#NF*%7G$abZ(U%$m$(Z)n7!_pz)6Tl*9K-r&7Oi9VlBMCeYM)#28+3m z^V_Rj)_`Fk$iq1p$K?UBUH#5>Y1NJ-y-M`5-zq{?0#2N7(7bWEera#bh6Ng_ zJmF+2Ci$<%oDQ$8s7m`FCg<%T=Pc?&OZ?PQ~1E%aBYo6~#lL%q=tr_u<-@VnT!$isSJx z1$TF?Q;V+R&PYW5v_=b>jo|^+woXz5pfrK$?{r>nGHaP`Y0h*lyXir7S{H=5c?|~4tg*HWMbFh8if@Oxk6E?x0 z6{?GI3$!VqzTMv@JMlr6(_#?5Jww~hCG*tW4>tu5T%v&Im}XTt05X@$?HoGJBX^Nf*zA;K7#M?a##qh)=86k(zIMbw@QX{6>rh}r&Vk$UxZ zXVv67B-C@`u@*EIf!4VwH?kIk#??_$tHZ9Z!IDm=>w1`or3JIN?5QVootzzC+{HBB zwnD{I*~cAToMizKlz#XYf*97l3ZhJ_inSc_saS%MyVw{A3125hQw>9hSPMj@QWZK7 zWs`{Tv6OM&DJ(3^W+jXibr`N%VLm!YA%{tf;NLitDB({6J1EhcBU=@75U++HB=%5& z&>af;5pMHnxq?Ecj3|P)6N38mdSiqENAn#YzRl;WnkbDF3%826FUtnfFY-4l8vt`I zl4imb*aAc$q$$6fPY*vxWggBi0fg_@h2>!__Oml;!v`L2M0BK`r`Bl;3`WmIfth zdIOs%d~jTVs`t4Bc{{f+wW0dkKyRe-qHmI+EB;6j0j`{+n*e#6!s1cmJpXXdV4moK zj}U#Ha72Fn4u~Ha0D&Y}v|CYenB}ehD!$gv#33o1-IXcYm1EVsM9HQ7x%g}FxNuT| z*tN}D%fSbkU%U|aGN2o~5q_AWp zB0PQ)VUL4@Lx;L%?{T?RuGXkbnKL0$nH9Yrk4YXT_P(@vZJG#Uuv?hk*(4q~fr8df z7TP&mx0cje>A%|-vdWWoVj3Ky#W)*96A>0@x$u=07y^dRj*MEwCG-3hVf3cOKp zta&vlLC>f7ug(=K?%%2?VJ;jbkogOvvQPBZfvTRg=*mwp7>WLIIavPe4u6O(a;uKa^)+$5PBqiC4k&e|)Z2q>7 z4ts~99M-nts`B9`tE1T@;os^ng(Lj%;2FNsKI}xmT&q(}X!Aiu zh?~U!Kr^Gl$m^GK+#|ge(y<(hKLyY3g=}ssRktR3ksT}=_;KX5iktp>EMHh!-W;_^ zw@~sr@mf4y)E7b*i!{Us|DAb`3m!z z37ahFm1x~P8p_X}2&20Q^b z<0JPj-Ekkxg!;0YW?+I`QJ7ra`*U{n>sV1e<&~hcmDuB#;Jt57ke2lrEkK(^KnQ>A zPNrTsRos0ZhPa@pW3PiiX2YB-aRQ6irs%@eg?SThIIw9YW7$~xv})N;VxCUr1691o z2=rI9?2!A?DnL**lXrBNn!P{oG0K1sT8MMUXY+R$2jojqY2(|(L=3`P%NF-K>FFKe z0csCi$9!f!^q1)JdbOme^V;3(hq@!N@n`|*jn&)ruYp$H>#(=eWlLsb!;&?qBl#9e z*@2HrdNL;4D3IN%DoiUW0ZJyaw&a0c>Wd!Rk@_#Tx06>B+KV>XabWT1W}9&mrv}MG z)B$s%`muAcjNjKcl(7B3;~Th3M%OVhvc6oHA5@@sh6l5@nmNR$Lb1c+Vxj~@#=T+)jA6Jb7XS`YGnx)- z8U<7M7^6m{rVvIYIZDEdA!-$7bgiBZ=G34OtwTcMfP9F$p^5a|s!U!lSyRo;{CnhH2V~h%-}QF1YbIFhh=pJiYh?VYPi$ZRgqF$koQ(kQ{FfTj*qxLFfkt4!Zi$ z;Kis0fgtLp_l#L#UjHET^_Iq_j~)fM>B+2a^7V^ zXg{O~+Zp5`j-B&2PsBCHG->0rKuWtSh85D9QmT^VctY_cvN4Q=45v`%F6(6<3~+rJ zRG)4{Ve%pCz`*M9E*0NL@il)Ne_bW%=ZoJMw4exwP5`A748kUchAJ_s*7nMNJhV{4 zjWgaaV)G!|Bftvllj8d8@HgB7DB{P%9>;ao@zgPUBUgw zUI<_WVYLsTdaH{@{7Js+{2|nrY-OnGWFA74A`me{DQ~#VnlZBw>#oJ&G@yIn_=kcCxvW7hFBu+sw)9BBeLwPW6mr-wP*3V(04hMmUdZ7 zV=wd!hBM_`a!Ocm5P~cm1gv$%bkuoe3St6E)!fEHrk%+UH??BAtR?r7IDM}e^jzDG zahlu9$DeCPI#8giGFBQN2t|L;hwFt5nDjWKd^Lzr7R*xD-kriL%<_p%cp`e5rS!Ij zs2{ykE4UW>+LR*Nk(O3GDp_5FWQ#1mi}bW0D;c9UfR;3y`xw5fieIJs#~Ufd)!s0T zFe*uR){t*ZWpJo@S!)brqYOs-5Ao(?4gNaHMkgTGwjWn-%Hi>D};7rbf4f z#TfMNjZ6`4N`W&fz4uk3u7Mw1k9<7u^Om;WVm-Fjkx@J=<#cuDgAQf%?D0t2wQr)n z`y`xd7c6v72qs&S+J93XrH>IvzPkd&v8TJ`t64?OTc&C$hAO$?j&+0Gd4r)A3RL^V zF)4vy6h`MU{!oD~X2(B+cCxM+)_;{-bzTvYsj7c2l(r>aEI~6KuWNaCPTYjIpj4IZ zO}T%KAn(Qn-3M$<$P4v7XW+PXBiDG47QlBO=Z?0A$mjO-5GH}kmH|vpqJ@e0u_1n5 z7!DUFtTk>pO|0$p_tX1=Qy`Z8ai>eWwI^7vL0ZCF&!rC+4-ECq%0#c~>p+?DhYCOs|Y}9Y0 zQ-XZnq5&yU>aWKS+rR84-Ux66Fr0EKFR<;!w}?Ex->sIZOP+~@kSDXw*3v+vA?<@k zx4_2<&m0nkCC3de-V#b+#b9lv8~4CJq>aMoVur{7|A_=?s2&#>g5l&lC=XqFFFKLhm^j}O5OP^70y!5uqLusr zhg-pI!YaD~T70-u{>2cbz<1W2kbWdq#Ry6fP zQ4%=gCF^(epbyfj+#qj?F?9$W=GOy_Q5mc5B>9jM2DxXtFn|b}*C6Vcm`ZwFcTyxf zd~tw@&)ngFId&8OnbY*^&>#!L;oU|vWEOJ>h*`Uo?#FqV+cy1)gtwU8N2sCUk6P=5 z(4|fmFkvz9y{O6T4w?LZL+I`+?11@kPS%7EZ6Nb;wAk5jS~k8ld2!s>T%3o4pc{Y% zt69fKnwJ#zwzxh3r2vb2^p-n(nVmk4YyAa#O%#fZmoYU+Nq8A+7tNm>hS?Etb`y3h zyErxOLm*7*avHG$QMx3Oz;|6-$ZZ)YHfxAgG`q^$YBY2Vw)l+hSpcST|4_ZOVBww@ z`qlM3SGALI8#HJQu0-A1j{{Wcp0@M0nhysKn9Un#ECT3Z-gF<3eBKKi2!n90TvkaW zN=Q_`6Fqkpq*6hZi5KA0oT++JSq&ntMlRYVf-lFO=!7^-#u9C}8`-#R-^#h}yS#A= zfePVx??d)ZUB6nVlcvdzO8OA&mq;OHJtoxx1YtC9l;E&9mQmknXzI1Kot^;e~2Vl%a%@7K6KA;|`doQsFk;-Op@`jpQqSG-c<+?xh0+=o?;MRfxdn z`o>7WlSNYsEN>!7C%y0tFznCX7fK!5){u8zuWW=I#+IfZ_j+%XpD3x~21Udxi~<`4 zI6Z-WalOVe67eeT8)k^>?Dh#^Udj*C00ACBdBb>LZAn^ zc&Z`e1gR;s8Gt-;__{pqQCznQFMZe(@^K|ZO;cYWlJnS=ObotM-W-C=GZ$niqW_)r zu#_Fgob4%%ewH3;5KjzQ5*Io}{^+=Cm9ZDMV#wTQW4(OBfo4|3kPC@kI2)-Wnl_BZ zbL2IDxDIKL?R?agVmY6-_9p9Iqfl%TR-zCQiQIk+I_6P>;arqP__@g@`@dGTH{Kq zA_*e;fiLs}AA_B^;*N_8H1)EjmP^Z{=<8x4{PFRXBhDe6BhSO6u-6YPm?s!NVbL`u w^u{!Fkv-$H8PBJd?FHWeNR|P&h}|F1^5KB06r7u_pMSiTl~k0d5Hs@sKU2~cIRF3v From 55d8381932315af0a7885cf70fd64eb567bd300a Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 21 Feb 2020 19:46:03 -0800 Subject: [PATCH 041/117] Remove CI linting and formatting, we don't want to cause extra trouble in forked repos. --- .github/ci.yml | 35 ----------------------------------- .github/workflows/ci.yml | 35 ----------------------------------- 2 files changed, 70 deletions(-) delete mode 100644 .github/ci.yml delete mode 100644 .github/workflows/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml deleted file mode 100644 index 2397f56d4..000000000 --- a/.github/ci.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: CI - -on: [push] - -jobs: - - format: - name: Format (Black) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@master - with: - python-version: 3.7.6 - - name: Install Dependencies - run: | - pip install --upgrade pip - pip install black - - name: Run Black - run: black app/ --check - - lint: - name: Lint (Flake8) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@master - with: - python-version: 3.7.6 - - name: Install Dependencies - run: | - pip install --upgrade pip - pip install flake8 - - name: Run Flake8 - run: flake8 app/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 2397f56d4..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: CI - -on: [push] - -jobs: - - format: - name: Format (Black) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@master - with: - python-version: 3.7.6 - - name: Install Dependencies - run: | - pip install --upgrade pip - pip install black - - name: Run Black - run: black app/ --check - - lint: - name: Lint (Flake8) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@master - with: - python-version: 3.7.6 - - name: Install Dependencies - run: | - pip install --upgrade pip - pip install flake8 - - name: Run Flake8 - run: flake8 app/ From b1e8d7f60acad2619bb3c044628f7dfd176c13ff Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sat, 14 Mar 2020 21:00:11 -0700 Subject: [PATCH 042/117] Overhaul the Python Starter Snake to be easier to user. (#19) Overhaul to make this easier to use. Also switch to cherrypy. --- CONTRIBUTING.md | 3 -- Procfile | 2 +- README.md | 4 +-- app.json | 4 +-- app/__init__.py | 0 app/server.py | 88 ------------------------------------------------ requirements.txt | 5 +-- server.py | 60 +++++++++++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 101 deletions(-) delete mode 100644 CONTRIBUTING.md delete mode 100644 app/__init__.py delete mode 100755 app/server.py create mode 100644 server.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 5a5d7073d..000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contributing - -Please see [community/CONTRIBUTING.md](https://github.com/BattlesnakeOfficial/community/blob/master/CONTRIBUTING.md) diff --git a/Procfile b/Procfile index cfeefd8e0..ac9d762f1 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn app.server --worker-class gevent +web: python server.py diff --git a/README.md b/README.md index 32c947e8e..05bd059dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -# starter-snake-python - -A simple [Battlesnake](http://play.battlesnake.com) written in Python. +# A simple [Battlesnake](http://play.battlesnake.com) written in Python. Visit [https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md](https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. diff --git a/app.json b/app.json index 1178cc6b2..72af990a8 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,6 @@ { - "name": "BattleSnake Python", - "description": "A simple BattleSnake written in Python.", + "name": "Python Starter Snake", + "description": "A simple Battlesnake written in Python.", "repository": "https://github.com/BattlesnakeOfficial/starter-snake-python", "website": "https://play.battlesnake.com", "keywords": [ diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/server.py b/app/server.py deleted file mode 100755 index 6abbc4a01..000000000 --- a/app/server.py +++ /dev/null @@ -1,88 +0,0 @@ -import json -import os -import random - -import bottle -from bottle import HTTPResponse - - -@bottle.route("/") -def index(): - return "Your Battlesnake is alive!" - - -@bottle.post("/ping") -def ping(): - """ - Used by the Battlesnake Engine to make sure your snake is still working. - """ - return HTTPResponse(status=200) - - -@bottle.post("/start") -def start(): - """ - Called every time a new Battlesnake game starts and your snake is in it. - Your response will control how your snake is displayed on the board. - """ - data = bottle.request.json - print("START:", json.dumps(data)) - - response = {"color": "#00FF00", "headType": "regular", "tailType": "regular"} - return HTTPResponse( - status=200, - headers={"Content-Type": "application/json"}, - body=json.dumps(response), - ) - - -@bottle.post("/move") -def move(): - """ - Called when the Battlesnake Engine needs to know your next move. - The data parameter will contain information about the board. - Your response must include your move of up, down, left, or right. - """ - data = bottle.request.json - print("MOVE:", json.dumps(data)) - - # Choose a random direction to move in - directions = ["up", "down", "left", "right"] - move = random.choice(directions) - - # Shouts are messages sent to all the other snakes in the game. - # Shouts are not displayed on the game board. - shout = "I am a python snake!" - - response = {"move": move, "shout": shout} - return HTTPResponse( - status=200, - headers={"Content-Type": "application/json"}, - body=json.dumps(response), - ) - - -@bottle.post("/end") -def end(): - """ - Called every time a game with your snake in it ends. - """ - data = bottle.request.json - print("END:", json.dumps(data)) - return HTTPResponse(status=200) - - -def main(): - bottle.run( - application, - host=os.getenv("IP", "0.0.0.0"), - port=os.getenv("PORT", "8080"), - debug=os.getenv("DEBUG", True), - ) - - -# Expose WSGI app (so gunicorn can find it) -application = bottle.default_app() - -if __name__ == "__main__": - main() diff --git a/requirements.txt b/requirements.txt index aa1d9874d..abd979817 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1 @@ -bottle==0.12.18 -gevent==1.4.0 -greenlet==0.4.15 -gunicorn==20.0.4 +CherryPy==18.5.0 diff --git a/server.py b/server.py new file mode 100644 index 000000000..d40b3f64a --- /dev/null +++ b/server.py @@ -0,0 +1,60 @@ +import os + +import cherrypy + +""" +This is a simple Battlesnake server written in Python. +For instructions see https://github.com/BattlesnakeOfficial/starter-snake-python/README.md +""" + + +class Battlesnake(object): + @cherrypy.expose + def index(self): + # If you open your snake URL in a browser you should see this message. + return "Your Battlesnake is alive!" + + @cherrypy.expose + def ping(self): + # The Battlesnake engine calls this function to make sure your snake is working. + return "pong" + + @cherrypy.expose + @cherrypy.tools.json_in() + @cherrypy.tools.json_out() + def start(self): + # This function is called everytime your snake is entered into a game. + # cherrypy.request.json contains information about the game that's about to be played. + # TODO: Use this function to decide how your snake is going to look on the board. + print("START") + data = cherrypy.request.json + return {"color": "#888888", "headType": "regular", "tailType": "regular"} + + @cherrypy.expose + @cherrypy.tools.json_in() + @cherrypy.tools.json_out() + def move(self): + # This function is called on every turn of a game. It's how your snake decides where to move. + # Valid moves are "up", "down", "left", or "right". + # TODO: Use the information in cherrypy.request.json to decide your next move. + print("MOVE") + data = cherrypy.request.json + return {"move": "down"} + + @cherrypy.expose + @cherrypy.tools.json_in() + def end(self): + # This function is called when a game your snake was in ends. + # It's purely for informational purposes, you don't have to make any decisions here. + print("END") + data = cherrypy.request.json + return "ok" + + +if __name__ == "__main__": + server = Battlesnake() + cherrypy.config.update({"server.socket_host": "0.0.0.0"}) + cherrypy.config.update( + {"server.socket_port": int(os.environ.get("PORT", "8080")),} + ) + cherrypy.quickstart(server) From bb49456063217b0e6b4231143c393169ae302b2c Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sat, 14 Mar 2020 21:01:39 -0700 Subject: [PATCH 043/117] Change default move to "up". --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index d40b3f64a..493f12dd2 100644 --- a/server.py +++ b/server.py @@ -39,7 +39,7 @@ def move(self): # TODO: Use the information in cherrypy.request.json to decide your next move. print("MOVE") data = cherrypy.request.json - return {"move": "down"} + return {"move": "up"} @cherrypy.expose @cherrypy.tools.json_in() From 752c86aaea5c19717a1c58d178aeb04d8967c34c Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sat, 14 Mar 2020 21:15:58 -0700 Subject: [PATCH 044/117] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 05bd059dc..d747e6dea 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -Visit [https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md](https://github.com/BattlesnakeOfficial/community/blob/master/starter-snakes.md) for API documentation and instructions for running your AI. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It's setup to be easily deployed to [Heroku](https://heroku.com), but you can use other cloud providers if you'd like. -This AI client uses the [bottle web framework](http://bottlepy.org/docs/dev/index.html) to serve requests and the [gunicorn web server](http://gunicorn.org/) for running bottle on Heroku. Dependencies are listed in [requirements.txt](requirements.txt). +## Technologies -[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) +This Battlesnake uses [Python 3.7.6](https://www.python.org/) and [CherryPy](https://cherrypy.org/). ## Prerequisites From 7eb225bf3dc7b14332fc20df72369448ea57ad90 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sat, 14 Mar 2020 21:16:19 -0700 Subject: [PATCH 045/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d747e6dea..a0deaeb24 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake ## Technologies -This Battlesnake uses [Python 3.7.6](https://www.python.org/) and [CherryPy](https://cherrypy.org/). +This Battlesnake uses [Python 3.7](https://www.python.org/) and [CherryPy](https://cherrypy.org/). ## Prerequisites From 2751198d7ba530b0f1c9e01ca9fe89971bd981df Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sun, 15 Mar 2020 15:20:50 -0700 Subject: [PATCH 046/117] Update README.md --- README.md | 153 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 114 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index a0deaeb24..7b094acdb 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,150 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It's setup to be easily deployed to [Heroku](https://heroku.com), but you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), but you can use other cloud providers if you'd like. -## Technologies +### Technologies -This Battlesnake uses [Python 3.7](https://www.python.org/) and [CherryPy](https://cherrypy.org/). +This Battlesnake uses [Python 3.7](https://www.python.org/) and [CherryPy](https://cherrypy.org/), deployed to [Heroku](https://heroku.com). -## Prerequisites +### Prerequisites -- A working [Python 3.7](https://www.python.org/downloads/) development environment - - [MacOS](http://hackercodex.com/guide/python-development-environment-on-mac-osx/) - - [Windows](https://docs.battlesnake.com/tutorials/python) -- [pip](https://pip.pypa.io/en/latest/installing.html) to install Python dependencies -- Experience [deploying Python apps to Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) +* [GitHub Account](https://github.com/) and [Git Command Line](https://www.atlassian.com/git/tutorials/install-git) +* [Heroku Account](https://signup.heroku.com/) and [Command Line](https://devcenter.heroku.com/categories/command-line) +* [Battlesnake Account](https://play.battlesnake.com) -## Running the Snake Locally +## Deploying Your First Battlesnake -1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork). - -2. Clone repo to your development environment: +1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your own GitHub Account +2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) to your local dev environment ```shell - git clone git@github.com:/starter-snake-python.git + git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-python.git ``` -3. Install dependencies using [pip](https://pip.pypa.io/en/latest/installing.html): - +3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps) ```shell - pip install -r requirements.txt + heroku create [YOUR-APP-NAME] ``` -4. Run local server: - +4. [Deploy your code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code) ```shell - python app/server.py + git push heroku master ``` -5. Test your snake by opening your snake server in your browser +5. Open your new Heroku app in your browser + ```shell + heroku open + ``` + If everything worked successfully, your browser should open up to http://[YOUR-APP-NAME].herokuapp.com and show the following message: + ``` + Your Battlesnake is alive! + ``` +6. If you want, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) ```shell - open http://127.0.0.1:8080/ + heroku logs --tail ``` + (the `--tail` option will show a live feed of your logs in real-time) -## Deploying to Heroku +**At this point your Battlesnake is live and ready to enter games!** -1. Create a new Heroku app: +## Register Your Battlesnake and Create Your First Game - ```shell - heroku create [APP_NAME] - ``` +1. [Login to your Battlesnake account](https://play.battlesnake.com/login/) if you haven't already -2. Deploy code to Heroku servers: +2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). - ```shell - git push heroku master - ``` + **Name**
+ Whatever you want to call your Battlesnake! -3. Open Heroku app in browser: + **URL**
+ The URL for your Heroku app, http://[YOUR-APP-NAME].herokuapp.com. - ```shell - heroku open - ``` + **Description**
+ Describe your Battlesnake for other Battlesnake Developers who might be interested. -or visit [http://APP_NAME.herokuapp.com](http://APP_NAME.herokuapp.com). + **Tags**
+ List any technologies you used to build your Battlesnake - probably `Heroku` and `Python`. -4. View server logs with the `heroku logs` command: + **Allow anyone to add your snake to a game?**
+ Select this if you want to allow other Battlesnake Developers to enter this Battlesnake into their own games. +3. Once your Battlesnake has been created, click [Create Game](https://play.battlesnake.com/account/games/create/) to start a new game with your new Battlesnake. Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game. + +4. You should now see a brand new Battlesnake game with your Battlesnake in it! Yay! Press `Play` to start the game and watch how your Battlesnake does. + +5. Repeat step 3 every time you want to start a new game and see how your snake behaves! + +6. If you open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running, you'll see your snake recieving API calls from the game engine and responding with its moves. ```shell heroku logs --tail ``` -## Questions? +**At this point you should have a registered Battlesnake and be able to create games!** + +## Customizing Your Battlesnake + +Now you're ready to start making your Battlesnake your own. By default, your Battlesnake won't be unique looking, nor very smart. Let's change that! + +### Customize your Battlesnake's appearance + +When the game engine tells your Battlesnake that a new game is starting, you can optionally reply with what color you want to Battlesnake to be, and what you want your head and tail to look like. + +Locate the `start` function inside server.py. You should see a line that looks like this: +```python +return {"color": "#888888", "headType": "regular", "tailType": "regular"} +``` + +See the [Battlesnake Documentation - Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. + +### Change Your Battlesnake's Behaviour + +On every turn of the game, your Battlesnake receives information about the game board and has to respond with its next move. + +Locate the `move` function inside server.py. You should see a line that looks like this: +```python +return {"move": "up"} +``` + +Your Battlesnake can move one of four directions: "up", "down", "left", or "right". For now, choose a new direction to move in. + +See the [Battlesnake Documentation - Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game and moving around the board. + +### Updating Your Battlesnake + +Once you've made your changes, commit them using git and deploy your changes to Heroku. +```shell +git add . +git commit -m "update my battlesnake's appearance" +git push heroku master +``` + +Once heroku has been updated, you can [start a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your new changes! + +**At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!** + +## Developing Your Battlesnake + +Now you have everything you need to start making your Battlesnake smarter. Here are a few helpful tips as you get going... + +* Keeping your `heroku logs --tail` command always running in a second window is always helpful for watching activity and debugging any problems with your Battlesnake. + +* You can use the Python `print()` function to output information to your `heroku logs` stream. This is very useful for viewing what information is available in each command, and debugging any logic in your code during Battlesnake games. + +* Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each comamnd. You can also output the data to your logs: + ```python + def move(self): + data = cherrypy.request.json + print(data) + return {"move": "up"} + ``` + +* When viewing a Battlesnake game, you can pause playback and move forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. + +Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Developers. + +--- + +### Questions? -Email [hello@battlesnake.com](mailto:hello@battlesnake.com), or tweet [@battlesnakeio](http://twitter.com/battlesnakeio). +You can join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake Developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) From c892490a5fa9c4f3f3e27226a5c4a6e0ee30a9a4 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Sun, 15 Mar 2020 15:28:39 -0700 Subject: [PATCH 047/117] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b094acdb..5e9ed002e 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ This Battlesnake uses [Python 3.7](https://www.python.org/) and [CherryPy](https Now you're ready to start making your Battlesnake your own. By default, your Battlesnake won't be unique looking, nor very smart. Let's change that! -### Customize your Battlesnake's appearance +### Changing Appearance When the game engine tells your Battlesnake that a new game is starting, you can optionally reply with what color you want to Battlesnake to be, and what you want your head and tail to look like. @@ -97,9 +97,9 @@ return {"color": "#888888", "headType": "regular", "tailType": "regular"} See the [Battlesnake Documentation - Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. -### Change Your Battlesnake's Behaviour +### Changing Behavior -On every turn of the game, your Battlesnake receives information about the game board and has to respond with its next move. +On every turn of the game your Battlesnake receives information about the game board and has to respond with its next move. Locate the `move` function inside server.py. You should see a line that looks like this: ```python @@ -112,14 +112,14 @@ See the [Battlesnake Documentation - Battlesnake Rules](https://docs.battlesnake ### Updating Your Battlesnake -Once you've made your changes, commit them using git and deploy your changes to Heroku. +After you've made your changes, commit them using git and deploy your changes to Heroku. ```shell git add . git commit -m "update my battlesnake's appearance" git push heroku master ``` -Once heroku has been updated, you can [start a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your new changes! +Once heroku has updated you can [start a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. **At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!** From 5548d9a740ada44fb685eb9c07f19410c5202c80 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 16 Mar 2020 13:27:12 -0700 Subject: [PATCH 048/117] Bring back random moves as default. --- server.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 493f12dd2..ebc33862b 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,5 @@ import os +import random import cherrypy @@ -26,8 +27,8 @@ def start(self): # This function is called everytime your snake is entered into a game. # cherrypy.request.json contains information about the game that's about to be played. # TODO: Use this function to decide how your snake is going to look on the board. - print("START") data = cherrypy.request.json + print("START") return {"color": "#888888", "headType": "regular", "tailType": "regular"} @cherrypy.expose @@ -37,17 +38,22 @@ def move(self): # This function is called on every turn of a game. It's how your snake decides where to move. # Valid moves are "up", "down", "left", or "right". # TODO: Use the information in cherrypy.request.json to decide your next move. - print("MOVE") data = cherrypy.request.json - return {"move": "up"} + + # Choose a random direction to move in + possible_moves = ["up", "down", "left", "right"] + move = random.choice(possible_moves) + + print(f"MOVE: {move}") + return {"move": move} @cherrypy.expose @cherrypy.tools.json_in() def end(self): # This function is called when a game your snake was in ends. # It's purely for informational purposes, you don't have to make any decisions here. - print("END") data = cherrypy.request.json + print("END") return "ok" @@ -57,4 +63,5 @@ def end(self): cherrypy.config.update( {"server.socket_port": int(os.environ.get("PORT", "8080")),} ) + print("Starting Battlesnake Server...") cherrypy.quickstart(server) From ea518b264db6f31f89c1ec7dd517a6984557ac85 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 16 Mar 2020 14:07:13 -0700 Subject: [PATCH 049/117] Update README further. --- README.md | 119 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 5e9ed002e..e8548ed36 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,140 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), but you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api) that moves randomly around the board. It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), and you can use other cloud providers if you'd like. ### Technologies -This Battlesnake uses [Python 3.7](https://www.python.org/) and [CherryPy](https://cherrypy.org/), deployed to [Heroku](https://heroku.com). +This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https://cherrypy.org/), and [Heroku](https://heroku.com). ### Prerequisites * [GitHub Account](https://github.com/) and [Git Command Line](https://www.atlassian.com/git/tutorials/install-git) -* [Heroku Account](https://signup.heroku.com/) and [Command Line](https://devcenter.heroku.com/categories/command-line) +* [Heroku Account](https://signup.heroku.com/) and [Heroku Command Line](https://devcenter.heroku.com/categories/command-line) * [Battlesnake Account](https://play.battlesnake.com) + + ## Deploying Your First Battlesnake -1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your own GitHub Account +1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your own GitHub Account. -2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) to your local dev environment +2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) to your local environment. ```shell git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-python.git ``` -3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps) +3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps). ```shell heroku create [YOUR-APP-NAME] ``` -4. [Deploy your code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code) +4. [Deploy your code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code). ```shell git push heroku master ``` -5. Open your new Heroku app in your browser +5. Open your new Heroku app in your browser. ```shell heroku open ``` - If everything worked successfully, your browser should open up to http://[YOUR-APP-NAME].herokuapp.com and show the following message: + You should see the following text: ``` Your Battlesnake is alive! ``` -6. If you want, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) - ```shell - heroku logs --tail - ``` - (the `--tail` option will show a live feed of your logs in real-time) +Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval). +```shell +heroku logs --tail +``` +(the `--tail` option will show a live feed of your logs in real-time) **At this point your Battlesnake is live and ready to enter games!** -## Register Your Battlesnake and Create Your First Game -1. [Login to your Battlesnake account](https://play.battlesnake.com/login/) if you haven't already -2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). - - **Name**
- Whatever you want to call your Battlesnake! +## Registering Your Battlesnake and Creating Your First Game - **URL**
- The URL for your Heroku app, http://[YOUR-APP-NAME].herokuapp.com. +1. Log in to [play.battlesnake.com](https://play.battlesnake.com/login/). - **Description**
- Describe your Battlesnake for other Battlesnake Developers who might be interested. +2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). - **Tags**
- List any technologies you used to build your Battlesnake - probably `Heroku` and `Python`. + Give your Battlesnake a name, and complete the form using the URL for your Heroku app. - **Allow anyone to add your snake to a game?**
- Select this if you want to allow other Battlesnake Developers to enter this Battlesnake into their own games. +3. Once your Battlesnake has been created, you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. -3. Once your Battlesnake has been created, click [Create Game](https://play.battlesnake.com/account/games/create/) to start a new game with your new Battlesnake. Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game. + Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game running. 4. You should now see a brand new Battlesnake game with your Battlesnake in it! Yay! Press `Play` to start the game and watch how your Battlesnake does. -5. Repeat step 3 every time you want to start a new game and see how your snake behaves! +Repeat step 3 & 4 every time you want to start a new game and see how your snake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. + +By default, your Battlesnake will move randomly around the board. See server.py for details on how it achieves that. -6. If you open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running, you'll see your snake recieving API calls from the game engine and responding with its moves. +Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running to see your Battlesnake receiving API calls and responding with its moves. ```shell heroku logs --tail ``` **At this point you should have a registered Battlesnake and be able to create games!** + + ## Customizing Your Battlesnake -Now you're ready to start making your Battlesnake your own. By default, your Battlesnake won't be unique looking, nor very smart. Let's change that! +Now you're ready to start making your Battlesnake yours. ### Changing Appearance -When the game engine tells your Battlesnake that a new game is starting, you can optionally reply with what color you want to Battlesnake to be, and what you want your head and tail to look like. +When the game engine tells your Battlesnake that a new game is starting, you can optionally reply with information about how you want your Battlesnake to look. Locate the `start` function inside server.py. You should see a line that looks like this: ```python return {"color": "#888888", "headType": "regular", "tailType": "regular"} ``` -See the [Battlesnake Documentation - Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. +See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. ### Changing Behavior -On every turn of the game your Battlesnake receives information about the game board and has to respond with its next move. +On every turn of each game your Battlesnake receives information about the game board and has to respond with its next move. -Locate the `move` function inside server.py. You should see a line that looks like this: +Locate the `move` function inside server.py. You should see code that looks like this: ```python -return {"move": "up"} +data = cherrypy.request.json +# Choose a random direction to move in +possible_moves = ["up", "down", "left", "right"] +move = random.choice(possible_moves) +return {"move": move} ``` -Your Battlesnake can move one of four directions: "up", "down", "left", or "right". For now, choose a new direction to move in. +Your Battlesnake can move one of four directions: "up", "down", "left", or "right". By default your Battlesnake chooses a direction randomly. Your goal is to read board information from `data` and make an intelligent decision on where your Battlesnake should move next. -See the [Battlesnake Documentation - Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game and moving around the board. +See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game and moving around the board and developing your Battlesnake. ### Updating Your Battlesnake -After you've made your changes, commit them using git and deploy your changes to Heroku. +After making changes, commit them using git and deploy your changes to Heroku. ```shell git add . git commit -m "update my battlesnake's appearance" git push heroku master ``` -Once heroku has updated you can [start a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. +Once heroku has updated you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. **At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!** -## Developing Your Battlesnake -Now you have everything you need to start making your Battlesnake smarter. Here are a few helpful tips as you get going... -* Keeping your `heroku logs --tail` command always running in a second window is always helpful for watching activity and debugging any problems with your Battlesnake. +## Developing Your Battlesnake Further + +Now you have everything you need to start making your Battlesnake smarter. Here are a few more helpful tips... -* You can use the Python `print()` function to output information to your `heroku logs` stream. This is very useful for viewing what information is available in each command, and debugging any logic in your code during Battlesnake games. +* Keeping your logs open in a second window (using `heroku logs --tail`) is helpful for watching activity and debugging any problems with your Battlesnake. -* Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each comamnd. You can also output the data to your logs: +* You can use the Python [print()](https://docs.python.org/3.7/library/functions.html#print) function to output information to your server logs. This is very useful for viewing what information is available in each command, and debugging any logic in your code during Battlesnake games. + +* Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each command. You can also output the data to your logs: ```python def move(self): data = cherrypy.request.json @@ -141,10 +144,30 @@ Now you have everything you need to start making your Battlesnake smarter. Here * When viewing a Battlesnake game, you can pause playback and move forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. -Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Developers. + + +## Joining a Battlesnake Arena + +Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Battlesnakes. + +Arenas will regularly create new games and rank Battlesnakes based on their results. They're a good way to get regular feedback on how well your Battlesnake is performing, and a fun way to track your progress as you develop your algorithm. + + + +## (Optional) Running Your Battlesnake Locally + +Eventually you might want to run your Battlesnake server locally for faster debugging and code testing. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running `server.py` from the command line: + ```shell + python server.py + ``` + +**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install a tunnelling tool like [ngrok](https://ngrok.com/). + --- ### Questions? -You can join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake Developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) +All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. + +You can also join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake Developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) From 0106e6216b98ea623216d50df7165696eceef141 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 16 Mar 2020 14:28:56 -0700 Subject: [PATCH 050/117] More README.md updates. --- README.md | 67 +++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index e8548ed36..771fa15b1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api) that moves randomly around the board. It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), and you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), and you can use other cloud providers if you'd like. ### Technologies @@ -16,19 +16,19 @@ This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https:// ## Deploying Your First Battlesnake -1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your own GitHub Account. +1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your GitHub Account. -2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) to your local environment. +2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) into your local environment. ```shell git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-python.git ``` -3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps). +3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps) to run your Battlesnake. ```shell heroku create [YOUR-APP-NAME] ``` -4. [Deploy your code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code). +4. [Deploy your Battlesnake code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code). ```shell git push heroku master ``` @@ -37,16 +37,12 @@ This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https:// ```shell heroku open ``` - You should see the following text: + If everything was successful, you should see the following text: ``` Your Battlesnake is alive! ``` -Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval). -```shell -heroku logs --tail -``` -(the `--tail` option will show a live feed of your logs in real-time) +Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) `heroku logs --tail`. The `--tail` option will show a live feed of your logs in real-time. **At this point your Battlesnake is live and ready to enter games!** @@ -56,24 +52,15 @@ heroku logs --tail 1. Log in to [play.battlesnake.com](https://play.battlesnake.com/login/). -2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). - - Give your Battlesnake a name, and complete the form using the URL for your Heroku app. - -3. Once your Battlesnake has been created, you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. +2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a a name, and complete the form using the URL for your Heroku app. - Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game running. +3. Once your Battlesnake has been created, you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game. -4. You should now see a brand new Battlesnake game with your Battlesnake in it! Yay! Press `Play` to start the game and watch how your Battlesnake does. - -Repeat step 3 & 4 every time you want to start a new game and see how your snake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. - -By default, your Battlesnake will move randomly around the board. See server.py for details on how it achieves that. +4. You should now see a brand new Battlesnake game with your Battlesnake in it! Yay! Press `Play` to start the game and watch how your Battlesnake behaves. By default your Battlesnake should move randomly around the board. Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running to see your Battlesnake receiving API calls and responding with its moves. - ```shell - heroku logs --tail - ``` + +Repeat step 3 and 4 every time you want to create a new game to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. **At this point you should have a registered Battlesnake and be able to create games!** @@ -81,22 +68,20 @@ Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/loggin ## Customizing Your Battlesnake -Now you're ready to start making your Battlesnake yours. +Now you're ready to start customizing your Battlesnake and making it smarter. ### Changing Appearance -When the game engine tells your Battlesnake that a new game is starting, you can optionally reply with information about how you want your Battlesnake to look. - Locate the `start` function inside server.py. You should see a line that looks like this: ```python return {"color": "#888888", "headType": "regular", "tailType": "regular"} ``` -See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. +This function is called every time a new game starts. How your Battlesnake responds determines what it will look like in that game. See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. ### Changing Behavior -On every turn of each game your Battlesnake receives information about the game board and has to respond with its next move. +On every turn of each game your Battlesnake receives information about the game board. It then responds with its next move - one of "up", "down", "left", or "right". Locate the `move` function inside server.py. You should see code that looks like this: ```python @@ -107,9 +92,7 @@ move = random.choice(possible_moves) return {"move": move} ``` -Your Battlesnake can move one of four directions: "up", "down", "left", or "right". By default your Battlesnake chooses a direction randomly. Your goal is to read board information from `data` and make an intelligent decision on where your Battlesnake should move next. - -See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game and moving around the board and developing your Battlesnake. +To start your Battlesnake will choose a direction randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game, moving around the board, and developing your Battlesnake algorithm. ### Updating Your Battlesnake @@ -128,11 +111,11 @@ Once heroku has updated you can [create a new game](https://play.battlesnake.com ## Developing Your Battlesnake Further -Now you have everything you need to start making your Battlesnake smarter. Here are a few more helpful tips... +Now you have everything you need to start making your Battlesnake super smart! Here are a few more helpful tips: -* Keeping your logs open in a second window (using `heroku logs --tail`) is helpful for watching activity and debugging any problems with your Battlesnake. +* Keeping your logs open in a second window (using `heroku logs --tail`) is helpful for watching server activity and debugging any problems with your Battlesnake. -* You can use the Python [print()](https://docs.python.org/3.7/library/functions.html#print) function to output information to your server logs. This is very useful for viewing what information is available in each command, and debugging any logic in your code during Battlesnake games. +* You can use the Python [print()](https://docs.python.org/3.7/library/functions.html#print) function to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. * Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each command. You can also output the data to your logs: ```python @@ -142,13 +125,13 @@ Now you have everything you need to start making your Battlesnake smarter. Here return {"move": "up"} ``` -* When viewing a Battlesnake game, you can pause playback and move forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. +* When viewing a Battlesnake game you can pause playback and step forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. ## Joining a Battlesnake Arena -Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Battlesnakes. +Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Battlesnakes worldwide. Arenas will regularly create new games and rank Battlesnakes based on their results. They're a good way to get regular feedback on how well your Battlesnake is performing, and a fun way to track your progress as you develop your algorithm. @@ -156,18 +139,20 @@ Arenas will regularly create new games and rank Battlesnakes based on their resu ## (Optional) Running Your Battlesnake Locally -Eventually you might want to run your Battlesnake server locally for faster debugging and code testing. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running `server.py` from the command line: +Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running: + ```shell python server.py ``` -**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install a tunnelling tool like [ngrok](https://ngrok.com/). +**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install a tunneling tool like [ngrok](https://ngrok.com/). --- + ### Questions? All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. -You can also join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake Developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) +You can also join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) From 30100edd84b40294912df2469dbd7393b8ca9404 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 16 Mar 2020 14:38:19 -0700 Subject: [PATCH 051/117] Update README.md --- README.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 771fa15b1..e9de1c328 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), and you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), although you can use other cloud providers if you'd like. ### Technologies @@ -42,7 +42,7 @@ This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https:// Your Battlesnake is alive! ``` -Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) `heroku logs --tail`. The `--tail` option will show a live feed of your logs in real-time. +6. Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) `heroku logs --tail`. The `--tail` option will show a live feed of your logs in real-time. **At this point your Battlesnake is live and ready to enter games!** @@ -52,15 +52,15 @@ Optionally, you can view your server logs using the [Heroku logs command](https: 1. Log in to [play.battlesnake.com](https://play.battlesnake.com/login/). -2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a a name, and complete the form using the URL for your Heroku app. +2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a name and complete the form using the URL for your Heroku app. -3. Once your Battlesnake has been created, you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. Type your Battlesnake's name into the search field and click 'Add' to add it to the game. Then click 'Create Game' to start the game. +3. Once your Battlesnake has been saved you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. Type your Battlesnake's name into the search field and click "Add" to add it to the game. Then click "Create Game" to start the game. -4. You should now see a brand new Battlesnake game with your Battlesnake in it! Yay! Press `Play` to start the game and watch how your Battlesnake behaves. By default your Battlesnake should move randomly around the board. +4. You should see a brand new Battlesnake game with your Battlesnake in it! Yay! Press "Play" to start the game and watch how your Battlesnake behaves. By default your Battlesnake should move randomly around the board. -Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running to see your Battlesnake receiving API calls and responding with its moves. +5. Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running to see your Battlesnake receiving API calls and responding with its moves. -Repeat step 3 and 4 every time you want to create a new game to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. +Repeat steps 3 and 4 every time you want to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. **At this point you should have a registered Battlesnake and be able to create games!** @@ -68,7 +68,7 @@ Repeat step 3 and 4 every time you want to create a new game to see how your Bat ## Customizing Your Battlesnake -Now you're ready to start customizing your Battlesnake and making it smarter. +Now you're ready to start customizing your Battlesnake and improving its algorithm. ### Changing Appearance @@ -77,11 +77,11 @@ Locate the `start` function inside server.py. You should see a line that looks l return {"color": "#888888", "headType": "regular", "tailType": "regular"} ``` -This function is called every time a new game starts. How your Battlesnake responds determines what it will look like in that game. See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. +This function is called every time a new game starts. Your response determines what your Battlesnake will look like in that game. See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. ### Changing Behavior -On every turn of each game your Battlesnake receives information about the game board. It then responds with its next move - one of "up", "down", "left", or "right". +On every turn of each game your Battlesnake receives information about the game board and must decide its next move. Locate the `move` function inside server.py. You should see code that looks like this: ```python @@ -92,7 +92,9 @@ move = random.choice(possible_moves) return {"move": move} ``` -To start your Battlesnake will choose a direction randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game, moving around the board, and developing your Battlesnake algorithm. +Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. + +See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game, moving around the board, and improving your algorithm. ### Updating Your Battlesnake @@ -103,7 +105,7 @@ git commit -m "update my battlesnake's appearance" git push heroku master ``` -Once heroku has updated you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. +Once Heroku has updated you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. **At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!** @@ -115,7 +117,7 @@ Now you have everything you need to start making your Battlesnake super smart! H * Keeping your logs open in a second window (using `heroku logs --tail`) is helpful for watching server activity and debugging any problems with your Battlesnake. -* You can use the Python [print()](https://docs.python.org/3.7/library/functions.html#print) function to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. +* You can use the Python [print function](https://docs.python.org/3.7/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. * Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each command. You can also output the data to your logs: ```python @@ -141,11 +143,11 @@ Arenas will regularly create new games and rank Battlesnakes based on their resu Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running: - ```shell - python server.py - ``` +```shell +python server.py +``` -**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install a tunneling tool like [ngrok](https://ngrok.com/). +**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install and use a port forwarding tool like [ngrok](https://ngrok.com/). --- From 6e3527b1bc80a06ba25446c4bee458e52cac9c30 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 16 Mar 2020 14:55:28 -0700 Subject: [PATCH 052/117] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e9de1c328..7b50178eb 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Now you're ready to start customizing your Battlesnake and improving its algorit ### Changing Appearance -Locate the `start` function inside server.py. You should see a line that looks like this: +Locate the `start` function inside [server.py](server.py#L26). You should see a line that looks like this: ```python return {"color": "#888888", "headType": "regular", "tailType": "regular"} ``` @@ -83,7 +83,7 @@ This function is called every time a new game starts. Your response determines w On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `move` function inside server.py. You should see code that looks like this: +Locate the `move` function inside [server.py](server.py#L37). You should see code that looks like this: ```python data = cherrypy.request.json # Choose a random direction to move in From 7fa6df01d5e7a6b4191f44dcca6d41ac31c9be5e Mon Sep 17 00:00:00 2001 From: Brandon Brown Date: Mon, 6 Apr 2020 10:57:43 -0700 Subject: [PATCH 053/117] Removes the app.json, nolonger used (#20) --- app.json | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 app.json diff --git a/app.json b/app.json deleted file mode 100644 index 72af990a8..000000000 --- a/app.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Python Starter Snake", - "description": "A simple Battlesnake written in Python.", - "repository": "https://github.com/BattlesnakeOfficial/starter-snake-python", - "website": "https://play.battlesnake.com", - "keywords": [ - "battlesnake" - ] -} From 3768c9cd97b0f675c29bbd1318e213bad9bf7117 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 18 May 2020 16:50:56 -0700 Subject: [PATCH 054/117] Update for API Version 1 --- server.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/server.py b/server.py index ebc33862b..18c8aed91 100644 --- a/server.py +++ b/server.py @@ -11,29 +11,33 @@ class Battlesnake(object): @cherrypy.expose + @cherrypy.tools.json_out def index(self): - # If you open your snake URL in a browser you should see this message. - return "Your Battlesnake is alive!" + # This function is called when you register your Battlesnake on play.battlesnake.com + # It controls your Battlesnake appearance and author permissions. + # TIP: If you open your Battlesnake URL in browser you should see this data + return { + "apiversion": "1", + "author": "", # TODO: Your Battlesnake Username + "color": "#399AF2", # TODO: Personalize + "head": "tongue", # TODO: Personalize + "tail": "curled", # TODO: Personalize + } @cherrypy.expose - def ping(self): - # The Battlesnake engine calls this function to make sure your snake is working. - return "pong" - - @cherrypy.expose - @cherrypy.tools.json_in() - @cherrypy.tools.json_out() + @cherrypy.tools.json_in def start(self): # This function is called everytime your snake is entered into a game. # cherrypy.request.json contains information about the game that's about to be played. # TODO: Use this function to decide how your snake is going to look on the board. data = cherrypy.request.json + print("START") - return {"color": "#888888", "headType": "regular", "tailType": "regular"} + return "ok" @cherrypy.expose - @cherrypy.tools.json_in() - @cherrypy.tools.json_out() + @cherrypy.tools.json_in + @cherrypy.tools.json_out def move(self): # This function is called on every turn of a game. It's how your snake decides where to move. # Valid moves are "up", "down", "left", or "right". @@ -48,11 +52,12 @@ def move(self): return {"move": move} @cherrypy.expose - @cherrypy.tools.json_in() + @cherrypy.tools.json_in def end(self): # This function is called when a game your snake was in ends. # It's purely for informational purposes, you don't have to make any decisions here. data = cherrypy.request.json + print("END") return "ok" From 57ae06e353ca74bac7ad643bbcd044e970f844db Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 18 May 2020 16:52:30 -0700 Subject: [PATCH 055/117] Reinstate decorator calls. --- server.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 18c8aed91..ae1e25cd9 100644 --- a/server.py +++ b/server.py @@ -11,7 +11,7 @@ class Battlesnake(object): @cherrypy.expose - @cherrypy.tools.json_out + @cherrypy.tools.json_out() def index(self): # This function is called when you register your Battlesnake on play.battlesnake.com # It controls your Battlesnake appearance and author permissions. @@ -25,7 +25,7 @@ def index(self): } @cherrypy.expose - @cherrypy.tools.json_in + @cherrypy.tools.json_in() def start(self): # This function is called everytime your snake is entered into a game. # cherrypy.request.json contains information about the game that's about to be played. @@ -36,8 +36,8 @@ def start(self): return "ok" @cherrypy.expose - @cherrypy.tools.json_in - @cherrypy.tools.json_out + @cherrypy.tools.json_in() + @cherrypy.tools.json_out() def move(self): # This function is called on every turn of a game. It's how your snake decides where to move. # Valid moves are "up", "down", "left", or "right". @@ -52,7 +52,7 @@ def move(self): return {"move": move} @cherrypy.expose - @cherrypy.tools.json_in + @cherrypy.tools.json_in() def end(self): # This function is called when a game your snake was in ends. # It's purely for informational purposes, you don't have to make any decisions here. From 1f59323f79784f47ca84ce704f75dd04e962a392 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 18 May 2020 16:54:31 -0700 Subject: [PATCH 056/117] Reinstate default personalization. --- server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index ae1e25cd9..11fe2b8b2 100644 --- a/server.py +++ b/server.py @@ -19,9 +19,9 @@ def index(self): return { "apiversion": "1", "author": "", # TODO: Your Battlesnake Username - "color": "#399AF2", # TODO: Personalize - "head": "tongue", # TODO: Personalize - "tail": "curled", # TODO: Personalize + "color": "#888888", # TODO: Personalize + "head": "default", # TODO: Personalize + "tail": "default", # TODO: Personalize } @cherrypy.expose From 40ad6ca5e464efb9a32bb9f03a1b04f374d11f81 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 18 May 2020 17:00:45 -0700 Subject: [PATCH 057/117] Update README for API Version 1. --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7b50178eb..c7d5e450e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/snake-api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), although you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), although you can use other cloud providers if you'd like. ### Technologies @@ -39,7 +39,7 @@ This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https:// ``` If everything was successful, you should see the following text: ``` - Your Battlesnake is alive! + {"apiversion": "1", "author": "", "color": "#888888", "head": "default", "tail": "default"} ``` 6. Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) `heroku logs --tail`. The `--tail` option will show a live feed of your logs in real-time. @@ -72,12 +72,18 @@ Now you're ready to start customizing your Battlesnake and improving its algorit ### Changing Appearance -Locate the `start` function inside [server.py](server.py#L26). You should see a line that looks like this: +Locate the `index` function inside [server.py](server.py#L15). You should see a line that looks like this: ```python -return {"color": "#888888", "headType": "regular", "tailType": "regular"} +return { + "apiversion": "1", + "author": "", + "color": "#888888", + "head": "default", + "tail": "default", +} ``` -This function is called every time a new game starts. Your response determines what your Battlesnake will look like in that game. See [Customizing Your Battlesnake](https://docs.battlesnake.com/snake-customization) for how to customize your Battlesnake's appearance using these values. +This function is called by the game engine to make sure your Battlesnake is healthy and responding correctly. Your response determines what your Battlesnake will look like in that game. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. ### Changing Behavior @@ -92,9 +98,9 @@ move = random.choice(possible_moves) return {"move": move} ``` -Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. +Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. -See the [Battlesnake Rules](https://docs.battlesnake.com/rules) for more information on playing the game, moving around the board, and improving your algorithm. +See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. ### Updating Your Battlesnake @@ -119,7 +125,7 @@ Now you have everything you need to start making your Battlesnake super smart! H * You can use the Python [print function](https://docs.python.org/3.7/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. -* Review the [Battlesnake API Docs](https://docs.battlesnake.com/snake-api) to learn what information is provided with each command. You can also output the data to your logs: +* Review the [Battlesnake API Docs](https://docs.battlesnake.com/references/api) to learn what information is provided with each command. You can also output the data to your logs: ```python def move(self): data = cherrypy.request.json From 0db9c1f02bbb4218f71fcffa0fe3809cdd3c1a61 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Tue, 19 May 2020 17:19:26 -0700 Subject: [PATCH 058/117] Update README.md --- README.md | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c7d5e450e..b139c0d35 100644 --- a/README.md +++ b/README.md @@ -89,16 +89,7 @@ This function is called by the game engine to make sure your Battlesnake is heal On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `move` function inside [server.py](server.py#L37). You should see code that looks like this: -```python -data = cherrypy.request.json -# Choose a random direction to move in -possible_moves = ["up", "down", "left", "right"] -move = random.choice(possible_moves) -return {"move": move} -``` - -Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. +Locate the `move` function inside [server.py](server.py#L37). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. @@ -125,13 +116,7 @@ Now you have everything you need to start making your Battlesnake super smart! H * You can use the Python [print function](https://docs.python.org/3.7/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. -* Review the [Battlesnake API Docs](https://docs.battlesnake.com/references/api) to learn what information is provided with each command. You can also output the data to your logs: - ```python - def move(self): - data = cherrypy.request.json - print(data) - return {"move": "up"} - ``` +* Review the [Battlesnake API Docs](https://docs.battlesnake.com/references/api) to learn what information is provided with each command. * When viewing a Battlesnake game you can pause playback and step forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. From a9c8e6edb816849d85756016cc4766425bb2ab87 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 10:33:00 -0700 Subject: [PATCH 059/117] Add repl.it support. Bump to Python 3.8. --- .replit | 2 + poetry.lock | 161 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 9 +++ runtime.txt | 2 +- 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 .replit create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/.replit b/.replit new file mode 100644 index 000000000..890feba18 --- /dev/null +++ b/.replit @@ -0,0 +1,2 @@ +language = "python3" +run = "python server.py" diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 000000000..db11ed754 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,161 @@ +[[package]] +category = "main" +description = "Highly-optimized, pure-python HTTP server" +name = "cheroot" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +version = "8.3.0" + +[package.dependencies] +"jaraco.functools" = "*" +more-itertools = ">=2.6" +six = ">=1.11.0" + +[[package]] +category = "main" +description = "Object-Oriented HTTP framework" +name = "cherrypy" +optional = false +python-versions = ">=3.5" +version = "18.6.0" + +[package.dependencies] +cheroot = ">=8.2.1" +"jaraco.collections" = "*" +more-itertools = "*" +portend = ">=2.1.1" +pywin32 = "*" +"zc.lockfile" = "*" + +[[package]] +category = "main" +description = "Utility functions for Python class constructs" +name = "jaraco.classes" +optional = false +python-versions = ">=3.6" +version = "3.1.0" + +[package.dependencies] +more-itertools = "*" + +[[package]] +category = "main" +description = "Collection objects similar to those in stdlib by jaraco" +name = "jaraco.collections" +optional = false +python-versions = ">=3.6" +version = "3.0.0" + +[package.dependencies] +"jaraco.classes" = "*" +"jaraco.text" = "*" +six = ">=1.7.0" + +[[package]] +category = "main" +description = "Functools like those found in stdlib" +name = "jaraco.functools" +optional = false +python-versions = ">=3.6" +version = "3.0.1" + +[package.dependencies] +more-itertools = "*" + +[[package]] +category = "main" +description = "Module for text manipulation" +name = "jaraco.text" +optional = false +python-versions = ">=2.7" +version = "3.2.0" + +[package.dependencies] +"jaraco.functools" = "*" +six = "*" + +[[package]] +category = "main" +description = "More routines for operating on iterables, beyond itertools" +name = "more-itertools" +optional = false +python-versions = ">=3.5" +version = "8.3.0" + +[[package]] +category = "main" +description = "TCP port monitoring and discovery" +name = "portend" +optional = false +python-versions = ">=2.7" +version = "2.6" + +[package.dependencies] +tempora = ">=1.8" + +[[package]] +category = "main" +description = "World timezone definitions, modern and historical" +name = "pytz" +optional = false +python-versions = "*" +version = "2020.1" + +[[package]] +category = "main" +description = "Python for Window Extensions" +marker = "sys_platform == \"win32\"" +name = "pywin32" +optional = false +python-versions = "*" +version = "227" + +[[package]] +category = "main" +description = "Python 2 and 3 compatibility utilities" +name = "six" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +version = "1.15.0" + +[[package]] +category = "main" +description = "Objects and routines pertaining to date and time (tempora)" +name = "tempora" +optional = false +python-versions = ">=3.6" +version = "3.0.0" + +[package.dependencies] +"jaraco.functools" = ">=1.20" +pytz = "*" + +[[package]] +category = "main" +description = "Basic inter-process locks" +name = "zc.lockfile" +optional = false +python-versions = "*" +version = "2.0" + +[package.dependencies] +setuptools = "*" + +[metadata] +content-hash = "4525054609701dd3baffd13f86cbea41801fb80b658a5de84dcccb8eaee13401" +python-versions = "^3.8" + +[metadata.hashes] +cheroot = ["2b48c88959b5b80a79aca627ae5212acb398becaa70b576b8b89bec1ad0d1367", "a0577e1f28661727d472671a7cc4e0c12ea0cbc5220265e70f00a8b8cb628931"] +cherrypy = ["56608edd831ad00991ae585625e0206ed61cf1a0850e4b2cc48489fb2308c499", "c0a7283f02a384c112a0a18404fd3abd849fc7fd4bec19378067150a2573d2e4"] +"jaraco.classes" = ["116429c2047953f525afdcae165475c4589c7b14870e78b2d068ecb01018827e", "c38698ff8ef932eb33d91c0e8fc192ad7c44ecee03f7f585afd4f35aeaef7aab"] +"jaraco.collections" = ["a7889f28c80c4875bd6256d9924e8526dacfef22cd7b80ff8469b4d312f9f144", "be570ef4f2e7290b757449395238fa63d70a9255574624e73c5ff9f1ee554721"] +"jaraco.functools" = ["9fedc4be3117512ca3e03e1b2ffa7a6a6ffa589bfb7d02bfb324e55d493b94f4", "d3dc9f6c1a1d45d7f59682a3bf77aceb685c1a60891606c7e4161e72ecc399ad"] +"jaraco.text" = ["c87569c9afae14f71b2e1c57f316770ab6981ab675d9c602be1c7981161bacdd", "e5078b1126cc0f166c7859aa75103a56c0d0f39ebcafc21695615472e0f810ec"] +more-itertools = ["558bb897a2232f5e4f8e2399089e35aecb746e1f9191b6584a151647e89267be", "7818f596b1e87be009031c7653d01acc46ed422e6656b394b0f765ce66ed4982"] +portend = ["600dd54175e17e9347e5f3d4217aa8bcf4bf4fa5ffbc4df034e5ec1ba7cdaff5", "62dd00b94a6a55fbf0320365fbdeba37f0d1fe14d613841037dc4780bedfda8f"] +pytz = ["a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed", "c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"] +pywin32 = ["300a2db938e98c3e7e2093e4491439e62287d0d493fe07cce110db070b54c0be", "31f88a89139cb2adc40f8f0e65ee56a8c585f629974f9e07622ba80199057511", "371fcc39416d736401f0274dd64c2302728c9e034808e37381b5e1b22be4a6b0", "47a3c7551376a865dd8d095a98deba954a98f326c6fe3c72d8726ca6e6b15507", "4cdad3e84191194ea6d0dd1b1b9bdda574ff563177d2adf2b4efec2a244fa116", "7c1ae32c489dc012930787f06244426f8356e129184a02c25aef163917ce158e", "7f18199fbf29ca99dff10e1f09451582ae9e372a892ff03a28528a24d55875bc", "9b31e009564fb95db160f154e2aa195ed66bcc4c058ed72850d047141b36f3a2", "a929a4af626e530383a579431b70e512e736e9588106715215bf685a3ea508d4", "c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295", "f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c", "f4c5be1a293bae0076d93c88f37ee8da68136744588bc5e2be2f299a34ceb7aa"] +six = ["30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"] +tempora = ["70503a3a10fb341f49e7919d193f0b6362bbfddffb560fac47df3e977414c0c6", "e370d822cf48f5356aab0734ea45807250f5120e291c76712a1d766b49ae34f8"] +"zc.lockfile" = ["307ad78227e48be260e64896ec8886edc7eae22d8ec53e4d528ab5537a83203b", "cc33599b549f0c8a248cb72f3bf32d77712de1ff7ee8814312eb6456b42c015f"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..09a8515ec --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[tool.poetry] +name = "starter-snake-python" +version = "1.0.0" +description = "A simple Battlesnake written in Python" +authors = ["Battlesnake Developers "] + +[tool.poetry.dependencies] +python = "^3.8" +cherrypy = "^18.6" diff --git a/runtime.txt b/runtime.txt index 6919bf9ed..385705b56 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.7.6 +python-3.8.3 From ac47c37dc107f0eb57fa7cb59a374cca414f732a Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 12:38:32 -0700 Subject: [PATCH 060/117] Update README. --- README.md | 101 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index b139c0d35..9b101b05a 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,71 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to deploy to [Heroku](https://heroku.com), although you can use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it), or even deploy to [Heroku](https://heroku.com). You can also use other cloud providers if you'd like. -### Technologies +### Technologies Used -This Battlesnake uses [Python 3.7](https://www.python.org/), [CherryPy](https://cherrypy.org/), and [Heroku](https://heroku.com). +* [Python3](https://www.python.org/) +* [CherryPy](https://cherrypy.org/) -### Prerequisites +# Programming your first Battlesnake using [Repl.it](https://repl.it) + + + +## Prerequisites -* [GitHub Account](https://github.com/) and [Git Command Line](https://www.atlassian.com/git/tutorials/install-git) -* [Heroku Account](https://signup.heroku.com/) and [Heroku Command Line](https://devcenter.heroku.com/categories/command-line) * [Battlesnake Account](https://play.battlesnake.com) +* [Repl.it Account](https://repl.it) +* [GitHub Account](https://github.com) (Optional) +## Running your code on [Repl.it](https://repl.it) +1. Login to your [Repl.it](https://repl.it) account. -## Deploying Your First Battlesnake +2. Create a new Repl and select `Import From GitHub`. -1. [Fork this repo](https://github.com/BattlesnakeOfficial/starter-snake-python/fork) into your GitHub Account. +3. Paste the URL for this GitHub repo into the text field. -2. [Clone your forked repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) into your local environment. - ```shell - git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-python.git ``` - -3. [Create a new Heroku app](https://devcenter.heroku.com/articles/creating-apps) to run your Battlesnake. - ```shell - heroku create [YOUR-APP-NAME] + https://github.com/BattlesnakeOfficial/starter-snake-python ``` -4. [Deploy your Battlesnake code to Heroku](https://devcenter.heroku.com/articles/git#deploying-code). - ```shell - git push heroku master - ``` +4. Click Import from GitHub to finish creating your new Repl. You should see your new Repl being created - this might take a few moments to complete. + +4. Once your Repl is ready to run, click `run ▶️` at the top of the screen. You should see CherryPy and any other dependencies being installed. Once installation is complete, your server will start: -5. Open your new Heroku app in your browser. - ```shell - heroku open ``` - If everything was successful, you should see the following text: + Starting Battlesnake Server... + ENGINE Serving on http://0.0.0.0:8080 + ``` + +5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. + + You should see output similar to this: + ``` {"apiversion": "1", "author": "", "color": "#888888", "head": "default", "tail": "default"} ``` -6. Optionally, you can view your server logs using the [Heroku logs command](https://devcenter.heroku.com/articles/logging#log-retrieval) `heroku logs --tail`. The `--tail` option will show a live feed of your logs in real-time. - **At this point your Battlesnake is live and ready to enter games!** -## Registering Your Battlesnake and Creating Your First Game +## Registering your Battlesnake and creating your first game -1. Log in to [play.battlesnake.com](https://play.battlesnake.com/login/). +1. Sign in to [play.battlesnake.com](https://play.battlesnake.com/login/). -2. [Create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a name and complete the form using the URL for your Heroku app. +2. Go [here to create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a meaningful name and complete the form using the URL for your Repl from above. 3. Once your Battlesnake has been saved you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. Type your Battlesnake's name into the search field and click "Add" to add it to the game. Then click "Create Game" to start the game. 4. You should see a brand new Battlesnake game with your Battlesnake in it! Yay! Press "Play" to start the game and watch how your Battlesnake behaves. By default your Battlesnake should move randomly around the board. -5. Optionally, open your [Heroku logs](https://devcenter.heroku.com/articles/logging#log-retrieval) while the game is running to see your Battlesnake receiving API calls and responding with its moves. +5. Optionally, watch your Repl logs while the game is running to see your Battlesnake receiving API calls and responding with its moves. Repeat steps 3 and 4 every time you want to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. +You can also use the "Create Rematch" button to quickly start a new game using the same Battlesnakes and configuration. + **At this point you should have a registered Battlesnake and be able to create games!** @@ -83,7 +87,9 @@ return { } ``` -This function is called by the game engine to make sure your Battlesnake is healthy and responding correctly. Your response determines what your Battlesnake will look like in that game. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. +This function is called by the game engine to make sure your Battlesnake is healthy and responding correctly. Your response determines what your Battlesnake will look like on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. + +Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration. ### Changing Behavior @@ -95,24 +101,31 @@ See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) ### Updating Your Battlesnake -After making changes, commit them using git and deploy your changes to Heroku. -```shell -git add . -git commit -m "update my battlesnake's appearance" -git push heroku master -``` +After making changes to your Battlesnake, you can stop and restart your Repl to have the change take effect. -Once Heroku has updated you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to view your latest changes in action. +Once the Repl has restarted, you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to watch your latest changes in action. -**At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!** +**At this point you should feel comfortable making changes to your code and starting new Battlesnake games to test those changes!** ## Developing Your Battlesnake Further -Now you have everything you need to start making your Battlesnake super smart! Here are a few more helpful tips: +Now you have everything you need to start making your Battlesnake super smart! + +### Early Development Goals + +[ ] Avoid colliding with yourself +[ ] Avoid colliding with walls +[ ] Avoid colliding with other snakes +[ ] Try to move towards food + +Once you have completed those steps, you'll be ready to compete live against other Battlesnakes, and start implementing more complex strategies to surive. + -* Keeping your logs open in a second window (using `heroku logs --tail`) is helpful for watching server activity and debugging any problems with your Battlesnake. +### Helpful Tips + +* Keeping your Repl open in a second window while games are running is helpful for watching server activity and debugging any problems with your Battlesnake. * You can use the Python [print function](https://docs.python.org/3.7/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. @@ -130,6 +143,14 @@ Arenas will regularly create new games and rank Battlesnakes based on their resu +## (Optioanl) Using a Cloud Provider + +As your Battlesnake gets more complex, it might make sense to move it to a dedicated hosting provider such as Heroku or AWS. We suggest choosing a platform you're familiar with, or one you'd be interested in learning more about. + +If you have questions or ideas, our developer community on [Slack](https://play.battlesnake.com/slack) and [Discord](https://play.battlesnake.com/discord) will be able to help out. + + + ## (Optional) Running Your Battlesnake Locally Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running: From 96e67365ea3c946356be9e5a721fd7c5e7917e29 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 16:05:00 -0700 Subject: [PATCH 061/117] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9b101b05a..8da2d265f 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) ### Updating Your Battlesnake -After making changes to your Battlesnake, you can stop and restart your Repl to have the change take effect. +After making changes to your Battlesnake, you can stop and restart your Repl to have the change take effect (or in many cases your Repl will restart automatically). Once the Repl has restarted, you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to watch your latest changes in action. @@ -115,10 +115,10 @@ Now you have everything you need to start making your Battlesnake super smart! ### Early Development Goals -[ ] Avoid colliding with yourself -[ ] Avoid colliding with walls -[ ] Avoid colliding with other snakes -[ ] Try to move towards food +- [ ] Avoid colliding with yourself +- [ ] Avoid colliding with walls +- [ ] Try to move towards food +- [ ] Avoid colliding with other snakes Once you have completed those steps, you'll be ready to compete live against other Battlesnakes, and start implementing more complex strategies to surive. @@ -143,7 +143,7 @@ Arenas will regularly create new games and rank Battlesnakes based on their resu -## (Optioanl) Using a Cloud Provider +## (Optional) Using a Cloud Provider As your Battlesnake gets more complex, it might make sense to move it to a dedicated hosting provider such as Heroku or AWS. We suggest choosing a platform you're familiar with, or one you'd be interested in learning more about. From 949f97b51c6eaa88b365efa9c0960d9921683efa Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 16:16:54 -0700 Subject: [PATCH 062/117] Update README.md --- README.md | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8da2d265f..2c8cd4ec6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake * [Repl.it Account](https://repl.it) * [GitHub Account](https://github.com) (Optional) -## Running your code on [Repl.it](https://repl.it) +## Running your Battlesnake on [Repl.it](https://repl.it) 1. Login to your [Repl.it](https://repl.it) account. @@ -29,23 +29,23 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake https://github.com/BattlesnakeOfficial/starter-snake-python ``` -4. Click Import from GitHub to finish creating your new Repl. You should see your new Repl being created - this might take a few moments to complete. +4. Click "Import from GitHub" to finish creating your new Repl. You should see your Repl being initialized - this might take a few moments to complete. -4. Once your Repl is ready to run, click `run ▶️` at the top of the screen. You should see CherryPy and any other dependencies being installed. Once installation is complete, your server will start: +4. Once your Repl is ready to run, click `Run ▶️` at the top of the screen. You should see CherryPy (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following: ``` Starting Battlesnake Server... ENGINE Serving on http://0.0.0.0:8080 ``` -5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. - - You should see output similar to this: +5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. If you visit that URL in your browser, you should see text similar to this: ``` {"apiversion": "1", "author": "", "color": "#888888", "head": "default", "tail": "default"} ``` +This means your Battlesnake is running correctly on Repl.it. + **At this point your Battlesnake is live and ready to enter games!** @@ -62,9 +62,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake 5. Optionally, watch your Repl logs while the game is running to see your Battlesnake receiving API calls and responding with its moves. -Repeat steps 3 and 4 every time you want to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. - -You can also use the "Create Rematch" button to quickly start a new game using the same Battlesnakes and configuration. +Repeat steps 3 and 4 every time you want to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. You can also use the "Create Rematch" button to quickly start a new game using the same Battlesnakes and configuration. **At this point you should have a registered Battlesnake and be able to create games!** @@ -72,11 +70,12 @@ You can also use the "Create Rematch" button to quickly start a new game using t ## Customizing Your Battlesnake -Now you're ready to start customizing your Battlesnake and improving its algorithm. +Now you're ready to start customizing your Battlesnake's appearance and behavior. ### Changing Appearance -Locate the `index` function inside [server.py](server.py#L15). You should see a line that looks like this: +Locate the `index` function inside [server.py](server.py#L15). At the end of that function tou should see a line that looks like this: + ```python return { "apiversion": "1", @@ -87,23 +86,23 @@ return { } ``` -This function is called by the game engine to make sure your Battlesnake is healthy and responding correctly. Your response determines what your Battlesnake will look like on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. +This function is called by the game engine periodically to make sure your Battlesnake is healthy, responding correctly, and to determine how your Battlesnake will appear \on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. -Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration. +Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration and those changes should be reflected in the UI as well as any new games created. ### Changing Behavior On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `move` function inside [server.py](server.py#L37). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and make an intelligent decision about where your Battlesnake should move next. +Locate the `move` function inside [server.py](server.py#L37). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. ### Updating Your Battlesnake -After making changes to your Battlesnake, you can stop and restart your Repl to have the change take effect (or in many cases your Repl will restart automatically). +After making changes to your Battlesnake, you can restart your Repl to have the change take effect (or in many cases your Repl will restart automatically). -Once the Repl has restarted, you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to watch your latest changes in action. +Once the Repl has restarted you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to watch your latest changes in action. **At this point you should feel comfortable making changes to your code and starting new Battlesnake games to test those changes!** @@ -115,19 +114,21 @@ Now you have everything you need to start making your Battlesnake super smart! ### Early Development Goals +Here are some simple goals to help you develop your Battlesnake early on. Completing these will make your Battlesnake competitive against other Battlesnakes in multi-player games. + - [ ] Avoid colliding with yourself - [ ] Avoid colliding with walls - [ ] Try to move towards food - [ ] Avoid colliding with other snakes -Once you have completed those steps, you'll be ready to compete live against other Battlesnakes, and start implementing more complex strategies to surive. +Once you have completed these steps you'll be ready to compete live against other Battlesnakes and start exploring and implementing more complex strategies. ### Helpful Tips * Keeping your Repl open in a second window while games are running is helpful for watching server activity and debugging any problems with your Battlesnake. -* You can use the Python [print function](https://docs.python.org/3.7/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. +* You can use the Python [print function](https://docs.python.org/3.8/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. * Review the [Battlesnake API Docs](https://docs.battlesnake.com/references/api) to learn what information is provided with each command. @@ -153,7 +154,7 @@ If you have questions or ideas, our developer community on [Slack](https://play. ## (Optional) Running Your Battlesnake Locally -Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.7](https://www.python.org/downloads/) and running: +Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.8](https://www.python.org/downloads/) and running: ```shell python server.py @@ -169,4 +170,4 @@ python server.py All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. -You can also join the [Battlesnake Developer Community on Slack](https://play.battlesnake.com/slack). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) +You can also join the Battlesnake Developer Community on [Slack](https://play.battlesnake.com/slack) and [Discord](https://play.battlesnake.com/discord). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) From 6f443190681f2b895075ddc57a38f087c9768ef5 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 16:23:12 -0700 Subject: [PATCH 063/117] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 2c8cd4ec6..9a373645c 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ # A simple [Battlesnake](http://play.battlesnake.com) written in Python. -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it), or even deploy to [Heroku](https://heroku.com). You can also use other cloud providers if you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started. It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. ### Technologies Used * [Python3](https://www.python.org/) * [CherryPy](https://cherrypy.org/) -# Programming your first Battlesnake using [Repl.it](https://repl.it) - - ## Prerequisites From 5b80e14b367212ac431008cdbc9e8982f521d81f Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 16:24:37 -0700 Subject: [PATCH 064/117] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a373645c..fb97fce00 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake * [Repl.it Account](https://repl.it) * [GitHub Account](https://github.com) (Optional) -## Running your Battlesnake on [Repl.it](https://repl.it) +## Running Your Battlesnake on [Repl.it](https://repl.it) 1. Login to your [Repl.it](https://repl.it) account. @@ -47,7 +47,7 @@ This means your Battlesnake is running correctly on Repl.it. -## Registering your Battlesnake and creating your first game +## Registering Your Battlesnake and Creating Your First Game 1. Sign in to [play.battlesnake.com](https://play.battlesnake.com/login/). From e97e732df5a0bf6e45c3ad50db40a89313d27836 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 11 Jun 2020 16:26:22 -0700 Subject: [PATCH 065/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb97fce00..95810fca7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# A simple [Battlesnake](http://play.battlesnake.com) written in Python. +# A Simple [Battlesnake](http://play.battlesnake.com) Written in Python This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started. It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. From c75c1e3363b215328118c3870222430087786b19 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 12 Jun 2020 15:24:23 -0700 Subject: [PATCH 066/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95810fca7..d06abd6c6 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ Now you have everything you need to start making your Battlesnake super smart! Here are some simple goals to help you develop your Battlesnake early on. Completing these will make your Battlesnake competitive against other Battlesnakes in multi-player games. -- [ ] Avoid colliding with yourself - [ ] Avoid colliding with walls +- [ ] Avoid colliding with yourself - [ ] Try to move towards food - [ ] Avoid colliding with other snakes From 2a59a3ee3faded555cbde03996523cf0e26742bc Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 12 Jun 2020 16:00:57 -0700 Subject: [PATCH 067/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d06abd6c6..b9f667e0e 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ return { } ``` -This function is called by the game engine periodically to make sure your Battlesnake is healthy, responding correctly, and to determine how your Battlesnake will appear \on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. +This function is called by the game engine periodically to make sure your Battlesnake is healthy, responding correctly, and to determine how your Battlesnake will appear on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration and those changes should be reflected in the UI as well as any new games created. From baf57c26d5185a1714f1451f569d78f072f1e794 Mon Sep 17 00:00:00 2001 From: Arnav Bansal Date: Sat, 20 Jun 2020 02:37:45 -0400 Subject: [PATCH 068/117] Added the 'Run on Repl.it' button to Readme (#22) --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b9f667e0e..b8f2404f2 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,13 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake ## Running Your Battlesnake on [Repl.it](https://repl.it) -1. Login to your [Repl.it](https://repl.it) account. - -2. Create a new Repl and select `Import From GitHub`. +[![Run on Repl.it](https://repl.it/badge/github/BattlesnakeOfficial/starter-snake-python)](https://repl.it/github/BattlesnakeOfficial/starter-snake-python) -3. Paste the URL for this GitHub repo into the text field. +1. Login to your [Repl.it](https://repl.it) account. - ``` - https://github.com/BattlesnakeOfficial/starter-snake-python - ``` +2. Click the 'Run on Repl.it' button above, or visit the following URL: https://repl.it/github/BattlesnakeOfficial/starter-snake-python. -4. Click "Import from GitHub" to finish creating your new Repl. You should see your Repl being initialized - this might take a few moments to complete. +3. You should see your Repl being initialized - this might take a few moments to complete. 4. Once your Repl is ready to run, click `Run ▶️` at the top of the screen. You should see CherryPy (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following: From b0486421d44e3fc9c563ed260aac292b3f3952bf Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 15 Nov 2020 22:21:53 -0800 Subject: [PATCH 069/117] Remove outdated TODO (#27) /start no longer personalizes in v1; removing outdated TODO comment --- server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/server.py b/server.py index 11fe2b8b2..db706d40d 100644 --- a/server.py +++ b/server.py @@ -29,7 +29,6 @@ def index(self): def start(self): # This function is called everytime your snake is entered into a game. # cherrypy.request.json contains information about the game that's about to be played. - # TODO: Use this function to decide how your snake is going to look on the board. data = cherrypy.request.json print("START") From 3eedcd80ddbc1db84c7a12fdf4bbe35f91cc4d98 Mon Sep 17 00:00:00 2001 From: Sven Kerschbaum Date: Sun, 21 Mar 2021 00:51:48 +0100 Subject: [PATCH 070/117] Update README.md (#31) Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8f2404f2..60c4bf4af 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Now you're ready to start customizing your Battlesnake's appearance and behavior ### Changing Appearance -Locate the `index` function inside [server.py](server.py#L15). At the end of that function tou should see a line that looks like this: +Locate the `index` function inside [server.py](server.py#L15). At the end of that function you should see a line that looks like this: ```python return { From 6c13ea72a433fcdcc612e294d856486eefacfa1a Mon Sep 17 00:00:00 2001 From: Andrew MacLean <26526271+andrewdmaclean@users.noreply.github.com> Date: Mon, 5 Apr 2021 16:46:20 -0700 Subject: [PATCH 071/117] Create CODE_OF_CONDUCT --- CODE_OF_CONDUCT | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CODE_OF_CONDUCT diff --git a/CODE_OF_CONDUCT b/CODE_OF_CONDUCT new file mode 100644 index 000000000..a4dbea56e --- /dev/null +++ b/CODE_OF_CONDUCT @@ -0,0 +1,3 @@ +# Battlesnake Code of Conduct + +Please see https://docs.battlesnake.com/policies/conduct From 4d65f2227f1c0cf84529811974c3c4f1e8257da8 Mon Sep 17 00:00:00 2001 From: Andrew MacLean <26526271+andrewdmaclean@users.noreply.github.com> Date: Mon, 5 Apr 2021 16:47:00 -0700 Subject: [PATCH 072/117] Rename CODE_OF_CONDUCT to CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT => CODE_OF_CONDUCT.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CODE_OF_CONDUCT => CODE_OF_CONDUCT.md (100%) diff --git a/CODE_OF_CONDUCT b/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT rename to CODE_OF_CONDUCT.md From eb076cbf703d085107f1ea9e388c7d3c5d621141 Mon Sep 17 00:00:00 2001 From: Andrew MacLean <26526271+andrewdmaclean@users.noreply.github.com> Date: Tue, 18 May 2021 09:09:58 -0700 Subject: [PATCH 073/117] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 60c4bf4af..f54ad8292 100644 --- a/README.md +++ b/README.md @@ -164,3 +164,8 @@ python server.py All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. You can also join the Battlesnake Developer Community on [Slack](https://play.battlesnake.com/slack) and [Discord](https://play.battlesnake.com/discord). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) + + +### Feedback + +* **Do you have an issue or suggestions for this repository?** Head over to our [Feedback Repository](https://play.battlesnake.com/feedback) today and let us know! From f326634de0a3175b92c16af6ff4966a0bb49ceef Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Wed, 7 Jul 2021 13:39:22 -0700 Subject: [PATCH 074/117] DEV-24 Adding additional starter code and updating comments/documentation, adding simple tests (#33) Co-authored-by: Aurora Walker --- README.md | 4 +- server.py | 51 +++++++++++++++----------- server_logic.py | 78 +++++++++++++++++++++++++++++++++++++++ tests.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 207 insertions(+), 23 deletions(-) create mode 100644 server_logic.py create mode 100644 tests.py diff --git a/README.md b/README.md index f54ad8292..3b045dcda 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # A Simple [Battlesnake](http://play.battlesnake.com) Written in Python -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started. It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started that line up with the [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started). It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. ### Technologies Used @@ -87,7 +87,7 @@ Whenever you update these values, go to the page for your Battlesnake and select On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `move` function inside [server.py](server.py#L37). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. +Locate the `move` function inside [server.py](server.py#L48). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. Your Battlesnakes move logic lives in [server_logic.py](server_logic.py#L37). This is the code you will want to edit. See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. diff --git a/server.py b/server.py index db706d40d..895c0617d 100644 --- a/server.py +++ b/server.py @@ -1,21 +1,27 @@ import os -import random import cherrypy -""" -This is a simple Battlesnake server written in Python. -For instructions see https://github.com/BattlesnakeOfficial/starter-snake-python/README.md -""" +import server_logic +class BattlesnakeServer(object): + """ + This is a simple Battlesnake server written in Python using the CherryPy Web Framework. + For instructions see https://github.com/BattlesnakeOfficial/starter-snake-python/README.md + """ -class Battlesnake(object): @cherrypy.expose @cherrypy.tools.json_out() def index(self): - # This function is called when you register your Battlesnake on play.battlesnake.com - # It controls your Battlesnake appearance and author permissions. - # TIP: If you open your Battlesnake URL in browser you should see this data + """ + This function is called when you register your Battlesnake on play.battlesnake.com + See https://docs.battlesnake.com/guides/getting-started#step-4-register-your-battlesnake + + It controls your Battlesnake appearance and author permissions. + For customization options, see https://docs.battlesnake.com/references/personalization + + TIP: If you open your Battlesnake URL in browser you should see this data. + """ return { "apiversion": "1", "author": "", # TODO: Your Battlesnake Username @@ -27,8 +33,10 @@ def index(self): @cherrypy.expose @cherrypy.tools.json_in() def start(self): - # This function is called everytime your snake is entered into a game. - # cherrypy.request.json contains information about the game that's about to be played. + """ + This function is called everytime your snake is entered into a game. + cherrypy.request.json contains information about the game that's about to be played. + """ data = cherrypy.request.json print("START") @@ -38,23 +46,24 @@ def start(self): @cherrypy.tools.json_in() @cherrypy.tools.json_out() def move(self): - # This function is called on every turn of a game. It's how your snake decides where to move. - # Valid moves are "up", "down", "left", or "right". - # TODO: Use the information in cherrypy.request.json to decide your next move. + """ + This function is called on every turn of a game. It's how your snake decides where to move. + Valid moves are "up", "down", "left", or "right". + """ data = cherrypy.request.json - # Choose a random direction to move in - possible_moves = ["up", "down", "left", "right"] - move = random.choice(possible_moves) + # TODO - look at the server_logic.py file to see how we decide what move to return! + move = server_logic.choose_move(data) - print(f"MOVE: {move}") return {"move": move} @cherrypy.expose @cherrypy.tools.json_in() def end(self): - # This function is called when a game your snake was in ends. - # It's purely for informational purposes, you don't have to make any decisions here. + """ + This function is called when a game your snake was in ends. + It's purely for informational purposes, you don't have to make any decisions here. + """ data = cherrypy.request.json print("END") @@ -62,7 +71,7 @@ def end(self): if __name__ == "__main__": - server = Battlesnake() + server = BattlesnakeServer() cherrypy.config.update({"server.socket_host": "0.0.0.0"}) cherrypy.config.update( {"server.socket_port": int(os.environ.get("PORT", "8080")),} diff --git a/server_logic.py b/server_logic.py new file mode 100644 index 000000000..3ffc42f52 --- /dev/null +++ b/server_logic.py @@ -0,0 +1,78 @@ +import random +from typing import List, Dict + +""" +This file can be a nice home for your move logic, and to write helper functions. + +We have started this for you, with a function to help remove the 'neck' direction +from the list of possible moves! +""" + + +def avoid_my_neck(my_head: Dict[str, int], my_body: List[dict], possible_moves: List[str]) -> List[str]: + """ + my_head: Dictionary of x/y coordinates of the Battlesnake head. + e.g. {"x": 0, "y": 0} + my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake. + e.g. [ {"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0} ] + possible_moves: List of strings. Moves to pick from. + e.g. ["up", "down", "left", "right"] + + return: The list of remaining possible_moves, with the 'neck' direction removed + """ + my_neck = my_body[1] # The segment of body right after the head is the 'neck' + + if my_neck["x"] < my_head["x"]: # my neck is left of my head + possible_moves.remove("left") + elif my_neck["x"] > my_head["x"]: # my neck is right of my head + possible_moves.remove("right") + elif my_neck["y"] < my_head["y"]: # my neck is below my head + possible_moves.remove("down") + elif my_neck["y"] > my_head["y"]: # my neck is above my head + possible_moves.remove("up") + + return possible_moves + + +def choose_move(data: dict) -> str: + """ + data: Dictionary of all Game Board data as received from the Battlesnake Engine. + For a full example of 'data', see https://docs.battlesnake.com/references/api/sample-move-request + + return: A String, the single move to make. One of "up", "down", "left" or "right". + + Use the information in 'data' to decide your next move. The 'data' variable can be interacted + with as a Python Dictionary, and contains all of the information about the Battlesnake board + for each move of the game. + + """ + my_head = data["you"]["head"] # A dictionary of x/y coordinates like {"x": 0, "y": 0} + my_body = data["you"]["body"] # A list of x/y coordinate dictionaries like [ {"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0} ] + + # TODO: uncomment the lines below so you can see what this data looks like in your output! + # print(f"~~~ Turn: {data['turn']} Game Mode: {data['game']['ruleset']['name']} ~~~") + # print(f"All board data this turn: {data}") + # print(f"My Battlesnakes head this turn is: {my_head}") + # print(f"My Battlesnakes body this turn is: {my_body}") + + possible_moves = ["up", "down", "left", "right"] + + # Don't allow your Battlesnake to move back in on it's own neck + possible_moves = avoid_my_neck(my_head, my_body, possible_moves) + + # TODO: Using information from 'data', find the edges of the board and don't let your Battlesnake move beyond them + # board_height = ? + # board_width = ? + + # TODO Using information from 'data', don't let your Battlesnake pick a move that would hit its own body + + # TODO: Using information from 'data', don't let your Battlesnake pick a move that would collide with another Battlesnake + + # TODO: Using information from 'data', make your Battlesnake move towards a piece of food on the board + + # Choose a random direction from the remaining possible_moves to move in, and then return that move + move = random.choice(possible_moves) + + print(f"CHOOSING MOVE: {move} from all valid options in {possible_moves}") + + return move diff --git a/tests.py b/tests.py new file mode 100644 index 000000000..879835f2f --- /dev/null +++ b/tests.py @@ -0,0 +1,97 @@ +""" +Starter Unit Tests using the built-in Python unittest library. +See https://docs.python.org/3/library/unittest.html + +You can expand these to cover more cases! + +To run the unit tests, use the following command in your terminal, +in the folder where this file exists: + + python tests.py -v + +""" +import unittest + +from server_logic import avoid_my_neck + + +class AvoidNeckTest(unittest.TestCase): + + def test_avoid_neck_all(self): + """ + The possible move set should be all moves. + + In the starter position, a Battlesnake body is 'stacked' in a + single place, and thus all directions are valid. + """ + # Arrange + test_head = {"x": 5, "y": 5} + test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 5}, {"x": 5, "y": 5}] + possible_moves = ["up", "down", "left", "right"] + + # Act + result_moves = avoid_my_neck(test_head, test_body, possible_moves) + + # Assert + self.assertEqual(len(result_moves), 4) + self.assertEqual(possible_moves, result_moves) + + def test_avoid_neck_left(self): + # Arrange + test_head = {"x": 5, "y": 5} + test_body = [{"x": 5, "y": 5}, {"x": 4, "y": 5}, {"x": 3, "y": 5}] + possible_moves = ["up", "down", "left", "right"] + expected = ["up", "down", "right"] + + # Act + result_moves = avoid_my_neck(test_head, test_body, possible_moves) + + # Assert + self.assertEqual(len(result_moves), 3) + self.assertEqual(expected, result_moves) + + def test_avoid_neck_right(self): + # Arrange + test_head = {"x": 5, "y": 5} + test_body = [{"x": 5, "y": 5}, {"x": 6, "y": 5}, {"x": 7, "y": 5}] + possible_moves = ["up", "down", "left", "right"] + expected = ["up", "down", "left"] + + # Act + result_moves = avoid_my_neck(test_head, test_body, possible_moves) + + # Assert + self.assertEqual(len(result_moves), 3) + self.assertEqual(expected, result_moves) + + def test_avoid_neck_up(self): + # Arrange + test_head = {"x": 5, "y": 5} + test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 6}, {"x": 5, "y": 7}] + possible_moves = ["up", "down", "left", "right"] + expected = ["down", "left", "right"] + + # Act + result_moves = avoid_my_neck(test_head, test_body, possible_moves) + + # Assert + self.assertEqual(len(result_moves), 3) + self.assertEqual(expected, result_moves) + + def test_avoid_neck_down(self): + # Arrange + test_head = {"x": 5, "y": 5} + test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}] + possible_moves = ["up", "down", "left", "right"] + expected = ["up", "left", "right"] + + # Act + result_moves = avoid_my_neck(test_head, test_body, possible_moves) + + # Assert + self.assertEqual(len(result_moves), 3) + self.assertEqual(expected, result_moves) + + +if __name__ == '__main__': + unittest.main() From 6d6d6b2f7da68d53475f27a0d3c235b7340b57c9 Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Thu, 8 Jul 2021 17:01:23 -0700 Subject: [PATCH 075/117] Update LICENSE Bumping licence version as is in-line with most recent changes --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 94ec72e7c..1b0a00485 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Battlesnake Inc. +Copyright (c) 2021 Battlesnake Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From e385cce7619e24ba491f9d2015204321e3fede79 Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Mon, 12 Jul 2021 13:53:24 -0700 Subject: [PATCH 076/117] Dev 24 update debugging statements (#34) * Update server_logic.py * update debug prints for info/start/end --- server.py | 9 +++++---- server_logic.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server.py b/server.py index 895c0617d..6167b2ea1 100644 --- a/server.py +++ b/server.py @@ -22,6 +22,7 @@ def index(self): TIP: If you open your Battlesnake URL in browser you should see this data. """ + print("INFO") return { "apiversion": "1", "author": "", # TODO: Your Battlesnake Username @@ -38,8 +39,8 @@ def start(self): cherrypy.request.json contains information about the game that's about to be played. """ data = cherrypy.request.json - - print("START") + + print(f"{data['game']['id']} START") return "ok" @cherrypy.expose @@ -65,8 +66,8 @@ def end(self): It's purely for informational purposes, you don't have to make any decisions here. """ data = cherrypy.request.json - - print("END") + + print(f"{data['game']['id']} END") return "ok" diff --git a/server_logic.py b/server_logic.py index 3ffc42f52..c5fb89a15 100644 --- a/server_logic.py +++ b/server_logic.py @@ -72,7 +72,8 @@ def choose_move(data: dict) -> str: # Choose a random direction from the remaining possible_moves to move in, and then return that move move = random.choice(possible_moves) + # TODO: Explore new strategies for picking a move that are better than random + + print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {possible_moves}") - print(f"CHOOSING MOVE: {move} from all valid options in {possible_moves}") - return move From 4a3108d4a0a81a7fda48eb1dfa7d761513137bb9 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 16 Jul 2021 20:54:20 -0700 Subject: [PATCH 077/117] Swap in Flask for CherryPy --- README.md | 9 +- poetry.lock | 221 ++++++++++++++++++++++------------------------- pyproject.toml | 2 +- requirements.txt | 2 +- server.py | 134 ++++++++++++++-------------- server_logic.py | 4 +- tests.py | 5 +- 7 files changed, 178 insertions(+), 199 deletions(-) diff --git a/README.md b/README.md index 3b045dcda..23bb023ca 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake ### Technologies Used * [Python3](https://www.python.org/) -* [CherryPy](https://cherrypy.org/) +* [Flask](https://flask.palletsprojects.com/) ## Prerequisites @@ -24,11 +24,14 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake 3. You should see your Repl being initialized - this might take a few moments to complete. -4. Once your Repl is ready to run, click `Run ▶️` at the top of the screen. You should see CherryPy (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following: +4. Once your Repl is ready to run, click `Run ▶️` at the top of the screen. You should see Flask (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following: ``` + * Serving Flask app 'server' (lazy loading) + * Environment: production + WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Debug mode: on Starting Battlesnake Server... - ENGINE Serving on http://0.0.0.0:8080 ``` 5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. If you visit that URL in your browser, you should see text similar to this: diff --git a/poetry.lock b/poetry.lock index db11ed754..d793b3a27 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,161 +1,144 @@ [[package]] +name = "click" +version = "8.0.1" +description = "Composable command line interface toolkit" category = "main" -description = "Highly-optimized, pure-python HTTP server" -name = "cheroot" -optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" -version = "8.3.0" - -[package.dependencies] -"jaraco.functools" = "*" -more-itertools = ">=2.6" -six = ">=1.11.0" - -[[package]] -category = "main" -description = "Object-Oriented HTTP framework" -name = "cherrypy" -optional = false -python-versions = ">=3.5" -version = "18.6.0" - -[package.dependencies] -cheroot = ">=8.2.1" -"jaraco.collections" = "*" -more-itertools = "*" -portend = ">=2.1.1" -pywin32 = "*" -"zc.lockfile" = "*" - -[[package]] -category = "main" -description = "Utility functions for Python class constructs" -name = "jaraco.classes" optional = false python-versions = ">=3.6" -version = "3.1.0" [package.dependencies] -more-itertools = "*" +colorama = {version = "*", markers = "platform_system == \"Windows\""} [[package]] +name = "colorama" +version = "0.4.4" +description = "Cross-platform colored terminal text." category = "main" -description = "Collection objects similar to those in stdlib by jaraco" -name = "jaraco.collections" optional = false -python-versions = ">=3.6" -version = "3.0.0" - -[package.dependencies] -"jaraco.classes" = "*" -"jaraco.text" = "*" -six = ">=1.7.0" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] +name = "flask" +version = "2.0.1" +description = "A simple framework for building complex web applications." category = "main" -description = "Functools like those found in stdlib" -name = "jaraco.functools" optional = false python-versions = ">=3.6" -version = "3.0.1" [package.dependencies] -more-itertools = "*" - -[[package]] -category = "main" -description = "Module for text manipulation" -name = "jaraco.text" -optional = false -python-versions = ">=2.7" -version = "3.2.0" +click = ">=7.1.2" +itsdangerous = ">=2.0" +Jinja2 = ">=3.0" +Werkzeug = ">=2.0" -[package.dependencies] -"jaraco.functools" = "*" -six = "*" +[package.extras] +async = ["asgiref (>=3.2)"] +dotenv = ["python-dotenv"] [[package]] +name = "itsdangerous" +version = "2.0.1" +description = "Safely pass data to untrusted environments and back." category = "main" -description = "More routines for operating on iterables, beyond itertools" -name = "more-itertools" optional = false -python-versions = ">=3.5" -version = "8.3.0" +python-versions = ">=3.6" [[package]] +name = "jinja2" +version = "3.0.1" +description = "A very fast and expressive template engine." category = "main" -description = "TCP port monitoring and discovery" -name = "portend" optional = false -python-versions = ">=2.7" -version = "2.6" +python-versions = ">=3.6" [package.dependencies] -tempora = ">=1.8" - -[[package]] -category = "main" -description = "World timezone definitions, modern and historical" -name = "pytz" -optional = false -python-versions = "*" -version = "2020.1" - -[[package]] -category = "main" -description = "Python for Window Extensions" -marker = "sys_platform == \"win32\"" -name = "pywin32" -optional = false -python-versions = "*" -version = "227" +MarkupSafe = ">=2.0" -[[package]] -category = "main" -description = "Python 2 and 3 compatibility utilities" -name = "six" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" -version = "1.15.0" +[package.extras] +i18n = ["Babel (>=2.7)"] [[package]] +name = "markupsafe" +version = "2.0.1" +description = "Safely add untrusted strings to HTML/XML markup." category = "main" -description = "Objects and routines pertaining to date and time (tempora)" -name = "tempora" optional = false python-versions = ">=3.6" -version = "3.0.0" - -[package.dependencies] -"jaraco.functools" = ">=1.20" -pytz = "*" [[package]] +name = "werkzeug" +version = "2.0.1" +description = "The comprehensive WSGI web application library." category = "main" -description = "Basic inter-process locks" -name = "zc.lockfile" optional = false -python-versions = "*" -version = "2.0" +python-versions = ">=3.6" -[package.dependencies] -setuptools = "*" +[package.extras] +watchdog = ["watchdog"] [metadata] -content-hash = "4525054609701dd3baffd13f86cbea41801fb80b658a5de84dcccb8eaee13401" +lock-version = "1.1" python-versions = "^3.8" - -[metadata.hashes] -cheroot = ["2b48c88959b5b80a79aca627ae5212acb398becaa70b576b8b89bec1ad0d1367", "a0577e1f28661727d472671a7cc4e0c12ea0cbc5220265e70f00a8b8cb628931"] -cherrypy = ["56608edd831ad00991ae585625e0206ed61cf1a0850e4b2cc48489fb2308c499", "c0a7283f02a384c112a0a18404fd3abd849fc7fd4bec19378067150a2573d2e4"] -"jaraco.classes" = ["116429c2047953f525afdcae165475c4589c7b14870e78b2d068ecb01018827e", "c38698ff8ef932eb33d91c0e8fc192ad7c44ecee03f7f585afd4f35aeaef7aab"] -"jaraco.collections" = ["a7889f28c80c4875bd6256d9924e8526dacfef22cd7b80ff8469b4d312f9f144", "be570ef4f2e7290b757449395238fa63d70a9255574624e73c5ff9f1ee554721"] -"jaraco.functools" = ["9fedc4be3117512ca3e03e1b2ffa7a6a6ffa589bfb7d02bfb324e55d493b94f4", "d3dc9f6c1a1d45d7f59682a3bf77aceb685c1a60891606c7e4161e72ecc399ad"] -"jaraco.text" = ["c87569c9afae14f71b2e1c57f316770ab6981ab675d9c602be1c7981161bacdd", "e5078b1126cc0f166c7859aa75103a56c0d0f39ebcafc21695615472e0f810ec"] -more-itertools = ["558bb897a2232f5e4f8e2399089e35aecb746e1f9191b6584a151647e89267be", "7818f596b1e87be009031c7653d01acc46ed422e6656b394b0f765ce66ed4982"] -portend = ["600dd54175e17e9347e5f3d4217aa8bcf4bf4fa5ffbc4df034e5ec1ba7cdaff5", "62dd00b94a6a55fbf0320365fbdeba37f0d1fe14d613841037dc4780bedfda8f"] -pytz = ["a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed", "c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"] -pywin32 = ["300a2db938e98c3e7e2093e4491439e62287d0d493fe07cce110db070b54c0be", "31f88a89139cb2adc40f8f0e65ee56a8c585f629974f9e07622ba80199057511", "371fcc39416d736401f0274dd64c2302728c9e034808e37381b5e1b22be4a6b0", "47a3c7551376a865dd8d095a98deba954a98f326c6fe3c72d8726ca6e6b15507", "4cdad3e84191194ea6d0dd1b1b9bdda574ff563177d2adf2b4efec2a244fa116", "7c1ae32c489dc012930787f06244426f8356e129184a02c25aef163917ce158e", "7f18199fbf29ca99dff10e1f09451582ae9e372a892ff03a28528a24d55875bc", "9b31e009564fb95db160f154e2aa195ed66bcc4c058ed72850d047141b36f3a2", "a929a4af626e530383a579431b70e512e736e9588106715215bf685a3ea508d4", "c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295", "f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c", "f4c5be1a293bae0076d93c88f37ee8da68136744588bc5e2be2f299a34ceb7aa"] -six = ["30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"] -tempora = ["70503a3a10fb341f49e7919d193f0b6362bbfddffb560fac47df3e977414c0c6", "e370d822cf48f5356aab0734ea45807250f5120e291c76712a1d766b49ae34f8"] -"zc.lockfile" = ["307ad78227e48be260e64896ec8886edc7eae22d8ec53e4d528ab5537a83203b", "cc33599b549f0c8a248cb72f3bf32d77712de1ff7ee8814312eb6456b42c015f"] +content-hash = "cb806ee633cb53933ae5610583ae98ba3574ebb5c0d2a215cc8602e7af663e18" + +[metadata.files] +click = [ + {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, + {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +flask = [ + {file = "Flask-2.0.1-py3-none-any.whl", hash = "sha256:a6209ca15eb63fc9385f38e452704113d679511d9574d09b2cf9183ae7d20dc9"}, + {file = "Flask-2.0.1.tar.gz", hash = "sha256:1c4c257b1892aec1398784c63791cbaa43062f1f7aeb555c4da961b20ee68f55"}, +] +itsdangerous = [ + {file = "itsdangerous-2.0.1-py3-none-any.whl", hash = "sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c"}, + {file = "itsdangerous-2.0.1.tar.gz", hash = "sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"}, +] +jinja2 = [ + {file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"}, + {file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"}, +] +markupsafe = [ + {file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:0955295dd5eec6cb6cc2fe1698f4c6d84af2e92de33fbcac4111913cd100a6ff"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:0446679737af14f45767963a1a9ef7620189912317d095f2d9ffa183a4d25d2b"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:f826e31d18b516f653fe296d967d700fddad5901ae07c622bb3705955e1faa94"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:fa130dd50c57d53368c9d59395cb5526eda596d3ffe36666cd81a44d56e48872"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:905fec760bd2fa1388bb5b489ee8ee5f7291d692638ea5f67982d968366bef9f"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-win32.whl", hash = "sha256:6c4ca60fa24e85fe25b912b01e62cb969d69a23a5d5867682dd3e80b5b02581d"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b2f4bf27480f5e5e8ce285a8c8fd176c0b03e93dcc6646477d4630e83440c6a9"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0717a7390a68be14b8c793ba258e075c6f4ca819f15edfc2a3a027c823718567"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:6557b31b5e2c9ddf0de32a691f2312a32f77cd7681d8af66c2692efdbef84c18"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:49e3ceeabbfb9d66c3aef5af3a60cc43b85c33df25ce03d0031a608b0a8b2e3f"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:d7f9850398e85aba693bb640262d3611788b1f29a79f0c93c565694658f4071f"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:6a7fae0dd14cf60ad5ff42baa2e95727c3d81ded453457771d02b7d2b3f9c0c2"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:b7f2d075102dc8c794cbde1947378051c4e5180d52d276987b8d28a3bd58c17d"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-win32.whl", hash = "sha256:a30e67a65b53ea0a5e62fe23682cfe22712e01f453b95233b25502f7c61cb415"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:611d1ad9a4288cf3e3c16014564df047fe08410e628f89805e475368bd304914"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:be98f628055368795d818ebf93da628541e10b75b41c559fdf36d104c5787066"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:1d609f577dc6e1aa17d746f8bd3c31aa4d258f4070d61b2aa5c4166c1539de35"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7d91275b0245b1da4d4cfa07e0faedd5b0812efc15b702576d103293e252af1b"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:01a9b8ea66f1658938f65b93a85ebe8bc016e6769611be228d797c9d998dd298"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:47ab1e7b91c098ab893b828deafa1203de86d0bc6ab587b160f78fe6c4011f75"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:97383d78eb34da7e1fa37dd273c20ad4320929af65d156e35a5e2d89566d9dfb"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-win32.whl", hash = "sha256:023cb26ec21ece8dc3907c0e8320058b2e0cb3c55cf9564da612bc325bed5e64"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:984d76483eb32f1bcb536dc27e4ad56bba4baa70be32fa87152832cdd9db0833"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:2ef54abee730b502252bcdf31b10dacb0a416229b72c18b19e24a4509f273d26"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3c112550557578c26af18a1ccc9e090bfe03832ae994343cfdacd287db6a6ae7"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:53edb4da6925ad13c07b6d26c2a852bd81e364f95301c66e930ab2aef5b5ddd8"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:f5653a225f31e113b152e56f154ccbe59eeb1c7487b39b9d9f9cdb58e6c79dc5"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:4efca8f86c54b22348a5467704e3fec767b2db12fc39c6d963168ab1d3fc9135"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:ab3ef638ace319fa26553db0624c4699e31a28bb2a835c5faca8f8acf6a5a902"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:f8ba0e8349a38d3001fae7eadded3f6606f0da5d748ee53cc1dab1d6527b9509"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-win32.whl", hash = "sha256:10f82115e21dc0dfec9ab5c0223652f7197feb168c940f3ef61563fc2d6beb74"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:693ce3f9e70a6cf7d2fb9e6c9d8b204b6b39897a2c4a1aa65728d5ac97dcc1d8"}, + {file = "MarkupSafe-2.0.1.tar.gz", hash = "sha256:594c67807fb16238b30c44bdf74f36c02cdf22d1c8cda91ef8a0ed8dabf5620a"}, +] +werkzeug = [ + {file = "Werkzeug-2.0.1-py3-none-any.whl", hash = "sha256:6c1ec500dcdba0baa27600f6a22f6333d8b662d22027ff9f6202e3367413caa8"}, + {file = "Werkzeug-2.0.1.tar.gz", hash = "sha256:1de1db30d010ff1af14a009224ec49ab2329ad2cde454c8a708130642d579c42"}, +] diff --git a/pyproject.toml b/pyproject.toml index 09a8515ec..24dc0afd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,4 +6,4 @@ authors = ["Battlesnake Developers "] [tool.poetry.dependencies] python = "^3.8" -cherrypy = "^18.6" +Flask = "^2.0.1" diff --git a/requirements.txt b/requirements.txt index abd979817..31717cedd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -CherryPy==18.5.0 +Flask==2.0.1 diff --git a/server.py b/server.py index 6167b2ea1..c118951a6 100644 --- a/server.py +++ b/server.py @@ -1,81 +1,75 @@ -import os +import logging -import cherrypy +from flask import Flask +from flask import request import server_logic -class BattlesnakeServer(object): + +app = Flask(__name__) + + +@app.get("/") +def handle_info(): """ - This is a simple Battlesnake server written in Python using the CherryPy Web Framework. - For instructions see https://github.com/BattlesnakeOfficial/starter-snake-python/README.md + This function is called when you register your Battlesnake on play.battlesnake.com + See https://docs.battlesnake.com/guides/getting-started#step-4-register-your-battlesnake + + It controls your Battlesnake appearance and author permissions. + For customization options, see https://docs.battlesnake.com/references/personalization + + TIP: If you open your Battlesnake URL in browser you should see this data. """ + print("INFO") + return { + "apiversion": "1", + "author": "", # TODO: Your Battlesnake Username + "color": "#888888", # TODO: Personalize + "head": "default", # TODO: Personalize + "tail": "default", # TODO: Personalize + } - @cherrypy.expose - @cherrypy.tools.json_out() - def index(self): - """ - This function is called when you register your Battlesnake on play.battlesnake.com - See https://docs.battlesnake.com/guides/getting-started#step-4-register-your-battlesnake - - It controls your Battlesnake appearance and author permissions. - For customization options, see https://docs.battlesnake.com/references/personalization - - TIP: If you open your Battlesnake URL in browser you should see this data. - """ - print("INFO") - return { - "apiversion": "1", - "author": "", # TODO: Your Battlesnake Username - "color": "#888888", # TODO: Personalize - "head": "default", # TODO: Personalize - "tail": "default", # TODO: Personalize - } - - @cherrypy.expose - @cherrypy.tools.json_in() - def start(self): - """ - This function is called everytime your snake is entered into a game. - cherrypy.request.json contains information about the game that's about to be played. - """ - data = cherrypy.request.json - - print(f"{data['game']['id']} START") - return "ok" - - @cherrypy.expose - @cherrypy.tools.json_in() - @cherrypy.tools.json_out() - def move(self): - """ - This function is called on every turn of a game. It's how your snake decides where to move. - Valid moves are "up", "down", "left", or "right". - """ - data = cherrypy.request.json - - # TODO - look at the server_logic.py file to see how we decide what move to return! - move = server_logic.choose_move(data) - - return {"move": move} - - @cherrypy.expose - @cherrypy.tools.json_in() - def end(self): - """ - This function is called when a game your snake was in ends. - It's purely for informational purposes, you don't have to make any decisions here. - """ - data = cherrypy.request.json - - print(f"{data['game']['id']} END") - return "ok" + +@app.post("/start") +def handle_start(): + """ + This function is called everytime your snake is entered into a game. + cherrypy.request.json contains information about the game that's about to be played. + """ + data = request.get_json() + + print(f"{data['game']['id']} START") + return "ok" + + +@app.post("/move") +def handle_move(): + """ + This function is called on every turn of a game. It's how your snake decides where to move. + Valid moves are "up", "down", "left", or "right". + """ + data = request.get_json() + + # TODO - look at the server_logic.py file to see how we decide what move to return! + move = server_logic.choose_move(data) + + return {"move": move} + + +@app.post("/end") +def end(): + """ + This function is called when a game your snake was in ends. + It's purely for informational purposes, you don't have to make any decisions here. + """ + data = request.get_json() + + print(f"{data['game']['id']} END") + return "ok" if __name__ == "__main__": - server = BattlesnakeServer() - cherrypy.config.update({"server.socket_host": "0.0.0.0"}) - cherrypy.config.update( - {"server.socket_port": int(os.environ.get("PORT", "8080")),} - ) + logging.getLogger("werkzeug").setLevel(logging.ERROR) + print("Starting Battlesnake Server...") - cherrypy.quickstart(server) + app.run(host="0.0.0.0", port="8080", debug=True) diff --git a/server_logic.py b/server_logic.py index c5fb89a15..9b0c7dd4a 100644 --- a/server_logic.py +++ b/server_logic.py @@ -42,7 +42,7 @@ def choose_move(data: dict) -> str: return: A String, the single move to make. One of "up", "down", "left" or "right". Use the information in 'data' to decide your next move. The 'data' variable can be interacted - with as a Python Dictionary, and contains all of the information about the Battlesnake board + with as a Python Dictionary, and contains all of the information about the Battlesnake board for each move of the game. """ @@ -51,7 +51,7 @@ def choose_move(data: dict) -> str: # TODO: uncomment the lines below so you can see what this data looks like in your output! # print(f"~~~ Turn: {data['turn']} Game Mode: {data['game']['ruleset']['name']} ~~~") - # print(f"All board data this turn: {data}") + # print(f"All board data this turn: {data}") # print(f"My Battlesnakes head this turn is: {my_head}") # print(f"My Battlesnakes body this turn is: {my_body}") diff --git a/tests.py b/tests.py index 879835f2f..47bce7ca6 100644 --- a/tests.py +++ b/tests.py @@ -16,12 +16,11 @@ class AvoidNeckTest(unittest.TestCase): - def test_avoid_neck_all(self): """ The possible move set should be all moves. - In the starter position, a Battlesnake body is 'stacked' in a + In the starter position, a Battlesnake body is 'stacked' in a single place, and thus all directions are valid. """ # Arrange @@ -93,5 +92,5 @@ def test_avoid_neck_down(self): self.assertEqual(expected, result_moves) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() From 4c2f34fa7424d47f51dffbcc2760e64961c3d04a Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 19 Jul 2021 13:06:36 -0700 Subject: [PATCH 078/117] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 23bb023ca..ab447afa5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # A Simple [Battlesnake](http://play.battlesnake.com) Written in Python +![Battlesnake Logo](https://media.battlesnake.com/social/GitHubSocial.png) + This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started that line up with the [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started). It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. ### Technologies Used From f71d9596ea842f42ee90367d80d9c160c6f2fc80 Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Mon, 19 Jul 2021 15:08:54 -0700 Subject: [PATCH 079/117] Dev 175 (#35) * Update runtime.txt file for Heroku Heroku python supported versions are now: https://devcenter.heroku.com/articles/python-support#supported-runtimes * Check env vars for port Change is to support deploying on Heroku, which uses the environment variable. Default to 8080 if not supplied. --- runtime.txt | 2 +- server.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime.txt b/runtime.txt index 385705b56..9bff0e00f 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.8.3 +python-3.9.6 diff --git a/server.py b/server.py index c118951a6..9f6f09803 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,5 @@ import logging +import os from flask import Flask from flask import request @@ -72,4 +73,5 @@ def end(): logging.getLogger("werkzeug").setLevel(logging.ERROR) print("Starting Battlesnake Server...") - app.run(host="0.0.0.0", port="8080", debug=True) + port = int(os.environ.get("PORT", "8080")) + app.run(host="0.0.0.0", port=port, debug=True) From 051c30eac5fcffe76d021f7740f9f3c4755e8d6b Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Tue, 20 Jul 2021 14:57:15 -0700 Subject: [PATCH 080/117] Dev 175 (#36) ReadMe Updates: Updates to rely more on linked information via docs.battlesnake.com Adding UTM to see if ReadMe changes are effective Added note about testing file --- README.md | 147 +++++++++++------------------------------------------- 1 file changed, 29 insertions(+), 118 deletions(-) diff --git a/README.md b/README.md index ab447afa5..f5b30c2f3 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,28 @@ -# A Simple [Battlesnake](http://play.battlesnake.com) Written in Python +# A Simple [Battlesnake](http://play.battlesnake.com?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) Written in Python ![Battlesnake Logo](https://media.battlesnake.com/social/GitHubSocial.png) -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and provides instructions below for getting started that line up with the [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started). It can also be deployed to [Heroku](https://heroku.com), or any other cloud provider you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. -### Technologies Used +## Technologies Used * [Python3](https://www.python.org/) * [Flask](https://flask.palletsprojects.com/) -## Prerequisites +## Quickstart -* [Battlesnake Account](https://play.battlesnake.com) -* [Repl.it Account](https://repl.it) -* [GitHub Account](https://github.com) (Optional) +The [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started) provides the full set of instructions to customize, register, and create your first games with your Battlesnake! While the guide uses [Repl.it](https://repl.it) as an example host, the instructions can be modified to work with any hosting provider. You can also find advice on other hosting providers on our [Hosting Suggestions](https://docs.battlesnake.com/references/hosting-suggestions) page. -## Running Your Battlesnake on [Repl.it](https://repl.it) - -[![Run on Repl.it](https://repl.it/badge/github/BattlesnakeOfficial/starter-snake-python)](https://repl.it/github/BattlesnakeOfficial/starter-snake-python) - -1. Login to your [Repl.it](https://repl.it) account. - -2. Click the 'Run on Repl.it' button above, or visit the following URL: https://repl.it/github/BattlesnakeOfficial/starter-snake-python. - -3. You should see your Repl being initialized - this might take a few moments to complete. - -4. Once your Repl is ready to run, click `Run ▶️` at the top of the screen. You should see Flask (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following: - - ``` - * Serving Flask app 'server' (lazy loading) - * Environment: production - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. - * Debug mode: on - Starting Battlesnake Server... - ``` - -5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. If you visit that URL in your browser, you should see text similar to this: - - ``` - {"apiversion": "1", "author": "", "color": "#888888", "head": "default", "tail": "default"} - ``` - -This means your Battlesnake is running correctly on Repl.it. - -**At this point your Battlesnake is live and ready to enter games!** - - - -## Registering Your Battlesnake and Creating Your First Game - -1. Sign in to [play.battlesnake.com](https://play.battlesnake.com/login/). - -2. Go [here to create a new Battlesnake](https://play.battlesnake.com/account/snakes/create/). Give it a meaningful name and complete the form using the URL for your Repl from above. - -3. Once your Battlesnake has been saved you can [create a new game](https://play.battlesnake.com/account/games/create/) and add your Battlesnake to it. Type your Battlesnake's name into the search field and click "Add" to add it to the game. Then click "Create Game" to start the game. - -4. You should see a brand new Battlesnake game with your Battlesnake in it! Yay! Press "Play" to start the game and watch how your Battlesnake behaves. By default your Battlesnake should move randomly around the board. - -5. Optionally, watch your Repl logs while the game is running to see your Battlesnake receiving API calls and responding with its moves. - -Repeat steps 3 and 4 every time you want to see how your Battlesnake behaves. It's common for Battlesnake developers to repeat these steps often as they make their Battlesnake smarter. You can also use the "Create Rematch" button to quickly start a new game using the same Battlesnakes and configuration. - -**At this point you should have a registered Battlesnake and be able to create games!** +### Prerequisites +* A free [Battlesnake Account](https://play.battlesnake.com/?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) +--- ## Customizing Your Battlesnake -Now you're ready to start customizing your Battlesnake's appearance and behavior. - -### Changing Appearance - -Locate the `index` function inside [server.py](server.py#L15). At the end of that function you should see a line that looks like this: +Locate the `handle_info` function inside [server.py](server.py#L15). At the end of that function you should see a line that looks like this: ```python return { @@ -88,89 +38,50 @@ This function is called by the game engine periodically to make sure your Battle Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration and those changes should be reflected in the UI as well as any new games created. -### Changing Behavior +## Changing Behavior On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `move` function inside [server.py](server.py#L48). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. Your Battlesnakes move logic lives in [server_logic.py](server_logic.py#L37). This is the code you will want to edit. +Locate the `handle_move` function inside [server.py](server.py#L48). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. Your Battlesnakes move logic lives in [server_logic.py](server_logic.py#L37). This is the code you will want to edit. See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. -### Updating Your Battlesnake - -After making changes to your Battlesnake, you can restart your Repl to have the change take effect (or in many cases your Repl will restart automatically). - -Once the Repl has restarted you can [create a new game](https://play.battlesnake.com/account/games/create/) with your Battlesnake to watch your latest changes in action. - -**At this point you should feel comfortable making changes to your code and starting new Battlesnake games to test those changes!** +## Running Tests +This Starter Project comes with a very simple test suite for you to expand! Located in `tests.py` you can run them using the following command: +```python tests.py -v``` +--- -## Developing Your Battlesnake Further - -Now you have everything you need to start making your Battlesnake super smart! - -### Early Development Goals - -Here are some simple goals to help you develop your Battlesnake early on. Completing these will make your Battlesnake competitive against other Battlesnakes in multi-player games. - -- [ ] Avoid colliding with walls -- [ ] Avoid colliding with yourself -- [ ] Try to move towards food -- [ ] Avoid colliding with other snakes - -Once you have completed these steps you'll be ready to compete live against other Battlesnakes and start exploring and implementing more complex strategies. - - -### Helpful Tips - -* Keeping your Repl open in a second window while games are running is helpful for watching server activity and debugging any problems with your Battlesnake. - -* You can use the Python [print function](https://docs.python.org/3.8/library/functions.html#print) to output information to your server logs. This is very useful for debugging logic in your code during Battlesnake games. - -* Review the [Battlesnake API Docs](https://docs.battlesnake.com/references/api) to learn what information is provided with each command. - -* When viewing a Battlesnake game you can pause playback and step forward/backward one frame at a time. If you review your logs at the same time, you can see what decision your Battlesnake made on each turn. +## Playing Battlesnake +### Completing Challenges +If you're looking for the Single Player Mode of Battlesnake, or something to practice with between events, check out [Challenges.](https://docs.battlesnake.com/guides/quick-start-challenges-guide) -## Joining a Battlesnake Arena +### Joining a Battlesnake Arena Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Battlesnakes worldwide. Arenas will regularly create new games and rank Battlesnakes based on their results. They're a good way to get regular feedback on how well your Battlesnake is performing, and a fun way to track your progress as you develop your algorithm. +### Joining a Battlesnake League - -## (Optional) Using a Cloud Provider - -As your Battlesnake gets more complex, it might make sense to move it to a dedicated hosting provider such as Heroku or AWS. We suggest choosing a platform you're familiar with, or one you'd be interested in learning more about. - -If you have questions or ideas, our developer community on [Slack](https://play.battlesnake.com/slack) and [Discord](https://play.battlesnake.com/discord) will be able to help out. - - - -## (Optional) Running Your Battlesnake Locally - -Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.8](https://www.python.org/downloads/) and running: - -```shell -python server.py -``` - -**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install and use a port forwarding tool like [ngrok](https://ngrok.com/). - +Want to get out there to compete and win prizes? Check out the [Quick Start League Guide](https://docs.battlesnake.com/guides/quick-start-league-guide) for information on the how and when of our competitive seasons. --- - -### Questions? +## Resources All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. -You can also join the Battlesnake Developer Community on [Slack](https://play.battlesnake.com/slack) and [Discord](https://play.battlesnake.com/discord). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) +You can also join the Battlesnake Developer Community on [Discord](https://play.battlesnake.com/discord?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=discord). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) + +Check out live Battlesnake events on [Twitch](https://www.twitch.tv/battlesnakeofficial) and see what is happening when on the [Calendar.](https://play.battlesnake.com/calendar?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=calendar) + +Want to contribute to Battlesnake? We have a number of open-source codebases and would love for you to get involved! Check out our page on [Contributing.](https://docs.battlesnake.com/guides/contributing) -### Feedback +## Feedback -* **Do you have an issue or suggestions for this repository?** Head over to our [Feedback Repository](https://play.battlesnake.com/feedback) today and let us know! +**Do you have an issue or suggestions for this repository?** Head over to our [Feedback Repository](https://play.battlesnake.com/feedback?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=feedback) today and let us know! From 91a240076129b7fb1248a7d39b643cc79123d830 Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Tue, 20 Jul 2021 15:40:48 -0700 Subject: [PATCH 081/117] putting back running local instructions --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index f5b30c2f3..724f50357 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,16 @@ Locate the `handle_move` function inside [server.py](server.py#L48). Possible mo See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. +## (Optional) Running Your Battlesnake Locally + +Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.8](https://www.python.org/downloads/) and running: + +```shell +python server.py +``` + +**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install and use a port forwarding tool like [ngrok](https://ngrok.com/). See [Hosting Suggestions.](https://docs.battlesnake.com/references/hosting-suggestions#local) + ## Running Tests This Starter Project comes with a very simple test suite for you to expand! Located in `tests.py` you can run them using the following command: From 4dbed6229ea3b0270c8b75a93df2f270ea1cbbc6 Mon Sep 17 00:00:00 2001 From: Justin Workman Date: Sat, 24 Jul 2021 09:35:09 -0700 Subject: [PATCH 082/117] Remove reference to CherryPy in server.py (#37) CherryPy was replaced with Flask, just updating the comment accordingly --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 9f6f09803..b02076adf 100644 --- a/server.py +++ b/server.py @@ -35,7 +35,7 @@ def handle_info(): def handle_start(): """ This function is called everytime your snake is entered into a game. - cherrypy.request.json contains information about the game that's about to be played. + request.json contains information about the game that's about to be played. """ data = request.get_json() From e6a5c156b3aa63a07fae45f8c29293abac346e11 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 1 Sep 2021 14:19:23 -0700 Subject: [PATCH 083/117] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 724f50357..cc4d16da2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# A Simple [Battlesnake](http://play.battlesnake.com?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) Written in Python +# Getting started with [Battlesnake](http://play.battlesnake.com?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) and Python ![Battlesnake Logo](https://media.battlesnake.com/social/GitHubSocial.png) -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api). It's a great starting point for anyone wanting to program their first Battlesnake using Python. It comes ready to use with [Repl.it](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake using Python, and comes ready to deploy with [Replit](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. ## Technologies Used From 7fb6344e3b08e8f898f88e22a81014fd3aeea7bd Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 2 Sep 2021 10:23:12 -0700 Subject: [PATCH 084/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc4d16da2..08637457d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Getting started with [Battlesnake](http://play.battlesnake.com?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) and Python -![Battlesnake Logo](https://media.battlesnake.com/social/GitHubSocial.png) +![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake using Python, and comes ready to deploy with [Replit](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. From ecf5973865839e3de4aa38f398fbba895a052ac6 Mon Sep 17 00:00:00 2001 From: Chris Hoefgen <53871533+chris-bsnake@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:29:26 -0700 Subject: [PATCH 085/117] Adding initial CODEOWNERS file --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..ddc015ee9 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @chris-bsnake @aurorawalker @bvanvugt From 236899974c0b006bd8012f6c44230bd077b2910a Mon Sep 17 00:00:00 2001 From: Aurora Walker <663009+aurorawalker@users.noreply.github.com> Date: Fri, 1 Oct 2021 15:30:02 -0700 Subject: [PATCH 086/117] Create CONTRIBUTING.md --- CONTRIBUTING.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..b567ca45b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,8 @@ +# Contributing + +We welcome contributions from the community! + +Please see https://docs.battlesnake.com/community/contributing + +We track all issues/discussions for all our open source repos at https://github.com/BattlesnakeOfficial/feedback/discussions +Any item tagged with "flag/help-wanted ✋" is a great place to start, as it highlights any issues where we'd love to get some help! From 6cc4bbe0f49b94eb7956debb4ac6a49cc8b91f0a Mon Sep 17 00:00:00 2001 From: Chris Hoefgen <53871533+chris-bsnake@users.noreply.github.com> Date: Tue, 4 Jan 2022 11:56:41 -0800 Subject: [PATCH 087/117] Update copyright year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 1b0a00485..ea13dce2d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Battlesnake Inc. +Copyright (c) 2022 Battlesnake Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From b3cd721ff2b54ad17f6be54d9be1a211ef9d65c6 Mon Sep 17 00:00:00 2001 From: Torben Date: Thu, 10 Feb 2022 09:13:48 -0800 Subject: [PATCH 088/117] use 'server' header to identify project (#38) --- server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server.py b/server.py index b02076adf..acca156e0 100644 --- a/server.py +++ b/server.py @@ -68,6 +68,10 @@ def end(): print(f"{data['game']['id']} END") return "ok" +@app.after_request +def identify_server(response): + response.headers["Server"] = "BattlesnakeOfficial/starter-snake-python" + return response if __name__ == "__main__": logging.getLogger("werkzeug").setLevel(logging.ERROR) From 3fb7e117a989d6c6df368482bfcbc875ab8a9555 Mon Sep 17 00:00:00 2001 From: Chris Hoefgen <53871533+chris-bsnake@users.noreply.github.com> Date: Tue, 1 Mar 2022 10:30:17 -0800 Subject: [PATCH 089/117] Removing CODEOWNERS file as it doesn't make sense in a template project --- CODEOWNERS | 1 - 1 file changed, 1 deletion(-) delete mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index ddc015ee9..000000000 --- a/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @chris-bsnake @aurorawalker @bvanvugt From 049b054e55fe8dd20622b4d017120936965f4dc0 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:29:20 -0800 Subject: [PATCH 090/117] Re-organize under src directory. --- requirements.txt | 2 +- server_logic.py => src/logic.py | 86 +++++++++++++++++++++------------ server.py => src/main.py | 37 ++++++-------- tests.py => src/tests.py | 17 +++---- 4 files changed, 77 insertions(+), 65 deletions(-) rename server_logic.py => src/logic.py (51%) rename server.py => src/main.py (55%) rename tests.py => src/tests.py (79%) diff --git a/requirements.txt b/requirements.txt index 31717cedd..f21b24b41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask==2.0.1 +Flask==2.0.3 diff --git a/server_logic.py b/src/logic.py similarity index 51% rename from server_logic.py rename to src/logic.py index 9b0c7dd4a..267e3de06 100644 --- a/server_logic.py +++ b/src/logic.py @@ -2,36 +2,26 @@ from typing import List, Dict """ -This file can be a nice home for your move logic, and to write helper functions. +This file can be a nice home for your Battlesnake's logic and helper functions. -We have started this for you, with a function to help remove the 'neck' direction +We have started this for you, and included some logic to remove your Battlesnake's 'neck' from the list of possible moves! """ - -def avoid_my_neck(my_head: Dict[str, int], my_body: List[dict], possible_moves: List[str]) -> List[str]: +def get_info() -> dict: """ - my_head: Dictionary of x/y coordinates of the Battlesnake head. - e.g. {"x": 0, "y": 0} - my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake. - e.g. [ {"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0} ] - possible_moves: List of strings. Moves to pick from. - e.g. ["up", "down", "left", "right"] + This controls your Battlesnake appearance and author permissions. + For customization options, see https://docs.battlesnake.com/references/personalization - return: The list of remaining possible_moves, with the 'neck' direction removed + TIP: If you open your Battlesnake URL in browser you should see this data. """ - my_neck = my_body[1] # The segment of body right after the head is the 'neck' - - if my_neck["x"] < my_head["x"]: # my neck is left of my head - possible_moves.remove("left") - elif my_neck["x"] > my_head["x"]: # my neck is right of my head - possible_moves.remove("right") - elif my_neck["y"] < my_head["y"]: # my neck is below my head - possible_moves.remove("down") - elif my_neck["y"] > my_head["y"]: # my neck is above my head - possible_moves.remove("up") - - return possible_moves + return { + "apiversion": "1", + "author": "", # TODO: Your Battlesnake Username + "color": "#888888", # TODO: Personalize + "head": "default", # TODO: Personalize + "tail": "default", # TODO: Personalize + } def choose_move(data: dict) -> str: @@ -46,29 +36,37 @@ def choose_move(data: dict) -> str: for each move of the game. """ - my_head = data["you"]["head"] # A dictionary of x/y coordinates like {"x": 0, "y": 0} - my_body = data["you"]["body"] # A list of x/y coordinate dictionaries like [ {"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0} ] + my_snake = data["you"] # A dictionary describing your snake's position on the board + my_head = my_snake["head"] # A dictionary of coordinates like {"x": 0, "y": 0} + my_body = my_snake["body"] # A list of coordinate dictionaries like [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0}] - # TODO: uncomment the lines below so you can see what this data looks like in your output! + # Uncomment the lines below to see what this data looks like in your output! # print(f"~~~ Turn: {data['turn']} Game Mode: {data['game']['ruleset']['name']} ~~~") # print(f"All board data this turn: {data}") + # print(f"My Battlesnake this turn is: {my_snake}") # print(f"My Battlesnakes head this turn is: {my_head}") # print(f"My Battlesnakes body this turn is: {my_body}") possible_moves = ["up", "down", "left", "right"] - # Don't allow your Battlesnake to move back in on it's own neck - possible_moves = avoid_my_neck(my_head, my_body, possible_moves) + # Step 0: Don't allow your Battlesnake to move back on it's own neck. + possible_moves = _avoid_my_neck(my_body, possible_moves) - # TODO: Using information from 'data', find the edges of the board and don't let your Battlesnake move beyond them + # TODO: Step 1 - Don't hit walls. + # Use information from `data` and `my_head` to not move beyond the game board. + # board = data['board'] # board_height = ? # board_width = ? - # TODO Using information from 'data', don't let your Battlesnake pick a move that would hit its own body + # TODO: Step 2 - Don't hit yourself. + # Use information from `my_body` to avoid moves that would collide with yourself. - # TODO: Using information from 'data', don't let your Battlesnake pick a move that would collide with another Battlesnake + # TODO: Step 3 - Don't collide with others. + # Use information from `data` to prevent your Battlesnake from colliding with others. - # TODO: Using information from 'data', make your Battlesnake move towards a piece of food on the board + # TODO: Step 4 - Find food. + # Use information in `data` to seek out and find food. + # food = data['board']['food'] # Choose a random direction from the remaining possible_moves to move in, and then return that move move = random.choice(possible_moves) @@ -77,3 +75,27 @@ def choose_move(data: dict) -> str: print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {possible_moves}") return move + + +def _avoid_my_neck(my_body: dict, possible_moves: List[str]) -> List[str]: + """ + my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake. + e.g. [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0}] + possible_moves: List of strings. Moves to pick from. + e.g. ["up", "down", "left", "right"] + + return: The list of remaining possible_moves, with the 'neck' direction removed + """ + my_head = my_body[0] # The first body coordinate is always the head + my_neck = my_body[1] # The segment of body right after the head is the 'neck' + + if my_neck["x"] < my_head["x"]: # my neck is left of my head + possible_moves.remove("left") + elif my_neck["x"] > my_head["x"]: # my neck is right of my head + possible_moves.remove("right") + elif my_neck["y"] < my_head["y"]: # my neck is below my head + possible_moves.remove("down") + elif my_neck["y"] > my_head["y"]: # my neck is above my head + possible_moves.remove("up") + + return possible_moves diff --git a/server.py b/src/main.py similarity index 55% rename from server.py rename to src/main.py index acca156e0..f629320d0 100644 --- a/server.py +++ b/src/main.py @@ -4,7 +4,7 @@ from flask import Flask from flask import request -import server_logic +import logic app = Flask(__name__) @@ -15,26 +15,16 @@ def handle_info(): """ This function is called when you register your Battlesnake on play.battlesnake.com See https://docs.battlesnake.com/guides/getting-started#step-4-register-your-battlesnake - - It controls your Battlesnake appearance and author permissions. - For customization options, see https://docs.battlesnake.com/references/personalization - - TIP: If you open your Battlesnake URL in browser you should see this data. """ print("INFO") - return { - "apiversion": "1", - "author": "", # TODO: Your Battlesnake Username - "color": "#888888", # TODO: Personalize - "head": "default", # TODO: Personalize - "tail": "default", # TODO: Personalize - } + return logic.get_info() @app.post("/start") def handle_start(): """ - This function is called everytime your snake is entered into a game. + This function is called everytime your Battlesnake enters a game. + It's purely for informational purposes, you don't have to make any decisions here. request.json contains information about the game that's about to be played. """ data = request.get_json() @@ -46,21 +36,21 @@ def handle_start(): @app.post("/move") def handle_move(): """ - This function is called on every turn of a game. It's how your snake decides where to move. + This function is called on every turn and is how your Battlesnake decides where to move. Valid moves are "up", "down", "left", or "right". """ data = request.get_json() - # TODO - look at the server_logic.py file to see how we decide what move to return! - move = server_logic.choose_move(data) + # TODO - look at the logic.py file to see how we decide what move to return! + move = logic.choose_move(data) return {"move": move} @app.post("/end") -def end(): +def handle_end(): """ - This function is called when a game your snake was in ends. + This function is called when a game your Battlesnake was in has ended. It's purely for informational purposes, you don't have to make any decisions here. """ data = request.get_json() @@ -68,14 +58,19 @@ def end(): print(f"{data['game']['id']} END") return "ok" + @app.after_request def identify_server(response): response.headers["Server"] = "BattlesnakeOfficial/starter-snake-python" return response + if __name__ == "__main__": logging.getLogger("werkzeug").setLevel(logging.ERROR) - print("Starting Battlesnake Server...") + host = "0.0.0.0" port = int(os.environ.get("PORT", "8080")) - app.run(host="0.0.0.0", port=port, debug=True) + + print(f"\nRunning Battlesnake server at http://{host}:{port}") + app.env = 'development' + app.run(host=host, port=port, debug=True) diff --git a/tests.py b/src/tests.py similarity index 79% rename from tests.py rename to src/tests.py index 47bce7ca6..a0615bf81 100644 --- a/tests.py +++ b/src/tests.py @@ -12,7 +12,7 @@ """ import unittest -from server_logic import avoid_my_neck +import logic class AvoidNeckTest(unittest.TestCase): @@ -24,12 +24,11 @@ def test_avoid_neck_all(self): single place, and thus all directions are valid. """ # Arrange - test_head = {"x": 5, "y": 5} test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 5}, {"x": 5, "y": 5}] possible_moves = ["up", "down", "left", "right"] # Act - result_moves = avoid_my_neck(test_head, test_body, possible_moves) + result_moves = logic._avoid_my_neck(test_body, possible_moves) # Assert self.assertEqual(len(result_moves), 4) @@ -37,13 +36,12 @@ def test_avoid_neck_all(self): def test_avoid_neck_left(self): # Arrange - test_head = {"x": 5, "y": 5} test_body = [{"x": 5, "y": 5}, {"x": 4, "y": 5}, {"x": 3, "y": 5}] possible_moves = ["up", "down", "left", "right"] expected = ["up", "down", "right"] # Act - result_moves = avoid_my_neck(test_head, test_body, possible_moves) + result_moves = logic._avoid_my_neck(test_body, possible_moves) # Assert self.assertEqual(len(result_moves), 3) @@ -51,13 +49,12 @@ def test_avoid_neck_left(self): def test_avoid_neck_right(self): # Arrange - test_head = {"x": 5, "y": 5} test_body = [{"x": 5, "y": 5}, {"x": 6, "y": 5}, {"x": 7, "y": 5}] possible_moves = ["up", "down", "left", "right"] expected = ["up", "down", "left"] # Act - result_moves = avoid_my_neck(test_head, test_body, possible_moves) + result_moves = logic._avoid_my_neck(test_body, possible_moves) # Assert self.assertEqual(len(result_moves), 3) @@ -65,13 +62,12 @@ def test_avoid_neck_right(self): def test_avoid_neck_up(self): # Arrange - test_head = {"x": 5, "y": 5} test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 6}, {"x": 5, "y": 7}] possible_moves = ["up", "down", "left", "right"] expected = ["down", "left", "right"] # Act - result_moves = avoid_my_neck(test_head, test_body, possible_moves) + result_moves = logic._avoid_my_neck(test_body, possible_moves) # Assert self.assertEqual(len(result_moves), 3) @@ -79,13 +75,12 @@ def test_avoid_neck_up(self): def test_avoid_neck_down(self): # Arrange - test_head = {"x": 5, "y": 5} test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}] possible_moves = ["up", "down", "left", "right"] expected = ["up", "left", "right"] # Act - result_moves = avoid_my_neck(test_head, test_body, possible_moves) + result_moves = logic._avoid_my_neck(test_body, possible_moves) # Assert self.assertEqual(len(result_moves), 3) From 591205dde20dd42b8bfc7b27f10c8fd5ab2c3586 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:58:29 -0800 Subject: [PATCH 091/117] Update replit support. --- .replit | 2 +- poetry.lock => _poetry.lock | 0 pyproject.toml => _pyproject.toml | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename poetry.lock => _poetry.lock (100%) rename pyproject.toml => _pyproject.toml (93%) diff --git a/.replit b/.replit index 890feba18..bb7d412ab 100644 --- a/.replit +++ b/.replit @@ -1,2 +1,2 @@ language = "python3" -run = "python server.py" +run = ["python", "src/main.py"] diff --git a/poetry.lock b/_poetry.lock similarity index 100% rename from poetry.lock rename to _poetry.lock diff --git a/pyproject.toml b/_pyproject.toml similarity index 93% rename from pyproject.toml rename to _pyproject.toml index 24dc0afd0..cda685b43 100644 --- a/pyproject.toml +++ b/_pyproject.toml @@ -6,4 +6,4 @@ authors = ["Battlesnake Developers "] [tool.poetry.dependencies] python = "^3.8" -Flask = "^2.0.1" +Flask = "^2.0.3" From 476801e2ad778f33880bbb780c7d0fa5dcf17c3b Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:10:30 -0800 Subject: [PATCH 092/117] Try new replit run command. --- .replit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.replit b/.replit index bb7d412ab..bf967b491 100644 --- a/.replit +++ b/.replit @@ -1,2 +1,2 @@ language = "python3" -run = ["python", "src/main.py"] +run = "python src/main.py" From 0f91a2f096a5b786392137a07dd0bbd29a79ed0e Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:38:52 -0800 Subject: [PATCH 093/117] Try to fix replit file. --- .replit | 1 + _poetry.lock => poetry.lock | 0 _pyproject.toml => pyproject.toml | 0 3 files changed, 1 insertion(+) rename _poetry.lock => poetry.lock (100%) rename _pyproject.toml => pyproject.toml (100%) diff --git a/.replit b/.replit index bf967b491..75cc604d7 100644 --- a/.replit +++ b/.replit @@ -1,2 +1,3 @@ language = "python3" run = "python src/main.py" +entrypoint = "src/logic.py" diff --git a/_poetry.lock b/poetry.lock similarity index 100% rename from _poetry.lock rename to poetry.lock diff --git a/_pyproject.toml b/pyproject.toml similarity index 100% rename from _pyproject.toml rename to pyproject.toml From c27a6962269fa101375d0c9c47cb9813185cf8f5 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:42:25 -0800 Subject: [PATCH 094/117] Update poetry.lock --- poetry.lock | 112 +++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/poetry.lock b/poetry.lock index d793b3a27..0a6fc9270 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,6 +1,6 @@ [[package]] name = "click" -version = "8.0.1" +version = "8.0.4" description = "Composable command line interface toolkit" category = "main" optional = false @@ -19,7 +19,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "flask" -version = "2.0.1" +version = "2.0.3" description = "A simple framework for building complex web applications." category = "main" optional = false @@ -37,15 +37,15 @@ dotenv = ["python-dotenv"] [[package]] name = "itsdangerous" -version = "2.0.1" +version = "2.1.0" description = "Safely pass data to untrusted environments and back." category = "main" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [[package]] name = "jinja2" -version = "3.0.1" +version = "3.0.3" description = "A very fast and expressive template engine." category = "main" optional = false @@ -59,15 +59,15 @@ i18n = ["Babel (>=2.7)"] [[package]] name = "markupsafe" -version = "2.0.1" +version = "2.1.0" description = "Safely add untrusted strings to HTML/XML markup." category = "main" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [[package]] name = "werkzeug" -version = "2.0.1" +version = "2.0.3" description = "The comprehensive WSGI web application library." category = "main" optional = false @@ -79,66 +79,72 @@ watchdog = ["watchdog"] [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "cb806ee633cb53933ae5610583ae98ba3574ebb5c0d2a215cc8602e7af663e18" +content-hash = "b4c40ed9f12705e7b3d182e0dd94fdc17a9d9d83491b0ae3efdec1b542450385" [metadata.files] click = [ - {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, - {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, + {file = "click-8.0.4-py3-none-any.whl", hash = "sha256:6a7a62563bbfabfda3a38f3023a1db4a35978c0abd76f6c9605ecd6554d6d9b1"}, + {file = "click-8.0.4.tar.gz", hash = "sha256:8458d7b1287c5fb128c90e23381cf99dcde74beaf6c7ff6384ce84d6fe090adb"}, ] colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] flask = [ - {file = "Flask-2.0.1-py3-none-any.whl", hash = "sha256:a6209ca15eb63fc9385f38e452704113d679511d9574d09b2cf9183ae7d20dc9"}, - {file = "Flask-2.0.1.tar.gz", hash = "sha256:1c4c257b1892aec1398784c63791cbaa43062f1f7aeb555c4da961b20ee68f55"}, + {file = "Flask-2.0.3-py3-none-any.whl", hash = "sha256:59da8a3170004800a2837844bfa84d49b022550616070f7cb1a659682b2e7c9f"}, + {file = "Flask-2.0.3.tar.gz", hash = "sha256:e1120c228ca2f553b470df4a5fa927ab66258467526069981b3eb0a91902687d"}, ] itsdangerous = [ - {file = "itsdangerous-2.0.1-py3-none-any.whl", hash = "sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c"}, - {file = "itsdangerous-2.0.1.tar.gz", hash = "sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"}, + {file = "itsdangerous-2.1.0-py3-none-any.whl", hash = "sha256:29285842166554469a56d427addc0843914172343784cb909695fdbe90a3e129"}, + {file = "itsdangerous-2.1.0.tar.gz", hash = "sha256:d848fcb8bc7d507c4546b448574e8a44fc4ea2ba84ebf8d783290d53e81992f5"}, ] jinja2 = [ - {file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"}, - {file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"}, + {file = "Jinja2-3.0.3-py3-none-any.whl", hash = "sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8"}, + {file = "Jinja2-3.0.3.tar.gz", hash = "sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7"}, ] markupsafe = [ - {file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:0955295dd5eec6cb6cc2fe1698f4c6d84af2e92de33fbcac4111913cd100a6ff"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:0446679737af14f45767963a1a9ef7620189912317d095f2d9ffa183a4d25d2b"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:f826e31d18b516f653fe296d967d700fddad5901ae07c622bb3705955e1faa94"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:fa130dd50c57d53368c9d59395cb5526eda596d3ffe36666cd81a44d56e48872"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:905fec760bd2fa1388bb5b489ee8ee5f7291d692638ea5f67982d968366bef9f"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-win32.whl", hash = "sha256:6c4ca60fa24e85fe25b912b01e62cb969d69a23a5d5867682dd3e80b5b02581d"}, - {file = "MarkupSafe-2.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b2f4bf27480f5e5e8ce285a8c8fd176c0b03e93dcc6646477d4630e83440c6a9"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0717a7390a68be14b8c793ba258e075c6f4ca819f15edfc2a3a027c823718567"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:6557b31b5e2c9ddf0de32a691f2312a32f77cd7681d8af66c2692efdbef84c18"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:49e3ceeabbfb9d66c3aef5af3a60cc43b85c33df25ce03d0031a608b0a8b2e3f"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:d7f9850398e85aba693bb640262d3611788b1f29a79f0c93c565694658f4071f"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:6a7fae0dd14cf60ad5ff42baa2e95727c3d81ded453457771d02b7d2b3f9c0c2"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:b7f2d075102dc8c794cbde1947378051c4e5180d52d276987b8d28a3bd58c17d"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-win32.whl", hash = "sha256:a30e67a65b53ea0a5e62fe23682cfe22712e01f453b95233b25502f7c61cb415"}, - {file = "MarkupSafe-2.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:611d1ad9a4288cf3e3c16014564df047fe08410e628f89805e475368bd304914"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:be98f628055368795d818ebf93da628541e10b75b41c559fdf36d104c5787066"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:1d609f577dc6e1aa17d746f8bd3c31aa4d258f4070d61b2aa5c4166c1539de35"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7d91275b0245b1da4d4cfa07e0faedd5b0812efc15b702576d103293e252af1b"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:01a9b8ea66f1658938f65b93a85ebe8bc016e6769611be228d797c9d998dd298"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:47ab1e7b91c098ab893b828deafa1203de86d0bc6ab587b160f78fe6c4011f75"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:97383d78eb34da7e1fa37dd273c20ad4320929af65d156e35a5e2d89566d9dfb"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-win32.whl", hash = "sha256:023cb26ec21ece8dc3907c0e8320058b2e0cb3c55cf9564da612bc325bed5e64"}, - {file = "MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:984d76483eb32f1bcb536dc27e4ad56bba4baa70be32fa87152832cdd9db0833"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:2ef54abee730b502252bcdf31b10dacb0a416229b72c18b19e24a4509f273d26"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3c112550557578c26af18a1ccc9e090bfe03832ae994343cfdacd287db6a6ae7"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:53edb4da6925ad13c07b6d26c2a852bd81e364f95301c66e930ab2aef5b5ddd8"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:f5653a225f31e113b152e56f154ccbe59eeb1c7487b39b9d9f9cdb58e6c79dc5"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:4efca8f86c54b22348a5467704e3fec767b2db12fc39c6d963168ab1d3fc9135"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:ab3ef638ace319fa26553db0624c4699e31a28bb2a835c5faca8f8acf6a5a902"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:f8ba0e8349a38d3001fae7eadded3f6606f0da5d748ee53cc1dab1d6527b9509"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-win32.whl", hash = "sha256:10f82115e21dc0dfec9ab5c0223652f7197feb168c940f3ef61563fc2d6beb74"}, - {file = "MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:693ce3f9e70a6cf7d2fb9e6c9d8b204b6b39897a2c4a1aa65728d5ac97dcc1d8"}, - {file = "MarkupSafe-2.0.1.tar.gz", hash = "sha256:594c67807fb16238b30c44bdf74f36c02cdf22d1c8cda91ef8a0ed8dabf5620a"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:3028252424c72b2602a323f70fbf50aa80a5d3aa616ea6add4ba21ae9cc9da4c"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:290b02bab3c9e216da57c1d11d2ba73a9f73a614bbdcc027d299a60cdfabb11a"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e104c0c2b4cd765b4e83909cde7ec61a1e313f8a75775897db321450e928cce"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:24c3be29abb6b34052fd26fc7a8e0a49b1ee9d282e3665e8ad09a0a68faee5b3"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:204730fd5fe2fe3b1e9ccadb2bd18ba8712b111dcabce185af0b3b5285a7c989"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d3b64c65328cb4cd252c94f83e66e3d7acf8891e60ebf588d7b493a55a1dbf26"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:96de1932237abe0a13ba68b63e94113678c379dca45afa040a17b6e1ad7ed076"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:75bb36f134883fdbe13d8e63b8675f5f12b80bb6627f7714c7d6c5becf22719f"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-win32.whl", hash = "sha256:4056f752015dfa9828dce3140dbadd543b555afb3252507348c493def166d454"}, + {file = "MarkupSafe-2.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:d4e702eea4a2903441f2735799d217f4ac1b55f7d8ad96ab7d4e25417cb0827c"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:f0eddfcabd6936558ec020130f932d479930581171368fd728efcfb6ef0dd357"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5ddea4c352a488b5e1069069f2f501006b1a4362cb906bee9a193ef1245a7a61"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:09c86c9643cceb1d87ca08cdc30160d1b7ab49a8a21564868921959bd16441b8"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a0a0abef2ca47b33fb615b491ce31b055ef2430de52c5b3fb19a4042dbc5cadb"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:736895a020e31b428b3382a7887bfea96102c529530299f426bf2e636aacec9e"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:679cbb78914ab212c49c67ba2c7396dc599a8479de51b9a87b174700abd9ea49"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:84ad5e29bf8bab3ad70fd707d3c05524862bddc54dc040982b0dbcff36481de7"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-win32.whl", hash = "sha256:8da5924cb1f9064589767b0f3fc39d03e3d0fb5aa29e0cb21d43106519bd624a"}, + {file = "MarkupSafe-2.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:454ffc1cbb75227d15667c09f164a0099159da0c1f3d2636aa648f12675491ad"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:142119fb14a1ef6d758912b25c4e803c3ff66920635c44078666fe7cc3f8f759"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b2a5a856019d2833c56a3dcac1b80fe795c95f401818ea963594b345929dffa7"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1d1fb9b2eec3c9714dd936860850300b51dbaa37404209c8d4cb66547884b7ed"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62c0285e91414f5c8f621a17b69fc0088394ccdaa961ef469e833dbff64bd5ea"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fc3150f85e2dbcf99e65238c842d1cfe69d3e7649b19864c1cc043213d9cd730"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f02cf7221d5cd915d7fa58ab64f7ee6dd0f6cddbb48683debf5d04ae9b1c2cc1"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d5653619b3eb5cbd35bfba3c12d575db2a74d15e0e1c08bf1db788069d410ce8"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:7d2f5d97fcbd004c03df8d8fe2b973fe2b14e7bfeb2cfa012eaa8759ce9a762f"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-win32.whl", hash = "sha256:3cace1837bc84e63b3fd2dfce37f08f8c18aeb81ef5cf6bb9b51f625cb4e6cd8"}, + {file = "MarkupSafe-2.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:fabbe18087c3d33c5824cb145ffca52eccd053061df1d79d4b66dafa5ad2a5ea"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:023af8c54fe63530545f70dd2a2a7eed18d07a9a77b94e8bf1e2ff7f252db9a3"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d66624f04de4af8bbf1c7f21cc06649c1c69a7f84109179add573ce35e46d448"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c532d5ab79be0199fa2658e24a02fce8542df196e60665dd322409a03db6a52c"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e67ec74fada3841b8c5f4c4f197bea916025cb9aa3fe5abf7d52b655d042f956"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:30c653fde75a6e5eb814d2a0a89378f83d1d3f502ab710904ee585c38888816c"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:961eb86e5be7d0973789f30ebcf6caab60b844203f4396ece27310295a6082c7"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:598b65d74615c021423bd45c2bc5e9b59539c875a9bdb7e5f2a6b92dfcfc268d"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:599941da468f2cf22bf90a84f6e2a65524e87be2fce844f96f2dd9a6c9d1e635"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-win32.whl", hash = "sha256:e6f7f3f41faffaea6596da86ecc2389672fa949bd035251eab26dc6697451d05"}, + {file = "MarkupSafe-2.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:b8811d48078d1cf2a6863dafb896e68406c5f513048451cd2ded0473133473c7"}, + {file = "MarkupSafe-2.1.0.tar.gz", hash = "sha256:80beaf63ddfbc64a0452b841d8036ca0611e049650e20afcb882f5d3c266d65f"}, ] werkzeug = [ - {file = "Werkzeug-2.0.1-py3-none-any.whl", hash = "sha256:6c1ec500dcdba0baa27600f6a22f6333d8b662d22027ff9f6202e3367413caa8"}, - {file = "Werkzeug-2.0.1.tar.gz", hash = "sha256:1de1db30d010ff1af14a009224ec49ab2329ad2cde454c8a708130642d579c42"}, + {file = "Werkzeug-2.0.3-py3-none-any.whl", hash = "sha256:1421ebfc7648a39a5c58c601b154165d05cf47a3cd0ccb70857cbdacf6c8f2b8"}, + {file = "Werkzeug-2.0.3.tar.gz", hash = "sha256:b863f8ff057c522164b6067c9e28b041161b4be5ba4d0daceeaa50a163822d3c"}, ] From 2b7f9b521c9851cdc1fb6d5d65f11db85eafeadb Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:43:47 -0800 Subject: [PATCH 095/117] Update heroku procfile. --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index ac9d762f1..e1e766005 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: python server.py +web: python src/main.py From d006030183992c15399f10e4125c29f772daca7c Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:54:27 -0800 Subject: [PATCH 096/117] Add pycache to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9bd6368cb..d06b87477 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.DS_Store *.pyc +__pycache__/ .cmd .idea .vscode From 475526ed6cba98b89b76fad95d9347bc747b68da Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Wed, 2 Mar 2022 15:04:43 -0800 Subject: [PATCH 097/117] Update README and inline docs. --- README.md | 14 +++++++------- src/tests.py | 8 +------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 08637457d..2ec95b377 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake using Python, and comes ready to deploy with [Replit](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. +This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake using Python, and comes ready to deploy with [Replit](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. ## Technologies Used @@ -12,7 +12,7 @@ This is a basic implementation of the [Battlesnake API](https://docs.battlesnake ## Quickstart -The [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started) provides the full set of instructions to customize, register, and create your first games with your Battlesnake! While the guide uses [Repl.it](https://repl.it) as an example host, the instructions can be modified to work with any hosting provider. You can also find advice on other hosting providers on our [Hosting Suggestions](https://docs.battlesnake.com/references/hosting-suggestions) page. +The [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started) provides the full set of instructions to customize, register, and create your first games with your Battlesnake! While the guide uses [Replit](https://repl.it) as an example host, the instructions can be modified to work with any hosting provider. You can also find advice on other hosting providers on our [Hosting Suggestions](https://docs.battlesnake.com/references/hosting-suggestions) page. ### Prerequisites @@ -22,7 +22,7 @@ The [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-start ## Customizing Your Battlesnake -Locate the `handle_info` function inside [server.py](server.py#L15). At the end of that function you should see a line that looks like this: +Locate the `get_info` function inside [logic.py](logic.py#L11). You should see a line that looks like this: ```python return { @@ -42,7 +42,7 @@ Whenever you update these values, go to the page for your Battlesnake and select On every turn of each game your Battlesnake receives information about the game board and must decide its next move. -Locate the `handle_move` function inside [server.py](server.py#L48). Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the `data` variable) and decide where your Battlesnake should move next. Your Battlesnakes move logic lives in [server_logic.py](server_logic.py#L37). This is the code you will want to edit. +Locate the `choose_move` function inside [logic.py](logic.py#L27). Possible moves are "up", "down", "left", or "right" and initially your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the game (available in the `data` variable) and decide where your Battlesnake should move next. All your Battlesnake logic lives in [logic.py](logic.py), and this is the code you will want to edit. See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. @@ -51,15 +51,15 @@ See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.8](https://www.python.org/downloads/) and running: ```shell -python server.py +python src/main.py ``` **Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install and use a port forwarding tool like [ngrok](https://ngrok.com/). See [Hosting Suggestions.](https://docs.battlesnake.com/references/hosting-suggestions#local) ## Running Tests -This Starter Project comes with a very simple test suite for you to expand! Located in `tests.py` you can run them using the following command: -```python tests.py -v``` +This Starter Project comes with a very simple test suite for you to expand! Located in [src/tests.py](src/tests.py) you can run them using the following command: +```python src/tests.py -v``` --- diff --git a/src/tests.py b/src/tests.py index a0615bf81..581a17e16 100644 --- a/src/tests.py +++ b/src/tests.py @@ -7,7 +7,7 @@ To run the unit tests, use the following command in your terminal, in the folder where this file exists: - python tests.py -v + python src/tests.py -v """ import unittest @@ -17,12 +17,6 @@ class AvoidNeckTest(unittest.TestCase): def test_avoid_neck_all(self): - """ - The possible move set should be all moves. - - In the starter position, a Battlesnake body is 'stacked' in a - single place, and thus all directions are valid. - """ # Arrange test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 5}, {"x": 5, "y": 5}] possible_moves = ["up", "down", "left", "right"] From 9247e7ad75194152ec07451184b1ec29ac149a10 Mon Sep 17 00:00:00 2001 From: david madden <58042797+DaveMadden@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:31:23 -0700 Subject: [PATCH 098/117] update replit file to import better (#39) --- .replit | 1 + 1 file changed, 1 insertion(+) diff --git a/.replit b/.replit index 75cc604d7..ddb21242b 100644 --- a/.replit +++ b/.replit @@ -1,3 +1,4 @@ language = "python3" run = "python src/main.py" entrypoint = "src/logic.py" +hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"] From 37f7da8c78224005bd96e1809bcbf067d41e0e06 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Fri, 19 Aug 2022 22:44:00 -0700 Subject: [PATCH 099/117] Rebuild python starter. --- .gitignore | 3 - .replit | 4 -- CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 8 --- Procfile | 1 - README.md | 107 ++++++++++---------------------- main.py | 99 ++++++++++++++++++++++++++++++ poetry.lock | 150 --------------------------------------------- pyproject.toml | 9 --- requirements.txt | 2 +- runtime.txt | 1 - server.py | 39 ++++++++++++ src/logic.py | 101 ------------------------------ src/main.py | 76 ----------------------- src/tests.py | 85 ------------------------- 15 files changed, 173 insertions(+), 515 deletions(-) delete mode 100644 .replit delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Procfile create mode 100644 main.py delete mode 100644 poetry.lock delete mode 100644 pyproject.toml delete mode 100644 runtime.txt create mode 100644 server.py delete mode 100644 src/logic.py delete mode 100644 src/main.py delete mode 100644 src/tests.py diff --git a/.gitignore b/.gitignore index d06b87477..ee643ad65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ *.DS_Store *.pyc __pycache__/ -.cmd -.idea -.vscode diff --git a/.replit b/.replit deleted file mode 100644 index ddb21242b..000000000 --- a/.replit +++ /dev/null @@ -1,4 +0,0 @@ -language = "python3" -run = "python src/main.py" -entrypoint = "src/logic.py" -hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"] diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index a4dbea56e..000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,3 +0,0 @@ -# Battlesnake Code of Conduct - -Please see https://docs.battlesnake.com/policies/conduct diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index b567ca45b..000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,8 +0,0 @@ -# Contributing - -We welcome contributions from the community! - -Please see https://docs.battlesnake.com/community/contributing - -We track all issues/discussions for all our open source repos at https://github.com/BattlesnakeOfficial/feedback/discussions -Any item tagged with "flag/help-wanted ✋" is a great place to start, as it highlights any issues where we'd love to get some help! diff --git a/Procfile b/Procfile deleted file mode 100644 index e1e766005..000000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: python src/main.py diff --git a/README.md b/README.md index 2ec95b377..1cb73cc1f 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,58 @@ -# Getting started with [Battlesnake](http://play.battlesnake.com?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) and Python +# Battlesnake Python Starter Project -![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) +![Battlesnake Logo](https://media.battlesnake.com/social/StarterProjectBanner-Python.png) -This is a basic implementation of the [Battlesnake API](https://docs.battlesnake.com/references/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake using Python, and comes ready to deploy with [Replit](https://repl.it) and [Heroku](https://heroku.com), or you can use any other cloud provider you'd like. +This project is a simple template that implements the [Battlesnake API](https://docs.battlesnake.com/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake, and can easily be deployed to a cloud provider of your choosing or run locally using a tool like [ngrok](https://ngrok.com/). + +**To get started, click [Use This Template](https://github.com/BattlesnakeOfficial/starter-snake-python/generate) to clone it to your own GitHub account.** ## Technologies Used -* [Python3](https://www.python.org/) +* [Python 3](https://www.python.org/) * [Flask](https://flask.palletsprojects.com/) +## Run Your Battlesnake -## Quickstart - -The [Quick Start Coding Guide](https://docs.battlesnake.com/guides/getting-started) provides the full set of instructions to customize, register, and create your first games with your Battlesnake! While the guide uses [Replit](https://repl.it) as an example host, the instructions can be modified to work with any hosting provider. You can also find advice on other hosting providers on our [Hosting Suggestions](https://docs.battlesnake.com/references/hosting-suggestions) page. - -### Prerequisites - -* A free [Battlesnake Account](https://play.battlesnake.com/?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=homepage) - ---- - -## Customizing Your Battlesnake - -Locate the `get_info` function inside [logic.py](logic.py#L11). You should see a line that looks like this: +Install dependencies using pip -```python -return { - "apiversion": "1", - "author": "", - "color": "#888888", - "head": "default", - "tail": "default", -} +```sh +pip install -r requirements.txt ``` -This function is called by the game engine periodically to make sure your Battlesnake is healthy, responding correctly, and to determine how your Battlesnake will appear on the game board. See [Battlesnake Personalization](https://docs.battlesnake.com/references/personalization) for how to customize your Battlesnake's appearance using these values. - -Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration and those changes should be reflected in the UI as well as any new games created. - -## Changing Behavior - -On every turn of each game your Battlesnake receives information about the game board and must decide its next move. - -Locate the `choose_move` function inside [logic.py](logic.py#L27). Possible moves are "up", "down", "left", or "right" and initially your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the game (available in the `data` variable) and decide where your Battlesnake should move next. All your Battlesnake logic lives in [logic.py](logic.py), and this is the code you will want to edit. - -See the [Battlesnake Game Rules](https://docs.battlesnake.com/references/rules) for more information on playing the game, moving around the board, and improving your algorithm. - -## (Optional) Running Your Battlesnake Locally - -Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing [Python 3.8](https://www.python.org/downloads/) and running: +Start your Battlesnake -```shell -python src/main.py +```sh +python main.py ``` -**Note:** You cannot create games on [play.battlesnake.com](https://play.battlesnake.com) using a locally running Battlesnake unless you install and use a port forwarding tool like [ngrok](https://ngrok.com/). See [Hosting Suggestions.](https://docs.battlesnake.com/references/hosting-suggestions#local) +You should see the following output once it is running -## Running Tests - -This Starter Project comes with a very simple test suite for you to expand! Located in [src/tests.py](src/tests.py) you can run them using the following command: -```python src/tests.py -v``` - ---- - -## Playing Battlesnake - -### Completing Challenges - -If you're looking for the Single Player Mode of Battlesnake, or something to practice with between events, check out [Challenges.](https://docs.battlesnake.com/guides/quick-start-challenges-guide) - -### Joining a Battlesnake Arena - -Once you've made your Battlesnake behave and survive on its own, you can enter it into the [Global Battlesnake Arena](https://play.battlesnake.com/arena/global) to see how it performs against other Battlesnakes worldwide. - -Arenas will regularly create new games and rank Battlesnakes based on their results. They're a good way to get regular feedback on how well your Battlesnake is performing, and a fun way to track your progress as you develop your algorithm. - -### Joining a Battlesnake League - -Want to get out there to compete and win prizes? Check out the [Quick Start League Guide](https://docs.battlesnake.com/guides/quick-start-league-guide) for information on the how and when of our competitive seasons. +```sh +Running your Battlesnake at http://0.0.0.0:8000 + * Serving Flask app 'My Battlesnake' + * Debug mode: off +``` ---- +Open [localhost:8000](http://localhost:8000) in your browser and you should see -## Resources +```json +{"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"} +``` -All documentation is available at [docs.battlesnake.com](https://docs.battlesnake.com), including detailed Guides, API References, and Tips. +## Play a Game Locally -You can also join the Battlesnake Developer Community on [Discord](https://play.battlesnake.com/discord?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=discord). We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :) +Install the [Battlesnake CLI](https://github.com/BattlesnakeOfficial/rules/tree/main/cli) +* You can [download compiled binaries here](https://github.com/BattlesnakeOfficial/rules/releases) +* or [install as a go package](https://github.com/BattlesnakeOfficial/rules/tree/main/cli#installation) (requires Go 1.18 or higher) -Check out live Battlesnake events on [Twitch](https://www.twitch.tv/battlesnakeofficial) and see what is happening when on the [Calendar.](https://play.battlesnake.com/calendar?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=calendar) +Command to run a local game -Want to contribute to Battlesnake? We have a number of open-source codebases and would love for you to get involved! Check out our page on [Contributing.](https://docs.battlesnake.com/guides/contributing) +```sh +battlesnake play -W 11 -H 11 --name 'Python Starter Project' --url http://localhost:8000 -g solo --browser +``` +## Next Steps -## Feedback +Continue with the [Battlesnake Quickstart Guide](https://docs.battlesnake.com/quickstart) to customize and improve your Battlesnake's behavior. -**Do you have an issue or suggestions for this repository?** Head over to our [Feedback Repository](https://play.battlesnake.com/feedback?utm_source=github&utm_medium=readme&utm_campaign=python_starter&utm_content=feedback) today and let us know! +**Note:** To play games on [play.battlesnake.com](https://play.battlesnake.com) you'll need to deploy your Battlesnake to a live web server OR use a port forwarding tool like [ngrok](https://ngrok.com/) to access your server locally. diff --git a/main.py b/main.py new file mode 100644 index 000000000..4ca21971e --- /dev/null +++ b/main.py @@ -0,0 +1,99 @@ +# Welcome to +# __________ __ __ .__ __ +# \______ \_____ _/ |__/ |_| | ____ ______ ____ _____ | | __ ____ +# | | _/\__ \\ __\ __\ | _/ __ \ / ___// \\__ \ | |/ // __ \ +# | | \ / __ \| | | | | |_\ ___/ \___ \| | \/ __ \| <\ ___/ +# |________/(______/__| |__| |____/\_____>______>___|__(______/__|__\\_____> +# +# This file can be a nice home for your Battlesnake logic and helper functions. +# +# To get you started we've included code to prevent your Battlesnake from moving backwards. +# For more info see docs.battlesnake.com + +import random +import typing + + +# info is called when you create your Battlesnake on play.battlesnake.com +# and controls your Battlesnake's appearance +# TIP: If you open your Battlesnake URL in a browser you should see this data +def info() -> typing.Dict: + print("INFO") + + return { + "apiversion": "1", + "author": "", # TODO: Your Battlesnake Username + "color": "#888888", # TODO: Choose color + "head": "default", # TODO: Choose head + "tail": "default", # TODO: Choose tail + } + + +# start is called when your Battlesnake begins a game +def start(game_state: typing.Dict): + print("GAME START") + + +# end is called when your Battlesnake finishes a game +def end(game_state: typing.Dict): + print("GAME OVER\n") + + +# move is called on every turn and returns your next move +# Valid moves are "up", "down", "left", or "right" +# See https://docs.battlesnake.com/api/example-move for available data +def move(game_state: typing.Dict) -> typing.Dict: + + is_move_safe = {"up": True, "down": True, "left": True, "right": True} + + # We've included code to prevent your Battlesnake from moving backwards + my_head = game_state["you"]["body"][0] # Coordinates of your head + my_neck = game_state["you"]["body"][1] # Coordinates of your "neck" + + if my_neck["x"] < my_head["x"]: # Neck is left of head, don't move left + is_move_safe["left"] = False + + elif my_neck["x"] > my_head["x"]: # Neck is right of head, don't move right + is_move_safe["right"] = False + + elif my_neck["y"] < my_head["y"]: # Neck is below head, don't move down + is_move_safe["down"] = False + + elif my_neck["y"] > my_head["y"]: # Neck is above head, don't move up + is_move_safe["up"] = False + + # TODO: Step 1 - Prevent your Battlesnake from moving out of bounds + # board_width = game_state['board']['width'] + # board_height = game_state['board']['height'] + + # TODO: Step 2 - Prevent your Battlesnake from colliding with itself + # my_body = game_state['you']['body'] + + # TODO: Step 3 - Prevent your Battlesnake from colliding with other Battlesnakes + # opponents = game_state['board']['snakes'] + + # Are there any safe moves left? + safe_moves = [] + for move, isSafe in is_move_safe.items(): + if isSafe: + safe_moves.append(move) + + if len(safe_moves) == 0: + print(f"MOVE {game_state['turn']}: No safe moves detected! Moving down") + return {"move": "down"} + + # Choose a random move from the safe ones + next_move = random.choice(safe_moves) + + # TODO: Step 4 - Move towards food instead of random, to regain health and survive longer + # food = game_state['board']['food'] + + print(f"MOVE {game_state['turn']}: {next_move}") + return {"move": next_move} + + +# Start server when `python main.py` is run +if __name__ == "__main__": + from server import run_server + + run_server({"info": info, "start": start, "move": move, "end": end}) diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index 0a6fc9270..000000000 --- a/poetry.lock +++ /dev/null @@ -1,150 +0,0 @@ -[[package]] -name = "click" -version = "8.0.4" -description = "Composable command line interface toolkit" -category = "main" -optional = false -python-versions = ">=3.6" - -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} - -[[package]] -name = "colorama" -version = "0.4.4" -description = "Cross-platform colored terminal text." -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package]] -name = "flask" -version = "2.0.3" -description = "A simple framework for building complex web applications." -category = "main" -optional = false -python-versions = ">=3.6" - -[package.dependencies] -click = ">=7.1.2" -itsdangerous = ">=2.0" -Jinja2 = ">=3.0" -Werkzeug = ">=2.0" - -[package.extras] -async = ["asgiref (>=3.2)"] -dotenv = ["python-dotenv"] - -[[package]] -name = "itsdangerous" -version = "2.1.0" -description = "Safely pass data to untrusted environments and back." -category = "main" -optional = false -python-versions = ">=3.7" - -[[package]] -name = "jinja2" -version = "3.0.3" -description = "A very fast and expressive template engine." -category = "main" -optional = false -python-versions = ">=3.6" - -[package.dependencies] -MarkupSafe = ">=2.0" - -[package.extras] -i18n = ["Babel (>=2.7)"] - -[[package]] -name = "markupsafe" -version = "2.1.0" -description = "Safely add untrusted strings to HTML/XML markup." -category = "main" -optional = false -python-versions = ">=3.7" - -[[package]] -name = "werkzeug" -version = "2.0.3" -description = "The comprehensive WSGI web application library." -category = "main" -optional = false -python-versions = ">=3.6" - -[package.extras] -watchdog = ["watchdog"] - -[metadata] -lock-version = "1.1" -python-versions = "^3.8" -content-hash = "b4c40ed9f12705e7b3d182e0dd94fdc17a9d9d83491b0ae3efdec1b542450385" - -[metadata.files] -click = [ - {file = "click-8.0.4-py3-none-any.whl", hash = "sha256:6a7a62563bbfabfda3a38f3023a1db4a35978c0abd76f6c9605ecd6554d6d9b1"}, - {file = "click-8.0.4.tar.gz", hash = "sha256:8458d7b1287c5fb128c90e23381cf99dcde74beaf6c7ff6384ce84d6fe090adb"}, -] -colorama = [ - {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, - {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, -] -flask = [ - {file = "Flask-2.0.3-py3-none-any.whl", hash = "sha256:59da8a3170004800a2837844bfa84d49b022550616070f7cb1a659682b2e7c9f"}, - {file = "Flask-2.0.3.tar.gz", hash = "sha256:e1120c228ca2f553b470df4a5fa927ab66258467526069981b3eb0a91902687d"}, -] -itsdangerous = [ - {file = "itsdangerous-2.1.0-py3-none-any.whl", hash = "sha256:29285842166554469a56d427addc0843914172343784cb909695fdbe90a3e129"}, - {file = "itsdangerous-2.1.0.tar.gz", hash = "sha256:d848fcb8bc7d507c4546b448574e8a44fc4ea2ba84ebf8d783290d53e81992f5"}, -] -jinja2 = [ - {file = "Jinja2-3.0.3-py3-none-any.whl", hash = "sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8"}, - {file = "Jinja2-3.0.3.tar.gz", hash = "sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7"}, -] -markupsafe = [ - {file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:3028252424c72b2602a323f70fbf50aa80a5d3aa616ea6add4ba21ae9cc9da4c"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:290b02bab3c9e216da57c1d11d2ba73a9f73a614bbdcc027d299a60cdfabb11a"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e104c0c2b4cd765b4e83909cde7ec61a1e313f8a75775897db321450e928cce"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:24c3be29abb6b34052fd26fc7a8e0a49b1ee9d282e3665e8ad09a0a68faee5b3"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:204730fd5fe2fe3b1e9ccadb2bd18ba8712b111dcabce185af0b3b5285a7c989"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d3b64c65328cb4cd252c94f83e66e3d7acf8891e60ebf588d7b493a55a1dbf26"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:96de1932237abe0a13ba68b63e94113678c379dca45afa040a17b6e1ad7ed076"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:75bb36f134883fdbe13d8e63b8675f5f12b80bb6627f7714c7d6c5becf22719f"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-win32.whl", hash = "sha256:4056f752015dfa9828dce3140dbadd543b555afb3252507348c493def166d454"}, - {file = "MarkupSafe-2.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:d4e702eea4a2903441f2735799d217f4ac1b55f7d8ad96ab7d4e25417cb0827c"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:f0eddfcabd6936558ec020130f932d479930581171368fd728efcfb6ef0dd357"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5ddea4c352a488b5e1069069f2f501006b1a4362cb906bee9a193ef1245a7a61"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:09c86c9643cceb1d87ca08cdc30160d1b7ab49a8a21564868921959bd16441b8"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a0a0abef2ca47b33fb615b491ce31b055ef2430de52c5b3fb19a4042dbc5cadb"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:736895a020e31b428b3382a7887bfea96102c529530299f426bf2e636aacec9e"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:679cbb78914ab212c49c67ba2c7396dc599a8479de51b9a87b174700abd9ea49"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:84ad5e29bf8bab3ad70fd707d3c05524862bddc54dc040982b0dbcff36481de7"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-win32.whl", hash = "sha256:8da5924cb1f9064589767b0f3fc39d03e3d0fb5aa29e0cb21d43106519bd624a"}, - {file = "MarkupSafe-2.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:454ffc1cbb75227d15667c09f164a0099159da0c1f3d2636aa648f12675491ad"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:142119fb14a1ef6d758912b25c4e803c3ff66920635c44078666fe7cc3f8f759"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b2a5a856019d2833c56a3dcac1b80fe795c95f401818ea963594b345929dffa7"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1d1fb9b2eec3c9714dd936860850300b51dbaa37404209c8d4cb66547884b7ed"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62c0285e91414f5c8f621a17b69fc0088394ccdaa961ef469e833dbff64bd5ea"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fc3150f85e2dbcf99e65238c842d1cfe69d3e7649b19864c1cc043213d9cd730"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f02cf7221d5cd915d7fa58ab64f7ee6dd0f6cddbb48683debf5d04ae9b1c2cc1"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d5653619b3eb5cbd35bfba3c12d575db2a74d15e0e1c08bf1db788069d410ce8"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:7d2f5d97fcbd004c03df8d8fe2b973fe2b14e7bfeb2cfa012eaa8759ce9a762f"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-win32.whl", hash = "sha256:3cace1837bc84e63b3fd2dfce37f08f8c18aeb81ef5cf6bb9b51f625cb4e6cd8"}, - {file = "MarkupSafe-2.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:fabbe18087c3d33c5824cb145ffca52eccd053061df1d79d4b66dafa5ad2a5ea"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:023af8c54fe63530545f70dd2a2a7eed18d07a9a77b94e8bf1e2ff7f252db9a3"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d66624f04de4af8bbf1c7f21cc06649c1c69a7f84109179add573ce35e46d448"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c532d5ab79be0199fa2658e24a02fce8542df196e60665dd322409a03db6a52c"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e67ec74fada3841b8c5f4c4f197bea916025cb9aa3fe5abf7d52b655d042f956"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:30c653fde75a6e5eb814d2a0a89378f83d1d3f502ab710904ee585c38888816c"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:961eb86e5be7d0973789f30ebcf6caab60b844203f4396ece27310295a6082c7"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:598b65d74615c021423bd45c2bc5e9b59539c875a9bdb7e5f2a6b92dfcfc268d"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:599941da468f2cf22bf90a84f6e2a65524e87be2fce844f96f2dd9a6c9d1e635"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-win32.whl", hash = "sha256:e6f7f3f41faffaea6596da86ecc2389672fa949bd035251eab26dc6697451d05"}, - {file = "MarkupSafe-2.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:b8811d48078d1cf2a6863dafb896e68406c5f513048451cd2ded0473133473c7"}, - {file = "MarkupSafe-2.1.0.tar.gz", hash = "sha256:80beaf63ddfbc64a0452b841d8036ca0611e049650e20afcb882f5d3c266d65f"}, -] -werkzeug = [ - {file = "Werkzeug-2.0.3-py3-none-any.whl", hash = "sha256:1421ebfc7648a39a5c58c601b154165d05cf47a3cd0ccb70857cbdacf6c8f2b8"}, - {file = "Werkzeug-2.0.3.tar.gz", hash = "sha256:b863f8ff057c522164b6067c9e28b041161b4be5ba4d0daceeaa50a163822d3c"}, -] diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index cda685b43..000000000 --- a/pyproject.toml +++ /dev/null @@ -1,9 +0,0 @@ -[tool.poetry] -name = "starter-snake-python" -version = "1.0.0" -description = "A simple Battlesnake written in Python" -authors = ["Battlesnake Developers "] - -[tool.poetry.dependencies] -python = "^3.8" -Flask = "^2.0.3" diff --git a/requirements.txt b/requirements.txt index f21b24b41..c9edc1a7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask==2.0.3 +Flask==2.2.2 diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index 9bff0e00f..000000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -python-3.9.6 diff --git a/server.py b/server.py new file mode 100644 index 000000000..aa6bbec47 --- /dev/null +++ b/server.py @@ -0,0 +1,39 @@ +import logging +import os +import typing + +from flask import Flask +from flask import request + + +def run_server(handlers: typing.Dict): + app = Flask("My Battlesnake") + + @app.get("/") + def on_info(): + return handlers["info"]() + + @app.post("/start") + def on_start(): + game_state = request.get_json() + handlers["start"](game_state) + return "ok" + + @app.post("/move") + def on_move(): + game_state = request.get_json() + return handlers["move"](game_state) + + @app.post("/end") + def on_end(): + game_state = request.get_json() + handlers["end"](game_state) + return "ok" + + host = "0.0.0.0" + port = int(os.environ.get("PORT", "8000")) + + logging.getLogger("werkzeug").setLevel(logging.ERROR) + + print(f"\nRunning Battlesnake at http://{host}:{port}") + app.run(host=host, port=port) diff --git a/src/logic.py b/src/logic.py deleted file mode 100644 index 267e3de06..000000000 --- a/src/logic.py +++ /dev/null @@ -1,101 +0,0 @@ -import random -from typing import List, Dict - -""" -This file can be a nice home for your Battlesnake's logic and helper functions. - -We have started this for you, and included some logic to remove your Battlesnake's 'neck' -from the list of possible moves! -""" - -def get_info() -> dict: - """ - This controls your Battlesnake appearance and author permissions. - For customization options, see https://docs.battlesnake.com/references/personalization - - TIP: If you open your Battlesnake URL in browser you should see this data. - """ - return { - "apiversion": "1", - "author": "", # TODO: Your Battlesnake Username - "color": "#888888", # TODO: Personalize - "head": "default", # TODO: Personalize - "tail": "default", # TODO: Personalize - } - - -def choose_move(data: dict) -> str: - """ - data: Dictionary of all Game Board data as received from the Battlesnake Engine. - For a full example of 'data', see https://docs.battlesnake.com/references/api/sample-move-request - - return: A String, the single move to make. One of "up", "down", "left" or "right". - - Use the information in 'data' to decide your next move. The 'data' variable can be interacted - with as a Python Dictionary, and contains all of the information about the Battlesnake board - for each move of the game. - - """ - my_snake = data["you"] # A dictionary describing your snake's position on the board - my_head = my_snake["head"] # A dictionary of coordinates like {"x": 0, "y": 0} - my_body = my_snake["body"] # A list of coordinate dictionaries like [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0}] - - # Uncomment the lines below to see what this data looks like in your output! - # print(f"~~~ Turn: {data['turn']} Game Mode: {data['game']['ruleset']['name']} ~~~") - # print(f"All board data this turn: {data}") - # print(f"My Battlesnake this turn is: {my_snake}") - # print(f"My Battlesnakes head this turn is: {my_head}") - # print(f"My Battlesnakes body this turn is: {my_body}") - - possible_moves = ["up", "down", "left", "right"] - - # Step 0: Don't allow your Battlesnake to move back on it's own neck. - possible_moves = _avoid_my_neck(my_body, possible_moves) - - # TODO: Step 1 - Don't hit walls. - # Use information from `data` and `my_head` to not move beyond the game board. - # board = data['board'] - # board_height = ? - # board_width = ? - - # TODO: Step 2 - Don't hit yourself. - # Use information from `my_body` to avoid moves that would collide with yourself. - - # TODO: Step 3 - Don't collide with others. - # Use information from `data` to prevent your Battlesnake from colliding with others. - - # TODO: Step 4 - Find food. - # Use information in `data` to seek out and find food. - # food = data['board']['food'] - - # Choose a random direction from the remaining possible_moves to move in, and then return that move - move = random.choice(possible_moves) - # TODO: Explore new strategies for picking a move that are better than random - - print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {possible_moves}") - - return move - - -def _avoid_my_neck(my_body: dict, possible_moves: List[str]) -> List[str]: - """ - my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake. - e.g. [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 0}] - possible_moves: List of strings. Moves to pick from. - e.g. ["up", "down", "left", "right"] - - return: The list of remaining possible_moves, with the 'neck' direction removed - """ - my_head = my_body[0] # The first body coordinate is always the head - my_neck = my_body[1] # The segment of body right after the head is the 'neck' - - if my_neck["x"] < my_head["x"]: # my neck is left of my head - possible_moves.remove("left") - elif my_neck["x"] > my_head["x"]: # my neck is right of my head - possible_moves.remove("right") - elif my_neck["y"] < my_head["y"]: # my neck is below my head - possible_moves.remove("down") - elif my_neck["y"] > my_head["y"]: # my neck is above my head - possible_moves.remove("up") - - return possible_moves diff --git a/src/main.py b/src/main.py deleted file mode 100644 index f629320d0..000000000 --- a/src/main.py +++ /dev/null @@ -1,76 +0,0 @@ -import logging -import os - -from flask import Flask -from flask import request - -import logic - - -app = Flask(__name__) - - -@app.get("/") -def handle_info(): - """ - This function is called when you register your Battlesnake on play.battlesnake.com - See https://docs.battlesnake.com/guides/getting-started#step-4-register-your-battlesnake - """ - print("INFO") - return logic.get_info() - - -@app.post("/start") -def handle_start(): - """ - This function is called everytime your Battlesnake enters a game. - It's purely for informational purposes, you don't have to make any decisions here. - request.json contains information about the game that's about to be played. - """ - data = request.get_json() - - print(f"{data['game']['id']} START") - return "ok" - - -@app.post("/move") -def handle_move(): - """ - This function is called on every turn and is how your Battlesnake decides where to move. - Valid moves are "up", "down", "left", or "right". - """ - data = request.get_json() - - # TODO - look at the logic.py file to see how we decide what move to return! - move = logic.choose_move(data) - - return {"move": move} - - -@app.post("/end") -def handle_end(): - """ - This function is called when a game your Battlesnake was in has ended. - It's purely for informational purposes, you don't have to make any decisions here. - """ - data = request.get_json() - - print(f"{data['game']['id']} END") - return "ok" - - -@app.after_request -def identify_server(response): - response.headers["Server"] = "BattlesnakeOfficial/starter-snake-python" - return response - - -if __name__ == "__main__": - logging.getLogger("werkzeug").setLevel(logging.ERROR) - - host = "0.0.0.0" - port = int(os.environ.get("PORT", "8080")) - - print(f"\nRunning Battlesnake server at http://{host}:{port}") - app.env = 'development' - app.run(host=host, port=port, debug=True) diff --git a/src/tests.py b/src/tests.py deleted file mode 100644 index 581a17e16..000000000 --- a/src/tests.py +++ /dev/null @@ -1,85 +0,0 @@ -""" -Starter Unit Tests using the built-in Python unittest library. -See https://docs.python.org/3/library/unittest.html - -You can expand these to cover more cases! - -To run the unit tests, use the following command in your terminal, -in the folder where this file exists: - - python src/tests.py -v - -""" -import unittest - -import logic - - -class AvoidNeckTest(unittest.TestCase): - def test_avoid_neck_all(self): - # Arrange - test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 5}, {"x": 5, "y": 5}] - possible_moves = ["up", "down", "left", "right"] - - # Act - result_moves = logic._avoid_my_neck(test_body, possible_moves) - - # Assert - self.assertEqual(len(result_moves), 4) - self.assertEqual(possible_moves, result_moves) - - def test_avoid_neck_left(self): - # Arrange - test_body = [{"x": 5, "y": 5}, {"x": 4, "y": 5}, {"x": 3, "y": 5}] - possible_moves = ["up", "down", "left", "right"] - expected = ["up", "down", "right"] - - # Act - result_moves = logic._avoid_my_neck(test_body, possible_moves) - - # Assert - self.assertEqual(len(result_moves), 3) - self.assertEqual(expected, result_moves) - - def test_avoid_neck_right(self): - # Arrange - test_body = [{"x": 5, "y": 5}, {"x": 6, "y": 5}, {"x": 7, "y": 5}] - possible_moves = ["up", "down", "left", "right"] - expected = ["up", "down", "left"] - - # Act - result_moves = logic._avoid_my_neck(test_body, possible_moves) - - # Assert - self.assertEqual(len(result_moves), 3) - self.assertEqual(expected, result_moves) - - def test_avoid_neck_up(self): - # Arrange - test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 6}, {"x": 5, "y": 7}] - possible_moves = ["up", "down", "left", "right"] - expected = ["down", "left", "right"] - - # Act - result_moves = logic._avoid_my_neck(test_body, possible_moves) - - # Assert - self.assertEqual(len(result_moves), 3) - self.assertEqual(expected, result_moves) - - def test_avoid_neck_down(self): - # Arrange - test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}] - possible_moves = ["up", "down", "left", "right"] - expected = ["up", "left", "right"] - - # Act - result_moves = logic._avoid_my_neck(test_body, possible_moves) - - # Assert - self.assertEqual(len(result_moves), 3) - self.assertEqual(expected, result_moves) - - -if __name__ == "__main__": - unittest.main() From c343b8aae42e30a1574d06181516db6e708929d0 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:52:58 -0700 Subject: [PATCH 100/117] Add Dockerfile --- Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..8deae9929 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.10.6-slim + +# Install app +COPY . /usr/app +WORKDIR /usr/app + +# Install dependencies +RUN pip install --upgrade pip && pip install -r requirements.txt + +# Run Battlesnake +CMD [ "python", "main.py" ] From 2130fda5abce84f0b8a98b5d8c3d1e22c102b0d2 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:53:43 -0700 Subject: [PATCH 101/117] Update to latest README. --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1cb73cc1f..bf1766276 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ # Battlesnake Python Starter Project -![Battlesnake Logo](https://media.battlesnake.com/social/StarterProjectBanner-Python.png) +### An official Battlesnake template written in Python. Get started at play.battlesnake.com. -This project is a simple template that implements the [Battlesnake API](https://docs.battlesnake.com/api) in Python. It's a great starting point for anyone wanting to program their first Battlesnake, and can easily be deployed to a cloud provider of your choosing or run locally using a tool like [ngrok](https://ngrok.com/). +![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) -**To get started, click [Use This Template](https://github.com/BattlesnakeOfficial/starter-snake-python/generate) to clone it to your own GitHub account.** +This project is a great starting point for anyone wanting to program their first Battlesnake in Python. It can be run locally or easily deployed to a cloud provider of your choosing. See the [Battlesnake API Docs](https://docs.battlesnake.com/api) for more detail. + +[![Run on Replit](https://repl.it/badge/github/BattlesnakeOfficial/starter-snake-python)](https://replit.com/@Battlesnake/starter-snake-python) ## Technologies Used -* [Python 3](https://www.python.org/) -* [Flask](https://flask.palletsprojects.com/) +This project uses [Python 3](https://www.python.org/) and [Flask](https://flask.palletsprojects.com/). It also comes with an optional [Dockerfile](https://docs.docker.com/engine/reference/builder/) to help with deployment. ## Run Your Battlesnake From fa8d9048d555ca5ad3efa01c88795e86d074c385 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 22 Aug 2022 11:58:27 -0700 Subject: [PATCH 102/117] Add server header --- server.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index aa6bbec47..93f85adbb 100644 --- a/server.py +++ b/server.py @@ -7,7 +7,7 @@ def run_server(handlers: typing.Dict): - app = Flask("My Battlesnake") + app = Flask("Battlesnake") @app.get("/") def on_info(): @@ -30,6 +30,13 @@ def on_end(): handlers["end"](game_state) return "ok" + @app.after_request + def identify_server(response): + response.headers.set( + "server", "battlesnake/github/starter-snake-python" + ) + return response + host = "0.0.0.0" port = int(os.environ.get("PORT", "8000")) From 4aef55791b80e915b964164847402809c33d33d2 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:02:23 -0700 Subject: [PATCH 103/117] Update link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf1766276..76787fbce 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Battlesnake Python Starter Project -### An official Battlesnake template written in Python. Get started at play.battlesnake.com. +### An official Battlesnake template written in Python. Get started at [play.battlesnake.com](https://play.battlesnake.com). ![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) From ed1bc03d0c33e5c11b316ddc6597406f64f3dd24 Mon Sep 17 00:00:00 2001 From: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> Date: Thu, 25 Aug 2022 06:35:35 -0700 Subject: [PATCH 104/117] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 76787fbce..35d90831c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Battlesnake Python Starter Project -### An official Battlesnake template written in Python. Get started at [play.battlesnake.com](https://play.battlesnake.com). +An official Battlesnake template written in Python. Get started at [play.battlesnake.com](https://play.battlesnake.com). ![Battlesnake Logo](https://media.battlesnake.com/social/StarterSnakeGitHubRepos_Python.png) From 4bd218a8a0287b50234273139bd7b17fde5a1596 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 17:49:24 -0700 Subject: [PATCH 105/117] Bump flask from 2.2.2 to 2.3.2 (#45) Bumps [flask](https://github.com/pallets/flask) from 2.2.2 to 2.3.2. - [Release notes](https://github.com/pallets/flask/releases) - [Changelog](https://github.com/pallets/flask/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/flask/compare/2.2.2...2.3.2) --- updated-dependencies: - dependency-name: flask dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c9edc1a7f..5aad892a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask==2.2.2 +Flask==2.3.2 From 3319f0d3c1d90756f10ee642f9237a2cc86b0248 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sat, 10 Jan 2026 10:10:00 +0100 Subject: [PATCH 106/117] Ignore Package --- .gitignore | 1 + game_state_example.txt | 20 ++++++++++++++++++++ run_local_game.txt | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 game_state_example.txt create mode 100644 run_local_game.txt diff --git a/.gitignore b/.gitignore index ee643ad65..71abc8967 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.DS_Store *.pyc __pycache__/ +__init__.py \ No newline at end of file diff --git a/game_state_example.txt b/game_state_example.txt new file mode 100644 index 000000000..f4f8455a5 --- /dev/null +++ b/game_state_example.txt @@ -0,0 +1,20 @@ + +{'game': {'id': 'e47d606f-0cbf-4485-955a-dcd76d89a074', +'ruleset': {'name': 'solo', 'version': 'cli', 'settings': {'foodSpawnChance': 15, 'minimumFood': 1, 'hazardDamagePerTurn': 14, 'hazardMap': '', 'hazardMapAuthor': '', 'royale': {'shrinkEveryNTurns': 25}, +'squad': {'allowBodyCollisions': False, 'sharedElimination': False, 'sharedHealth': False, 'sharedLength': False}}}, +'map': 'standard', +'timeout': 500, 'source': ''}, +'turn': 65, +'board': {'height': 11, 'width': 11, 'snakes': [{'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', +'name': 'Python Starter Project', +'latency': '9', +'health': 84, +'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], +'head': {'x': 2, 'y': 1}, +'length': 7, +'shout': '', +'squad': '', +'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}], +'food': [{'x': 5, 'y': 5}, {'x': 10, 'y': 9}, {'x': 9, 'y': 9}, {'x': 8, 'y': 2}, {'x': 10, 'y': 3}, {'x': 1, 'y': 3}, {'x': 4, 'y': 1}, {'x': 6, 'y': 2}], +'hazards': []}, +'you': {'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', 'name': 'Python Starter Project', 'latency': '0', 'health': 84, 'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], 'head': {'x': 2, 'y': 1}, 'length': 7, 'shout': '', 'squad': '', 'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}} \ No newline at end of file diff --git a/run_local_game.txt b/run_local_game.txt new file mode 100644 index 000000000..c94b9236e --- /dev/null +++ b/run_local_game.txt @@ -0,0 +1,6 @@ + +with opponent: +battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --name "Opponent" --url http://0.0.0.0:8001 --browser + +without opponent: +battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --browser \ No newline at end of file From 232e7f8c5f229918c50054d470a824509d63e8b3 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sat, 10 Jan 2026 10:12:13 +0100 Subject: [PATCH 107/117] Remove old files --- game_state_example.txt | 20 -------------------- run_local_game.txt | 6 ------ 2 files changed, 26 deletions(-) delete mode 100644 game_state_example.txt delete mode 100644 run_local_game.txt diff --git a/game_state_example.txt b/game_state_example.txt deleted file mode 100644 index f4f8455a5..000000000 --- a/game_state_example.txt +++ /dev/null @@ -1,20 +0,0 @@ - -{'game': {'id': 'e47d606f-0cbf-4485-955a-dcd76d89a074', -'ruleset': {'name': 'solo', 'version': 'cli', 'settings': {'foodSpawnChance': 15, 'minimumFood': 1, 'hazardDamagePerTurn': 14, 'hazardMap': '', 'hazardMapAuthor': '', 'royale': {'shrinkEveryNTurns': 25}, -'squad': {'allowBodyCollisions': False, 'sharedElimination': False, 'sharedHealth': False, 'sharedLength': False}}}, -'map': 'standard', -'timeout': 500, 'source': ''}, -'turn': 65, -'board': {'height': 11, 'width': 11, 'snakes': [{'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', -'name': 'Python Starter Project', -'latency': '9', -'health': 84, -'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], -'head': {'x': 2, 'y': 1}, -'length': 7, -'shout': '', -'squad': '', -'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}], -'food': [{'x': 5, 'y': 5}, {'x': 10, 'y': 9}, {'x': 9, 'y': 9}, {'x': 8, 'y': 2}, {'x': 10, 'y': 3}, {'x': 1, 'y': 3}, {'x': 4, 'y': 1}, {'x': 6, 'y': 2}], -'hazards': []}, -'you': {'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', 'name': 'Python Starter Project', 'latency': '0', 'health': 84, 'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], 'head': {'x': 2, 'y': 1}, 'length': 7, 'shout': '', 'squad': '', 'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}} \ No newline at end of file diff --git a/run_local_game.txt b/run_local_game.txt deleted file mode 100644 index c94b9236e..000000000 --- a/run_local_game.txt +++ /dev/null @@ -1,6 +0,0 @@ - -with opponent: -battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --name "Opponent" --url http://0.0.0.0:8001 --browser - -without opponent: -battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --browser \ No newline at end of file From 8b7650a862088085bb7efbdd4550472b7626522f Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 10:58:46 +0100 Subject: [PATCH 108/117] Restore Files --- game_state_example.txt | 20 ++++++++++++++++++++ run_local_game.txt | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 game_state_example.txt create mode 100644 run_local_game.txt diff --git a/game_state_example.txt b/game_state_example.txt new file mode 100644 index 000000000..f4f8455a5 --- /dev/null +++ b/game_state_example.txt @@ -0,0 +1,20 @@ + +{'game': {'id': 'e47d606f-0cbf-4485-955a-dcd76d89a074', +'ruleset': {'name': 'solo', 'version': 'cli', 'settings': {'foodSpawnChance': 15, 'minimumFood': 1, 'hazardDamagePerTurn': 14, 'hazardMap': '', 'hazardMapAuthor': '', 'royale': {'shrinkEveryNTurns': 25}, +'squad': {'allowBodyCollisions': False, 'sharedElimination': False, 'sharedHealth': False, 'sharedLength': False}}}, +'map': 'standard', +'timeout': 500, 'source': ''}, +'turn': 65, +'board': {'height': 11, 'width': 11, 'snakes': [{'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', +'name': 'Python Starter Project', +'latency': '9', +'health': 84, +'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], +'head': {'x': 2, 'y': 1}, +'length': 7, +'shout': '', +'squad': '', +'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}], +'food': [{'x': 5, 'y': 5}, {'x': 10, 'y': 9}, {'x': 9, 'y': 9}, {'x': 8, 'y': 2}, {'x': 10, 'y': 3}, {'x': 1, 'y': 3}, {'x': 4, 'y': 1}, {'x': 6, 'y': 2}], +'hazards': []}, +'you': {'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', 'name': 'Python Starter Project', 'latency': '0', 'health': 84, 'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], 'head': {'x': 2, 'y': 1}, 'length': 7, 'shout': '', 'squad': '', 'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}} \ No newline at end of file diff --git a/run_local_game.txt b/run_local_game.txt new file mode 100644 index 000000000..c94b9236e --- /dev/null +++ b/run_local_game.txt @@ -0,0 +1,6 @@ + +with opponent: +battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --name "Opponent" --url http://0.0.0.0:8001 --browser + +without opponent: +battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --browser \ No newline at end of file From 67a26828ac1776a36dfadcf69df428d731f0e5ff Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:01:25 +0100 Subject: [PATCH 109/117] Delete not relevant files from git --- game_state_example.txt | 20 -------------------- run_local_game.txt | 6 ------ 2 files changed, 26 deletions(-) delete mode 100644 game_state_example.txt delete mode 100644 run_local_game.txt diff --git a/game_state_example.txt b/game_state_example.txt deleted file mode 100644 index f4f8455a5..000000000 --- a/game_state_example.txt +++ /dev/null @@ -1,20 +0,0 @@ - -{'game': {'id': 'e47d606f-0cbf-4485-955a-dcd76d89a074', -'ruleset': {'name': 'solo', 'version': 'cli', 'settings': {'foodSpawnChance': 15, 'minimumFood': 1, 'hazardDamagePerTurn': 14, 'hazardMap': '', 'hazardMapAuthor': '', 'royale': {'shrinkEveryNTurns': 25}, -'squad': {'allowBodyCollisions': False, 'sharedElimination': False, 'sharedHealth': False, 'sharedLength': False}}}, -'map': 'standard', -'timeout': 500, 'source': ''}, -'turn': 65, -'board': {'height': 11, 'width': 11, 'snakes': [{'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', -'name': 'Python Starter Project', -'latency': '9', -'health': 84, -'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], -'head': {'x': 2, 'y': 1}, -'length': 7, -'shout': '', -'squad': '', -'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}], -'food': [{'x': 5, 'y': 5}, {'x': 10, 'y': 9}, {'x': 9, 'y': 9}, {'x': 8, 'y': 2}, {'x': 10, 'y': 3}, {'x': 1, 'y': 3}, {'x': 4, 'y': 1}, {'x': 6, 'y': 2}], -'hazards': []}, -'you': {'id': '46580b5d-c4e1-4901-b6f1-53a3410f818c', 'name': 'Python Starter Project', 'latency': '0', 'health': 84, 'body': [{'x': 2, 'y': 1}, {'x': 3, 'y': 1}, {'x': 3, 'y': 2}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}, {'x': 0, 'y': 2}, {'x': 0, 'y': 1}], 'head': {'x': 2, 'y': 1}, 'length': 7, 'shout': '', 'squad': '', 'customizations': {'color': '#FF0000', 'head': 'default', 'tail': 'default'}}} \ No newline at end of file diff --git a/run_local_game.txt b/run_local_game.txt deleted file mode 100644 index c94b9236e..000000000 --- a/run_local_game.txt +++ /dev/null @@ -1,6 +0,0 @@ - -with opponent: -battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --name "Opponent" --url http://0.0.0.0:8001 --browser - -without opponent: -battlesnake play -W 11 -H 11 --name "Super Meister" --url http://0.0.0.0:8000 --browser \ No newline at end of file From aa8ecea944118a0fa262e2dc822ad7212c31b0b7 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:03:34 +0100 Subject: [PATCH 110/117] Update git Ignore --- .gitignore | 3 ++- tests/__init__.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py diff --git a/.gitignore b/.gitignore index 71abc8967..9651198f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.DS_Store *.pyc __pycache__/ -__init__.py \ No newline at end of file +game_state_example.txt +run_local_game.txt \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..090eecd7e --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,2 @@ + +#__init__.py \ No newline at end of file From e1cea59c110c0889c9ba276c5e9d9166d0ffe654 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:08:07 +0100 Subject: [PATCH 111/117] Added test Module --- tests/test_not_backward.py | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/test_not_backward.py diff --git a/tests/test_not_backward.py b/tests/test_not_backward.py new file mode 100644 index 000000000..89e31df86 --- /dev/null +++ b/tests/test_not_backward.py @@ -0,0 +1,44 @@ + +import unittest +from unittest.mock import patch +from main import move + +class TestNotBackward(unittest.TestCase): + + def test_not_down(self): + + game_state = {"you": {"id": "my", "head": {"x": 2, "y": 2} ,"body": [{"x": 2, "y": 2}, {"x": 2, "y": 3}, {"x": 2, "y": 4}],"length": 3}, + "board": {"snakes": [], "food": [{"x": 10, "y": 10}]}, + "turn": 1 + } + + with patch.object(Move, "not_wall_collision", return_value = "patch not_wall_collision") as patch_1: + + with patch.object(Move, "not_itself_collision", return_value = "patch not_itself_collision") as patch_2: + + with patch.object(Move, "not_enemy_collision", return_value = "Patch not_enemy_collision") as patch_3: + + bot = Move() + + bot.choose_move(game_state) + + is_safe = bot.is_move_safe["up"]["is_safe"] + + self.assertFalse(is_safe) + + def test_not_left(self): + + game_state = {"you": {"id": "my", "head": {"x": 2, "y": 2} ,"body": [{"x": 2, "y": 2}, {"x": 1, "y": 2}, {"x": 0, "y": 2}],"length": 3}, + "board": {"snakes": [], "food": [{"x": 10, "y": 10}]}, + "turn": 1 + } + + move(game_state) + + is_safe = bot.is_move_safe["left"]["is_safe"] + + self.assertFalse(is_safe) + +if __name__ == "__main__": + + unittest.main() \ No newline at end of file From eaa423270bf5bd1bc7dfb9a0609630f8c3200e9d Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:10:03 +0100 Subject: [PATCH 112/117] Added class Move --- move.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 move.py diff --git a/move.py b/move.py new file mode 100644 index 000000000..e69de29bb From 422905757c35ca526a81dcbd8daa96718cf45489 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:45:15 +0100 Subject: [PATCH 113/117] Add Feature not_backward in Move() --- move.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/move.py b/move.py index e69de29bb..f0d860978 100644 --- a/move.py +++ b/move.py @@ -0,0 +1,28 @@ +import random + +class Move(): + + def __init__(self): + + self.is_move_safe = {"up": {"is_safe": True, "priority": 0}, + "down": {"is_safe": True, "priority": 0}, + "left": {"is_safe": True, "priority": 0}, + "right": {"is_safe": True, "priority": 0}} + + def not_backward(self, game_state): + + # We've included code to prevent your Battlesnake from moving backwards + my_head = game_state["you"]["body"][0] # Coordinates of your head + my_neck = game_state["you"]["body"][1] # Coordinates of your "neck" + + if my_neck["x"] < my_head["x"]: # Neck is left of head, don't move left + self.is_move_safe["left"]["is_safe"] = False + + elif my_neck["x"] > my_head["x"]: # Neck is right of head, don't move right + self.is_move_safe["right"]["is_safe"] = False + + elif my_neck["y"] < my_head["y"]: # Neck is below head, don't move down + self.is_move_safe["down"]["is_safe"] = False + + elif my_neck["y"] > my_head["y"]: # Neck is above head, don't move up + self.is_move_safe["up"]["is_safe"] = False \ No newline at end of file From fb4a4766bef2da49212eff17627b817123ccf832 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 11:50:04 +0100 Subject: [PATCH 114/117] Added choose_move in Move() --- move.py | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/move.py b/move.py index f0d860978..fd7f5fbea 100644 --- a/move.py +++ b/move.py @@ -4,10 +4,10 @@ class Move(): def __init__(self): - self.is_move_safe = {"up": {"is_safe": True, "priority": 0}, - "down": {"is_safe": True, "priority": 0}, - "left": {"is_safe": True, "priority": 0}, - "right": {"is_safe": True, "priority": 0}} + self.is_move_safe = {"up": {"is_safe": True}, + "down": {"is_safe": True}, + "left": {"is_safe": True}, + "right": {"is_safe": True}} def not_backward(self, game_state): @@ -25,4 +25,38 @@ def not_backward(self, game_state): self.is_move_safe["down"]["is_safe"] = False elif my_neck["y"] > my_head["y"]: # Neck is above head, don't move up - self.is_move_safe["up"]["is_safe"] = False \ No newline at end of file + self.is_move_safe["up"]["is_safe"] = False + + def choose_move(self, game_state): + + self.not_backward(game_state) + + # Are there any safe moves left? + safe_moves = [] + for move , data in self.is_move_safe.items(): + + if data["is_safe"] == True: + + safe_moves.append(move) + + if len(safe_moves) == 0: + print(f"MOVE {game_state['turn']}: No safe moves detected! Moving down") + return {"move": "down"} + + # Choose a random move from the safe ones + next_move = random.choice(safe_moves) + + return {"move": next_move} + +# TODO: Step 1 - Prevent your Battlesnake from moving out of bounds +# board_width = game_state['board']['width'] +# board_height = game_state['board']['height'] + +# TODO: Step 2 - Prevent your Battlesnake from colliding with itself +# my_body = game_state['you']['body'] + +# TODO: Step 3 - Prevent your Battlesnake from colliding with other Battlesnakes +# opponents = game_state['board']['snakes'] + +# TODO: Step 4 - Move towards food instead of random, to regain health and survive longer +# food = game_state['board']['food'] \ No newline at end of file From bbc5030d179c3a94d782b6bd2b02d0e39fb89aae Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 12:26:34 +0100 Subject: [PATCH 115/117] Test works --- tests/test_not_backward.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/test_not_backward.py b/tests/test_not_backward.py index 89e31df86..2b4c0eeca 100644 --- a/tests/test_not_backward.py +++ b/tests/test_not_backward.py @@ -1,7 +1,7 @@ import unittest from unittest.mock import patch -from main import move +from move import Move class TestNotBackward(unittest.TestCase): @@ -12,19 +12,13 @@ def test_not_down(self): "turn": 1 } - with patch.object(Move, "not_wall_collision", return_value = "patch not_wall_collision") as patch_1: + bot = Move() - with patch.object(Move, "not_itself_collision", return_value = "patch not_itself_collision") as patch_2: + bot.choose_move(game_state) - with patch.object(Move, "not_enemy_collision", return_value = "Patch not_enemy_collision") as patch_3: + is_safe = bot.is_move_safe["up"]["is_safe"] - bot = Move() - - bot.choose_move(game_state) - - is_safe = bot.is_move_safe["up"]["is_safe"] - - self.assertFalse(is_safe) + self.assertFalse(is_safe) def test_not_left(self): @@ -33,7 +27,9 @@ def test_not_left(self): "turn": 1 } - move(game_state) + bot = Move() + + bot.choose_move(game_state) is_safe = bot.is_move_safe["left"]["is_safe"] From 189c5a6974979d0d9981e63fc4a18c47b8ac960b Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 12:35:32 +0100 Subject: [PATCH 116/117] implement Move() in main --- main.py | 53 +++++------------------------------------------------ 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/main.py b/main.py index 4ca21971e..9e5e99a5d 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ import random import typing - +from move import Move # info is called when you create your Battlesnake on play.battlesnake.com # and controls your Battlesnake's appearance @@ -43,53 +43,10 @@ def end(game_state: typing.Dict): # Valid moves are "up", "down", "left", or "right" # See https://docs.battlesnake.com/api/example-move for available data def move(game_state: typing.Dict) -> typing.Dict: - - is_move_safe = {"up": True, "down": True, "left": True, "right": True} - - # We've included code to prevent your Battlesnake from moving backwards - my_head = game_state["you"]["body"][0] # Coordinates of your head - my_neck = game_state["you"]["body"][1] # Coordinates of your "neck" - - if my_neck["x"] < my_head["x"]: # Neck is left of head, don't move left - is_move_safe["left"] = False - - elif my_neck["x"] > my_head["x"]: # Neck is right of head, don't move right - is_move_safe["right"] = False - - elif my_neck["y"] < my_head["y"]: # Neck is below head, don't move down - is_move_safe["down"] = False - - elif my_neck["y"] > my_head["y"]: # Neck is above head, don't move up - is_move_safe["up"] = False - - # TODO: Step 1 - Prevent your Battlesnake from moving out of bounds - # board_width = game_state['board']['width'] - # board_height = game_state['board']['height'] - - # TODO: Step 2 - Prevent your Battlesnake from colliding with itself - # my_body = game_state['you']['body'] - - # TODO: Step 3 - Prevent your Battlesnake from colliding with other Battlesnakes - # opponents = game_state['board']['snakes'] - - # Are there any safe moves left? - safe_moves = [] - for move, isSafe in is_move_safe.items(): - if isSafe: - safe_moves.append(move) - - if len(safe_moves) == 0: - print(f"MOVE {game_state['turn']}: No safe moves detected! Moving down") - return {"move": "down"} - - # Choose a random move from the safe ones - next_move = random.choice(safe_moves) - - # TODO: Step 4 - Move towards food instead of random, to regain health and survive longer - # food = game_state['board']['food'] - - print(f"MOVE {game_state['turn']}: {next_move}") - return {"move": next_move} + + bot = Move() + + return bot.choose_move(game_state) # Start server when `python main.py` is run From 42261a61ea6f1d31cd10d81d50992450bb8248e6 Mon Sep 17 00:00:00 2001 From: SuperMeister808 Date: Sun, 11 Jan 2026 12:45:32 +0100 Subject: [PATCH 117/117] Updated git Ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9651198f9..368a85b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.DS_Store *.pyc +*.venv __pycache__/ game_state_example.txt run_local_game.txt \ No newline at end of file