# SSCU Extreme Games

Part of the Subspace Continuum network.

### Python Dev in EG

Develop, Discuss, Get Help with Pycore,FCcore,Opencore and other bot cores for Subspace and bot development in EG

Moderators: Fc, king, Chineh, Sann

### Re: Python Dev in EG#465481

By Wormhole-Surfer
#465481
Someone please test this lvz out with grazz's kotr bot and let me know if it works.

Thanks.
akoth5.lvz
Also, for future reference.. what is the file size limit for attachments on here?

### Re: Python Dev in EG#465518

By Wormhole-Surfer
#465518
Request:
LOTD BOT (for 24/7 use, not for an event)

Preview image of new lotd circle:
http://imgur.com/ejwn6.jpg

Description: This bot will run a continuous LOTD(lord of the duel) game in a new subarena(or duel arena) for up to 9 players. When a player enters the map as a ship, the bot will warp that player into one of 9 "waiting rooms" along the edge of the dueling circle. There the player will wait his turn until the bot will open the door of the waiting room and he will challenge the player currently in the center of the dueling ring. A maximum of 2 people will duel at a time. The winner of the duel will stay in the center until he is defeated.

Bot requirements:

1) warp player into one of the 8 waiting rooms(see attached image) when a player enters the game from spec mode
2) open and close the invisible doors in front of each waiting room (8 different doors total, using 8 different door tiles) in order (going clockwise)
3) send *objon commands and *arena %[bongsound] commands for each waiting room to alert player of their turn
4) warp the winner of the duel to a semi-random location inside the circle so he can't get an unfair advantage at the person entering

Optional:

- keep a record of the most consecutive kills and display the top 3 periodically
- have the bot open a random door ( from 1 to 8 ) instead of going clockwise
- have the bot announce every 5 minutes, zonewide, the number of open spots in LOTD
- the bot subtracts 0.10 EGC every time you enter the circle. players win 0.10 for each kill.

(Also, I am planning on putting an invisible wormhole behind each spawnroom with low negative gravity settings so when the door opens, the player will be pushed out of the waiting room. This should prevent people from hiding in the waiting rooms and avoid problems with players going afk in the waiting rooms. The only problem will be making the wormhole strong enough to push them out and still weak enough not to affect the gravity in the center of the circle too much.)
Last edited by Wormhole-Surfer on July 16th, 2010, 10:58 pm, edited 1 time in total.

### Re: Python Dev in EG#465525

By jream
#465525
I am learning Python right now, just started. I'm familiar with OOP and all the standard programming stuff, it appears to have a bit different syntax which I expected, and I think it's very clean. Also strangely they call an array a sequence it appears.

It will take me some time to write fast since I have to form a habit of the different syntax. It's a little strange they don't just auto-include all the modules for an interpreted language, but the same goes for C++ although it's not interpreted.

I'll probably go through a few weeks of tutorials and see if I stick with it, since you can't learn something unless you find a practical use for it and can practice it. I am also not fond of the idea of setting up a NGINX server (I think that's what it uses), so for now I'll toy with the shell and possibly try testing out a local NGINX server as long as it doesn't collide with Apache, not sure how that all works just yet But hopefully this doesn't turn into just another server-side language that goes to waste since I'd rather use code that can be used for something else.

### Re: Python Dev in EG#465530

By Wormhole-Surfer
#465530
jream, you are truly an enigma.

By lagGore
#465532
wow, lol

### Re: Python Dev in EG#465534

By prozaker
#465534
you don't need ngix at all, not even apache, since python comes with its own interpreter for the command line

### Re: Python Dev in EG#465535

By Wormhole-Surfer
#465535
I think an LOTD bot would be a great addition to the zone for the players that just feel like dueling/fraying and want instant gratification and an immediate challenge. If anyone has better ideas of how to design the bot, I'd be happy to contribute graphics and sound effects to make it happen. This would mostly cater to the duel crowd though anyone who just likes to casually fray would probably be drawn in.

### Re: Python Dev in EG#465538

By jream
#465538
ok wel i dont apreciate that wormhole

I am using Python shell getting familiar. This language is extremely clean and I am very impressed.

Is this a legitimate multi-dimensional array here? (It appears to be imo, but i can be wrong)
Code: Select all
>>> test = [1,2,3, [1,2,3], 4]
>>> test[3][0]
Because I see they also have a thing called dictionary that uses a key/value, ie:
Code: Select all
>>> test2 = {'Key':'Value', 1:500}
However, that "dictionary" looks like an associative array, ie:
Code: Select all
>>> test2['Key']
So in the original case of the var test,
test[0] is an array but you can never have a value for the [0] spot,
but in the dictionary you have a key/value where the key can be a num/str.

Why didn't they just do this rather than forcing separate syntax for the dictionary:
Code: Select all
>>> test = [0:'slot 0', 'blah':'something']

### Re: Python Dev in EG#465540

By Wormhole-Surfer
#465540
jream wrote:ok wel i dont apreciate that wormhole
enigma: a person of puzzling or contradictory character

### Re: Python Dev in EG#465544

By jream
#465544
I have a few questions?

1. Is there an API for the subspace calls? ie: Where does one find the methods? Or a built-in Python Reflection Class to see what is what (Sorry I don't know if Python has that, It probably does).

2. Are user-made bots instantiated from inside a "Parent-Bot"? Which would give user-made bots the ability to use these Commands from the examples?

The reason I ask #2 is because I am wondering if it is possible to connect locally to subspace with a bot running, and test it on there to get the hang of it.

### Re: Python Dev in EG#465585

By Wormhole-Surfer
#465585
yes, you can run subgame in local mode and test your bot that way.

if you haven't set up a subspace server before:
http://www.minegoboom.com/server/howto- ... index.html

### Re: Python Dev in EG#465602

By jream
#465602
Cool that will do me some good Ill save this for later, I need a few weeks to get fast at writing code. Im trying to think up a few sample applications I can write that don't totally suck for practice, if I just type code I never remember it later.

I was toying around with Django also but haven't got far with that, I'll stick to the roots here and reading a Python book which I will probably order the physical copy titled "Apress Beginning Python From Novice to Professional" (or something like that). Unless someone knows a better book.

One gripe I have is that the *.py files are stored in cgi-bin on a web-server, is this true anytime you want to run python files on a webserver? I'm just thinking ahead, and that is irritating to me that it's not in the webroot. Hence the shebash at the program headers.

I'll see if someone will explain to me how this is wired better so I know what else I can do with it.

### Re: Python Dev in EG#465661

By prozaker
#465661
you're confusing a web server hosting python based applications with console applications, which is what bots are. like i said before, YOU DO NOT NEED A WEB SERVER TO RUN BOTS.

there aren't any cgi files that you need to use.

django is an MVC framework for building web applications. don't think you can use it for subspace bots, because you can't, it is not what it is for

### Re: Python Dev in EG#465827

By jream
#465827
ok thak you.

i am making yahtzee consoel game, maybe a gui later in python i am doing it good i will show it later. it is to train me to get good

By prozaker
#465940
sounds good man.

### Re: Python Dev in EG#466582

By jream
#466582
Well yahtzee tricky cuz of the gui, so i went easier with Tic Tac Toe, lol.
I have a working console application, now I am arguing whether to use wxPython or I think its called tinyint or intTinker or something, I kind of like the intTinker ones commands.

By Dexter
#467299

### Re: Python Dev in EG#467309

By prozaker
#467309
pydev is a good ide. it helps with error checking at coding level.

python docs is a good resource too.

### Re: Python Dev in EG#469638

By f16 fighterjet
#469638
im interested in your programming experiance thanks.

### Re: Python Dev in EG#471800

By SEALs
#471800
f16 fighterjet wrote:im interested in your programming experiance thanks.
Not sure if you mean you want him to help you do something, or if you want help getting started, but read this. It's nice and concise imo:
Preliminary fluff
So, you want to learn the Python programming language but can’t find a concise and yet full-featured tutorial. This tutorial will attempt to teach you Python in 10 minutes. It’s probably not so much a tutorial as it is a cross between a tutorial and a cheatsheet, so it will just show you some basic concepts to start you off. Obviously, if you want to really learn a language you need to program in it for a while. I will assume that you are already familiar with programming and will, therefore, skip most of the non-language-specific stuff. The important keywords will be highlighted so you can easily spot them. Also, pay attention because, due to the terseness of this tutorial, some things will be introduced directly in code and only briefly commented on.

Properties
Python is strongly typed (i.e. types are enforced), dynamically, implicitly typed (i.e. you don’t have to declare variables), case sensitive (i.e. var and VAR are two different variables) and object-oriented (i.e. everything is an object).

Getting help
Help in Python is always available right in the interpreter. If you want to know how an object works, all you have to do is call help(<object>)! Also useful are dir(), which shows you all the object’s methods, and <object>.doc, which shows you its documentation string:

>>> help(5)
Help on int object:
(etc etc)

>>> dir(5)

>>> abs.__doc__
'abs(number) -> number\n\nReturn the absolute value of the argument.'

Syntax
Python has no mandatory statement termination characters and blocks are specified by indentation. Indent to begin a block, dedent to end one. Statements that expect an indentation level end in a colon (:). Comments start with the pound (#) sign and are single-line, multi-line strings are used for multi-line comments. Values are assigned (in fact, objects are bound to names) with the equals sign (”=”), and equality testing is done using two equals signs (”==“). You can increment/decrement values using the += and -= operators respectively by the right-hand amount. This works on many datatypes, strings included. You can also use multiple variables on one line. For example:

>>> myvar = 3
>>> myvar += 2
>>> myvar
5
>>> myvar -= 1
>>> myvar
4
"""This is a multiline comment.
The following lines concatenate the two strings."""
>>> mystring = "Hello"
>>> mystring += " world."
>>> print mystring
Hello world.
# This swaps the variables in one line(!).
# It doesn't violate strong typing because values aren't
# actually being assigned, but new objects are bound to
# the old names.
>>> myvar, mystring = mystring, myvar

Data types
The data structures available in python are lists, tuples and dictionaries. Sets are available in the sets library (but are built-in in Python 2.5 and later). Lists are like one-dimensional arrays (but you can also have lists of other lists), dictionaries are associative arrays (a.k.a. hash tables) and tuples are immutable one-dimensional arrays (Python “arrays” can be of any type, so you can mix e.g. integers, strings, etc in lists/dictionaries/tuples). The index of the first item in all array types is 0. Negative numbers count from the end towards the beginning, -1 is the last item. Variables can point to functions. The usage is as follows:

>>> sample = [1, ["another", "list"], ("a", "tuple")]
>>> mylist = ["List item 1", 2, 3.14]
>>> mylist[0] = "List item 1 again"
>>> mylist[-1] = 3.14
>>> mydict = {"Key 1": "Value 1", 2: 3, "pi": 3.14}
>>> mydict["pi"] = 3.15
>>> mytuple = (1, 2, 3)
>>> myfunction = len
>>> print myfunction(mylist)
3

You can access array ranges using a colon (:). Leaving the start index empty assumes the first item, leaving the end index assumes the last item. Negative indexes count from the last item backwards (thus -1 is the last item) like so:

>>> mylist = ["List item 1", 2, 3.14]
>>> print mylist[:]
['List item 1', 2, 3.1400000000000001]
>>> print mylist[0:2]
['List item 1', 2]
>>> print mylist[-3:-1]
['List item 1', 2]
>>> print mylist[1:]
[2, 3.14]

Strings
Its strings can use either single or double quotation marks, and you can have quotation marks of one kind inside a string that uses the other kind (i.e. “He said ‘hello’.” is valid). Multiline strings are enclosed in triple double (or single) quotes (”“”). Python supports Unicode out of the box, using the syntax u“This is a unicode string”. To fill a string with values, you use the % (modulo) operator and a tuple. Each %s gets replaced with an item from the tuple, left to right, and you can also use dictionary substitutions, like so:

>>>print "Name: %s\nNumber: %s\nString: %s" % (myclass.name, 3, 3 * "-")
Name: Poromenos
Number: 3
String: ---

strString = """This is
a multiline
string."""

# WARNING: Watch out for the trailing s in "%(key)s".
>>> print "This %(verb)s a %(noun)s." % {"noun": "test", "verb": "is"}
This is a test.

Flow control statements
Flow control statements are if, for, and while. There is no select; instead, use if. Use for to enumerate through members of a list. To obtain a list of numbers, use range(<number>). These statements’ syntax is thus:

rangelist = range(10)
>>> print rangelist
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for number in rangelist:
# Check if number is one of
# the numbers in the tuple.
if number in (3, 4, 7, 9):
# "Break" terminates a for without
# executing the "else" clause.
break
else:
# "Continue" starts the next iteration
# of the loop. It's rather useless here,
# as it's the last statement of the loop.
continue
else:
# The "else" clause is optional and is
# executed only if the loop didn't "break".
pass # Do nothing

if rangelist[1] == 2:
print "The second item (lists are 0-based) is 2"
elif rangelist[1] == 3:
print "The second item (lists are 0-based) is 3"
else:
print "Dunno"

while rangelist[1] == 1:
pass

Functions
Functions are declared with the “def” keyword. Optional arguments are set in the function declaration after the mandatory arguments by being assigned a default value. For named arguments, the name of the argument is assigned a value. Functions can return a tuple (and using tuple unpacking you can effectively return multiple values). Lambda functions are ad hoc functions that are comprised of a single statement. Parameters are passed by reference, but immutable types (tuples, ints, strings, etc) cannot be changed. This is because only the memory location of the item is passed, and binding another object to a variable discards the old one, so immutable types are replaced. For example:

# Same as def f(x): return x + 1
functionvar = lambda x: x + 1
>>> print functionvar(1)
2

# an_int and a_string are optional, they have default values
# if one is not passed (2 and "A default string", respectively).
def passing_example(a_list, an_int=2, a_string="A default string"):
a_list.append("A new item")
an_int = 4
return a_list, an_int, a_string

>>> my_list = [1, 2, 3]
>>> my_int = 10
>>> print passing_example(my_list, my_int)
([1, 2, 3, 'A new item'], 4, "A default string")
>>> my_list
[1, 2, 3, 'A new item']
>>> my_int
10

Classes
Python supports a limited form of multiple inheritance in classes. Private variables and methods can be declared (by convention, this is not enforced by the language) by adding at least two leading underscores and at most one trailing one (e.g. “__spam”). We can also bind arbitrary names to class instances. An example follows:

class MyClass:
common = 10
def __init__(self):
self.myvariable = 3
def myfunction(self, arg1, arg2):
return self.myvariable

# This is the class instantiation
>>> classinstance = MyClass()
>>> classinstance.myfunction(1, 2)
3
# This variable is shared by all classes.
>>> classinstance2 = MyClass()
>>> classinstance.common
10
>>> classinstance2.common
10
# Note how we use the class name
>>> MyClass.common = 30
>>> classinstance.common
30
>>> classinstance2.common
30
# This will not update the variable on the class,
# instead it will bind a new object to the old
# variable name.
>>> classinstance.common = 10
>>> classinstance.common
10
>>> classinstance2.common
30
>>> MyClass.common = 50
# This has not changed, because "common" is
# now an instance variable.
>>> classinstance.common
10
>>> classinstance2.common
50

# This class inherits from MyClass. Multiple
# inheritance is declared as:
# class OtherClass(MyClass1, MyClass2, MyClassN)
class OtherClass(MyClass):
# The "self" argument is passed automatically
# and refers to the class instance, so you can set
# instance variables as above, but from inside the class.
def __init__(self, arg1):
self.myvariable = 3
print arg1

>>> classinstance = OtherClass("hello")
hello
>>> classinstance.myfunction(1, 2)
3
# This class doesn't have a .test member, but
# we can add one to the instance anyway. Note
# that this will only be a member of classinstance.
>>> classinstance.test = 10
>>> classinstance.test
10

Exceptions
Exceptions in Python are handled with try-except [exceptionname] blocks:

def some_function():
try:
# Division by zero raises an exception
10 / 0
except ZeroDivisionError:
print "Oops, invalid."
else:
# Exception didn't occur, we're good.
pass
finally:
# This is executed after the code block is run
# and all exceptions have been handled, even
# if a new exception is raised while handling.
print "We're done with that."

>>> some_function()
Oops, invalid.
We're done with that.

Importing
External libraries are used with the import [libname] keyword. You can also use from [libname] import [funcname] for individual functions. Here is an example:

import random
from time import clock

randomint = random.randint(1, 100)
>>> print randomint
64

File I/O
Python has a wide array of libraries built in. As an example, here is how serializing (converting data structures to strings using the pickle library) with file I/O is used:

import pickle
mylist = ["This", "is", 4, 13327]
# Open the file C:\binary.dat for writing. The letter r before the
# filename string is used to prevent backslash escaping.
myfile = file(r"C:\binary.dat", "w")
pickle.dump(mylist, myfile)
myfile.close()

myfile = file(r"C:\text.txt", "w")
myfile.write("This is a sample string")
myfile.close()

myfile = file(r"C:\text.txt")
'This is a sample string'
myfile.close()

# Open the file for reading.
myfile = file(r"C:\binary.dat")
myfile.close()
['This', 'is', 4, 13327]

Miscellaneous
Conditions can be chained. 1 < a < 3 checks that a is both less than 3 and more than 1.
You can use del to delete variables or items in arrays.
List comprehensions provide a powerful way to create and manipulate lists. They consist of an expression followed by a for clause followed by zero or more if or for clauses, like so:

>>> lst1 = [1, 2, 3]
>>> lst2 = [3, 4, 5]
>>> print [x * y for x in lst1 for y in lst2]
[3, 4, 5, 6, 8, 10, 9, 12, 15]
>>> print [x for x in lst1 if 4 > x > 1]
[2, 3]
# Check if an item has a specific property.
# "any" returns true if any item in the list is true.
>>> any([i % 3 for i in [3, 3, 4, 4, 3]])
True
# This is because 4 % 3 = 1, and 1 is true, so any()
# returns True.

# Check how many items have this property.
>>> sum(1 for i in [3, 3, 4, 4, 3] if i == 4)
2
>>> del lst1[0]
>>> print lst1
[2, 3]
>>> del lst1

Global variables are declared outside of functions and can be read without any special declarations, but if you want to write to them you must declare them at the beginning of the function with the “global” keyword, otherwise Python will bind that object to a new local variable (be careful of that, it’s a small catch that can get you if you don’t know it). For example:

number = 5

def myfunc():
# This will print 5.
print number

def anotherfunc():
# This raises an exception because the variable has not
# been bound before printing. Python knows that it an
# object will be bound to it later and creates a new, local
# object instead of accessing the global one.
print number
number = 3

def yetanotherfunc():
global number
# This will correctly change the global.
number = 3

Epilogue
This tutorial is not meant to be an exhaustive list of all (or even a subset) of Python. Python has a vast array of libraries and much much more functionality which you will have to discover through other means, such as the excellent book Dive into Python. I hope I have made your transition in Python easier. Please leave comments if you believe there is something that could be improved or added or if there is anything else you would like to see (classes, error handling, anything).

### Re: Python Dev in EG#476868

By Meilay
#476868
I would like to help create bots for EG. I will be looking into commands and previous bots made to become more familiar so if anyone has tips or any info that could help me would be glad to listen.

### Re: Python Dev in EG#476895

By Meilay
#476895
Okay ive spent hours working on learning python, soooo complicated

### Re: Python Dev in EG#476920

By camshaft
#476920
thank you to allowing anyone to do this, not to hard to learn and it can be useful, thanks

### Re: Python Dev in EG#476932

By Wormhole-Surfer
#476932
New bot request A:

I just made some updates to EGHOCKEY arena and fixed a few things to improve the gameplay (most noticeable is wider goal). However, in order for eghockey to run smoothly, we'll need a fairly simple bot that can do the following:

1) Limit freq 0 and freq 1 to 5 players each
2) Limit freq 2 and 3 to 1 player each (goalies)
3) warp goalies if they try to pass the blue line
4) if player on freq 0 or 1 enters goal crease, lock player in spec or place in penalty box for 2 minutes
5) if a player kills the same player 3 times in less 10 seconds, lock in spec or send to penalty box

Those are the basic necessities for the current updated eghockey arena to run smoothly and keep abuse/cheating to a minimum. If you want to get more complicated you could add lvz scoreboard capabilities, but that's hardly necessary.

New bot request B:

I made some slight adjustments to the BATTLEFIELD 2D event. I know King was working on a bot for this event and I don't recall if it was a completed bot or was ever uploaded to the server. Anyway, I'm looking for a bot that will just do a few basic commands as the event mostly runs itself:

1) force everyone in spec mode and lock arena
2) tell players that event will begin in 3 minutes and unlock arena at conclusion of 3 minutes
3) every 60 seconds, display (using *arena) the total points for freq 0 and total points for freq 1
4) announce (using *arena) when a freq has taken control of a flag and the %area (3 flags total on map)
5) at end of game, announce which freq won (freq with most total points before time runs out)

For those of you who missed it, serexl hosted this event the other day and it worked out really well. We had 2 very good close/competitive games. There are 3 "outposts" on the map with a flag in the center of each one. Players gain points only by controlling the outposts, so the team that controls the most outposts for the longest period of time wins. Players can choose to play as infantry with shotgun, fully automatic rifle, sniper rifle, or hoverbike.

### Re: Python Dev in EG#478325

By Optimal
#478325
Im ready to learn, contact me in game

### Re: Python Dev in EG#478426

By The Junky
#478426
getting started guide http://code.google.com/p/subspace-pytho ... ingStarted
some old examples http://www.extreme-games.net/junky/python/examples/old/

if you cant get it to work contact me(Ratio)/king or chin in game

Edit:

we moved the python code to google code, so you can always grab the latest copy from the repo if you install svn
if not grab whatever the last release is.... ill try to update all the examples at some point so they will work under the current version of the core

### Re: Python Dev in EG#479094

By Grace Quek
#479094
Some years back, I think FC made bots which stayed in place and fired bullets. These are popularly used to make a variant out of different race events. He also had something where the bot would attach to him or follow him around in Team Elim, didn't he?

Here's my useless idea...

Has anyone tried making a pilot bot? I don't mean an AI player, just a bot that could move through bases. It's probably not something you would run on the EG server like the other bots. Maybe a program that looks at Continuum and sends signals to use the controls like a player?

You could accomplish it in two ways -- The first would be to somehow 'record' a fast player flying through a base and code the bot to replay those same moves. The other would be to write code that would really 'drive' the ship based on its objective destination and the walls around it, etc. There's racing game called TORCS in which people write bots to drive the tracks. Driving in SubSpace would be easy compared to that, and you could probably borrow some of the same design ideas. However, this might be impractical because I'm not sure how much information you would be able to et about the position, momentum/velocity of your ship, etc. It might be too close to a hack like Twister or whatever.

Maybe this would be useful for training players on how to quickly fly through bases. They could watch the bot moving flawlessly and try to follow it.

### Re: Python Dev in EG#479116

By prozaker
#479116
i think it is possible. make it so.

### Re: Python Dev in EG#481650

By col.1
#481650
I will send you a message ingame cy
###### FORUMS WILL BE SHUTTING DOWN (GO TO DISCORD INSTEAD)

I can host an archive of the forums if we want. Wo[…]