Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old September 5, 2010, 23:23   #1
grassy
Rookie
 
Join Date: Dec 2009
Posts: 21
grassy is on a distinguished road
softcoded borg

Spent some time over the weekend coding an angband borg (sort of . Instead of hardcoding the borg into the angband source as has been done previously, I decided to use a python script to control the character via pexpect. Here's the result:

Code:
import sys
import pexpect

tt=0.05

class Borg():
    
    def __init__(self):
        self.proc=pexpect.spawn("./angband -mgcu")
        #fout = file("borg.log","w")
        #self.proc.logfile = fout
        self.proc.logfile = sys.stdout
        self.proc.expect("[Press any key to continue]")
        self.proc.send("a")
        raw_input(">>> Press any key to begin <<<")

    def FindDown(self):
        self.proc.send("+")
        try:
            self.proc.expect("down staircase",timeout=tt)
            return True
        except pexpect.TIMEOUT:
            return False

    def FoundStuff(self):
        self.proc.send("+")
        try:
            self.proc.expect([
                "down staircase",
                #Ammo
                "Pebble",
                "Arrow",
                "Shot",
                "Bolt",
                #Bows
                "Sling",
                "Bow",
                "Crossbow",
                #Weapons
                "Dagger",
                "Sword",
                "Shovel",
                "Gauche",
                "Whip",
                "Spear",
                "Rapier",
                "Sabre",
                "Pick",
                "Cutlass",
                "Trident",
                "Mace",
                "Tulwar",
                "Quarterstaff",
                "Chain",
                "Hammer",
                "Lance",
                "Scimitar",
                "Axe",
                "Flail",
                "Pike",
                "Glaive",
                "Star",
                "Katana",
                "Halbert",
                "Mattock",
                "Scythe",
                "Blade",
                #Armor
                "Armor",
                "Leather",
                "Mail",
                "Cloak",
                "Gloves",
                "Boots",
                "Cap",
                "Gauntlets",
                "Shield",
                "Helm",
                "Crown",
                #Amulates
                "Amulet",
                #Rings
                "Ring"
                #Scrolls
                "Scroll",
                #Potions
                "Potion",
                #Food
                "Mushroom",
                "Food"
                "Waybread",
                #Rods"
                "Rod",
                #Wands
                "Wand",
                #Staffs
                "Staff",
                #Books
                "Book",
                #Chests
                "chest",
                #Misc
                "Spike",
                "Torch",
                "Lantern",
                "Flask",
                "Phial",
                "Star",
                "Arkenstone",
                "Palantir"
                ],timeout=tt)
            return True
        except pexpect.TIMEOUT:
            return False                

    def Diver(self):
        while True:
            self.proc.send("x")
            try:
                self.proc.expect("up staircase",timeout=tt)
                if self.FindDown():
                    self.proc.send("g")
                    self.proc.send("x")
                    try:
                        self.proc.expect("on a down staircase",timeout=tt)
                        self.proc.sendcontrol("[")
                        self.proc.send(">")
                    except pexpect.TIMEOUT:
                        break
                else:
                    self.proc.sendcontrol("[")
                    self.proc.send("<")
                    self.proc.send(">")
            except pexpect.TIMEOUT:
                break

    def Finder(self):
        while True:
            self.proc.send("x")
            try:
                self.proc.expect("up staircase", timeout=tt)
                if self.FoundStuff():
                    break
                else:
                    self.proc.sendcontrol("[")
                    self.proc.send("<")
                    self.proc.send(">")
            except pexpect.TIMEOUT:
                break
                
      
    def Run(self):
        #self.Diver()
        self.Finder()

if __name__ == "__main__":
    borg=Borg()
    borg.Run()
This will probably only run on *unix systems given the use of pexpect. Two *simple*functions are included - #uncomment# on or the other. Diver attempts to dive into the dungeon and Finder looks for stuff Nothing fancy - just wanted to demonstrate the concept.

To start the borg the character must be on a down staircase. You need to disable -more- prompts. Note that the borg use roguelike commands.

The tt parameter in the code is the time in seconds to wait on pexpect before timeout - you can try reducing this to speed up the borg.

Also - use this on a new character, don't risk your existing character

Andre

Last edited by grassy; September 5, 2010 at 23:44.
grassy is offline   Reply With Quote
Old September 7, 2010, 12:18   #2
Zababa
Apprentice
 
Join Date: Sep 2009
Location: Germany
Age: 37
Posts: 98
Zababa is on a distinguished road
I am not a programmer, so I don't understand the code, but is there any chance that there will be a borg for angband under windows some time soon? I really enjoy watching them playing.
Zababa is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Borg doesn't respawn nekrotyrael Vanilla 4 June 26, 2009 20:11
Ready for borg update? APWhite Development 8 April 21, 2009 19:22
Borg update APWhite Vanilla 75 April 11, 2009 12:14
APW borg on OS X pesachyonah Vanilla 7 February 12, 2008 10:56
Borg 3.0.9 Progress Update APWhite Vanilla 3 August 10, 2007 02:15


All times are GMT +1. The time now is 17:31.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.