1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
\section{Introduction}
Before starting this tutorial, you should \emph{already} know the basics of
Python. Specifically, you should know these bits of Python:
\begin{itemize}
\item How to \py|print| things
\item \py|if|, \py|elif| and \py|else|
\item \py|for| and \py|while| loops
\item \py|list|s and \py|dict|ionaries
\item functions (\py|def|)
\end{itemize}
\subsection{Help! I don’t know what these are…}
If you have no idea what any of those things are, \emph{don’t panic}.
All that means is that you’re not quite ready to follow this tutorial yet, and
you need to learn the basics of Python first.
There are many excellent \emph{free} resources for doing this:
\begin{itemize}
\item How to Think Like a Computer Scientist \\
(\url{http://openbookproject.net/thinkcs/python/english2e/})
\item Learn Python the Hard Way \\
\url{http://learnpythonthehardway.org/}
\item The official tutorial in the Python documentation \\
\url{http://docs.python.org/tutorial/}
\end{itemize}
The most important resource to learn programming, however, are the people you
know who are learning Python with you, already know Python, or some other
programming language.
You can spend hours trying to understand something in books and not get it,
but ask another person to explain it, and it will all suddenly ‘click’ and make
sense.
\subsection{Yeah, I know what those are.}
Excellent! Let’s get started then.
If you’re doing this in some kind of programming class, your instructor may have
provided you with a zip file (or similar) containing SnakeGame and pyglet.
If so, follow their instructions for setting it up, and head straight on to
Your First Bot.
Otherwise, you’ll need to first install the code. The latest version of
SnakeGame is available in a Mercurial repository at
\url{http://hg.flowblok.id.au/snakegame}.
You can install it using pip:
\begin{shell}
$ pip install hg+http://hg.flowblok.id.au/snakegame#egg=SnakeGame
\end{shell}
If you wish to have a pretty graphical viewer for watching the game being
played, you will also need to install pyglet\footnoteurl{http://pyglet.org/}
and/or pygame\footnoteurl{http://pygame.org}.
\subsection{Skipping ahead}
If you already know Python, you will probably want to skip some sections of this
tutorial. To make this easier, there is a \emph{Fast track} note at the start of
each section: if you can write a bot which does what it says, you can safely
skip that section.
|