Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Praesidium

Pages: [1]
DNA Tools / A Program to Make SG Bots
« on: March 30, 2008, 06:15:20 AM »
I suppose this would be the right place to post this. It was an idea I had back when I first started messing around with the DNA, but I got sidetracked by other things. A few days ago I finally sat down and wrote it, using python, and managed to get it working. It takes the path of the bot you want to make an SG Bot out of, then allows you to specify a different file to save the result into (optional). As far as my testing has concluded the results work perfectly, even if the resulting code is ugly, though errors may still occur. I'd appreciate any feedback on it. Oh, it requires the Python interpreter be installed (available free from, and then the source code saved in a .py file should run like a .exe (under windows, on other operating systems you may need to add a line of code to the top, unfortunately, I can never remember what it is...). I'll simply post the code here rather than uploading the file, just paste it into a text editor and save it as a .py, it should run like an executable after that. Try it out, just be sure to either use a copy of the bot or have it save to a different file, I think it's bug-free, but I'd hate to be responsible for a bot getting messed up.

Code: [Select]
print """      Copyright (C) 2008 Praesidium
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU 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
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <>."""

class SGBot():
    def __init__(self, path = "default.txt"):
        self.path = open(path, "r")
        self.text = []
        for line in self.path: self.text.append(line)

    def toSG(self):
        self.conds = []
        self.cond = []
        self.cur = ""
        self.iscond = 0
        self.curcond = 0
        for line in self.text:
            if "cond" in line: self.iscond = 1
            elif "start" in line:
                self.iscond = 2
                self.cur = "".join(self.cond) + " mult "
                self.cond = []
            elif "stop" in line: self.iscond = 0
            elif "end" in line: break
            elif self.iscond == 1:
                line = line.replace("\n", "")
                if " >=" in line: line = line.replace(">=", "sub 1 add sgn 0 floor ")
                elif " <=" in line: line = line.replace("<=", "sub 1 sub sgn - 0 floor ")
                elif " >" in line: line = line.replace(">", "sub sgn 0 floor ")
                elif " <" in line: line = line.replace("<", "sub sgn - 0 floor ")
                elif " !=" in line: line = line.replace("!=", "sub sgn abs ")
                elif " =" in line: line = line.replace("=", "sub sgn abs - ++ ")
                if " xor" in line: line = line.replace("xor", "sub dup div ")
                elif " or" in line: line = line.replace("or", "add sgn ")
                elif " and" in line: line = line.replace("and", "mult ")
                elif " not" in line: line = line.replace("not", "1 sub dup div ")
                elif len(self.cond) > 0: line += " mult "
            elif self.iscond == 2:
                line = line.replace("store", self.cur + " store")
                line = line.replace("inc", self.cur + "inc")
                line = line.replace("dec", self.cur + "dec")
        return "cond\nstart\n" + "".join(self.conds) + "stop\nend"

    def save(self, saveto, content = []):
        self.saving = open(saveto, "w")

path = raw_input("Enter path: ")
deci = raw_input("Would you like to save to the same file?[y/n] ")
parser = SGBot(path)
if not deci == "y": save = raw_input("Where would you like to save it? ")
else: save = path, parser.toSG())

Pages: [1]