Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

See Episode 11, Which contract should we take?

Contract 1, FedCom Extraction Raid
- 4 (100%)
Contract 2, Outworlds Alliance Recon Raid
- 0 (0%)
Contract 3, FedCom Recon Raid #1
- 0 (0%)
Contract 4, FedCom Recon Raid #2
- 0 (0%)
None of the above - wait a month and try again (please post to specify acceptable contract criteria)
- 0 (0%)

Total Members Voted: 4


Pages: 1 ... 16 17 [18] 19 20 ... 40

Author Topic: Let's Play MegaMek (Against the Bot campaign)  (Read 75169 times)

Neonivek

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #255 on: December 01, 2015, 04:31:00 pm »

A few COULD be fun... if a human being made it and not a AI that doesn't know what it is oding.
Logged

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #256 on: December 02, 2015, 06:19:02 am »

Unfortunately, the script is still unhappy – Round.txt is here, with the error message below.

Code: [Select]
File “C:\MekHQ\Battle_Results\Results.py”, line 156, in <module>
   targetUnit.damagetaken += int(r.group(3))
AttributeError: ‘NoneType’ object has no attribute ‘damageTaken’

That said, the mission didn't go that badly. The terrain meant the vehicles never really got that far from the starting area, so Battle Lance had a chance to show up and help stomp a hole in them. We still took a casualty, but hopefully it won't be permanent.

Also, thanks for the 2-4x repair time tip - it's saved a couple repair jobs already.
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #257 on: December 02, 2015, 11:02:38 am »

LOL, holy crap, so many combinations of names. This is probably caused by having the two same units in the same faction, which adds a #1 and #2 to each. Dagnabbit. This is why these scripts are better programmed inside the application itself instead of using lots of regular expressions that have to take into account all of the possibilities, hah :D

How soon would you need this?

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #258 on: December 02, 2015, 11:27:42 am »

I can wait, I really appreciate the convenience, but life and work always go ahead. :)
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #259 on: December 02, 2015, 12:01:00 pm »

Quick fix, looks like it might've been what I thought it was. I tested it and it didn't crash with the round that I had before and with this one. The round output of the new script matches the output of the old one for the old round. I didn't double check to see if the data seems to check out with the round you sent me though!

Code: [Select]
import re

with open ("round.txt", "r") as myfile:
    data=myfile.readlines()
   
data = [line.strip('\n').strip('\r').strip('\t') for line in data]
data = list(filter("".__ne__, data))

class Unit:
    def __init__(self, name, faction):
        self.name = name
        self.faction = faction
        self.timesFired = 0
        self.timesFiredHit = 0
        self.timesFiredAt = 0
        self.timesFiredAtHit = 0
        self.damageTaken = 0
        self.damageDealt = 0
       
        self.kick = False
        self.kicked = 0
        self.punch = 0
        self.punched = 0
        self.physTarget = None
        self.physDamage = 0
       
        self.lastPartHit = None
        self.crits = []
        self.destroyedParts = []
       
        self.destroyed = ""
        self.prone = False
        self.immobile = False
   
    def __str__(self):
        return "("+self.faction+") " + self.name
   
    def asList(self):
        l = []
        l.append("("+ self.faction +") " + self.name)
        if self.timesFired > 0:
            l.append("   Fired " + str(self.timesFired) + " times, hit " + str(self.timesFiredHit) + " times for " +str(self.damageDealt)+" damage")
        if self.damageTaken > 0 or self.timesFiredAt > 0:
            l.append("   Fired at " + str(self.timesFiredAt) + " times, hit " + str(self.timesFiredAtHit) + " times for " + str(self.damageTaken) +" damage")
        if self.kick:
            pd = " for " + str(self.physDamage) + " damage" if (self.physDamage > 0) else " and missed!"
            l.append("   Kicked " + str(self.physTarget) + pd)
        if self.punch > 0:
            pd = " " + str(self.punch) +" times for " + str(self.physDamage) + " damage" if (self.physDamage > 0) else " and missed!"
            l.append("   Punched " + str(self.physTarget) + pd)
        if self.punched > 0 or self.kicked > 0:
            l.append("   Was punched " + str(self.punched) + " times and kicked " + str(self.kicked) + " times.")
        if len(self.crits) > 0:
            l.append("   Crits received: " + ", ".join(self.crits))
        if len(self.destroyedParts) > 0:
            l.append("   Destroyed parts: " + ", ".join(self.destroyedParts))
        if self.prone:
            l.append("   PRONE")
        if self.immobile:
            l.append("   IMMOBILE")
        if len(self.destroyed) > 0:
            l.append("   DESTROYED ("+self.destroyed+")")
        return l

def getNextLine():
    global data
    line = data[0]
    data = data[1:]
    return line

faction = "\(([^\)]+?(?: *\(Reinforcements\))?)\)"
unitName = "([^\(]*(?: *\([^\)]+\))?(?: *#\d+)?) " + faction
weaponName = "([a-zA-Z/0-9 ]+)"
   
unitFire = re.compile('Weapons fire for ' + unitName)
unitPhys = re.compile('Physical attacks for ' + unitName)
weaponsFire = re.compile('[ ]*'+weaponName+' at '+unitName+'; needs \d+, rolls \d+ : (misses|hits)[ ]*(?:\([^\)]+\))?[ ]*([A-Z]+)?')
missileFire = re.compile('[ ]*'+weaponName+' at '+unitName+'; needs \d+, rolls \d+ : (misses|\d+ missile\(s\) hit)')
damageTaken = re.compile('[ ]*'+unitName+' takes (\d+) damage to ([A-Z]+)')
physAttack = re.compile('[ ]*(Kick|Punch)[ ]*(?:\([^\)]+\))? at '+unitName+'; needs \d+, rolls \d+ : (misses|hits)[ ]*(?:\([^\)]+\))?[ ]*([A-Z]+)?')
falling = re.compile('[ ]*'+unitName+' falls ')
critical = re.compile('CRITICAL HIT on ([^.]+).')
destroyedParts = re.compile('SECTION DESTROYED')
destroyed = re.compile('\*\*\* '+unitName+' DESTROYED by ([^!]+)! \*\*\*')
transferDamage = re.compile('(\d+) damage transfers to [A-Z]+')

units = dict()

def getUnit(name, faction):
    global units
    if name+faction not in units:
        units[name+faction] = Unit(name, faction)
    return units[name+faction]
   
currentUnit = None
targetUnit = None
physical = False

while len(data) > 0:
    line = getNextLine()
   
    # Check if this is a firing line
    r = unitFire.match(line)
    if r is not None:
        physical = False
        currentUnit = getUnit(r.group(1), r.group(2))
        targetUnit = None
        continue
   
    r = unitPhys.match(line)
    if r is not None:
        physical = True
        currentUnit = getUnit(r.group(1), r.group(2))
        targetUnit = None
        continue
   
    r = weaponsFire.search(line)
    if r is not None:
        currentUnit.timesFired += 1
        targetUnit = getUnit(r.group(2), r.group(3))
        targetUnit.timesFiredAt += 1
        if r.group(4) == "hits":
            currentUnit.timesFiredHit += 1
            targetUnit.timesFiredAtHit += 1
       
    r = missileFire.search(line)
    if r is not None:
        currentUnit.timesFired += 1
        targetUnit = getUnit(r.group(2), r.group(3))
        targetUnit.timesFiredAt += 1
        if r.group(4) != "misses":
            currentUnit.timesFiredHit += 1
            targetUnit.timesFiredAtHit += 1
        continue
   
    r = physAttack.search(line)
    if r is not None:
        targetUnit = getUnit(r.group(2), r.group(3))
        currentUnit.physTarget = targetUnit
        if r.group(1) == "Kick":
            currentUnit.kick = True
            if r.group(4) == "hits":
                targetUnit.kicked += 1
        elif r.group(1) == "Punch":
            currentUnit.punch += 1
            if r.group(4) == "hits":
                targetUnit.punched += 1
        continue

    r = falling.search(line)
    if r is not None:
        currentUnit = None
        targetUnit = getUnit(r.group(1), r.group(2))
        targetUnit.prone = True
       
    r = damageTaken.search(line)
    if r is not None:
        targetUnit.damageTaken += int(r.group(3))
        targetUnit.lastPartHit = r.group(4)
        if currentUnit is None:
            continue
        if physical:
            currentUnit.physDamage += int(r.group(3))
        else:
            currentUnit.damageDealt += int(r.group(3))
        continue   
   
    r = transferDamage.search(line)
    if r is not None:
        targetUnit.damageTaken -= int(r.group(1))
        if physical and currentUnit is not None:
            currentUnit.physDamage -= int(r.group(1))
        elif not physical and currentUnit is not None:
            currentUnit.damageDealt -= int(r.group(1))
   
    r = critical.search(line)
    if r is not None:
        targetUnit.crits.append(r.group(1) + "["+targetUnit.lastPartHit+"]")
   
    r = destroyedParts.search(line)
    if r is not None:
        targetUnit.destroyedParts.append(targetUnit.lastPartHit)
       
    r = destroyed.search(line)
    if r is not None:
        unit = getUnit(r.group(1), r.group(2))
        unit.destroyed = r.group(3)
   
   
factions = {}
def getFaction(name):
    global factions
    if name not in factions:
        factions[name] = {}
    return factions[name]

for unit in units.values():
    f = getFaction(unit.faction)
    f[unit.name] = unit

output = []
   
sortedFactions = sorted(factions.keys())
for factionName in sortedFactions:
    unitList = getFaction(factionName)
    sortedUnitList = sorted(unitList.keys())
    for unitName in sortedUnitList:
        output = output + unitList[unitName].asList() + [""]
       
   
with open ("round2.txt", "w") as myfile:
    myfile.write("\n".join(output))

Knave

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #260 on: December 02, 2015, 12:16:20 pm »

Anvil, seeing you whip up code quickly, makes me wish I had focused more on programming when I was younger  :'(
Logged

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #261 on: December 02, 2015, 12:25:30 pm »

Awesome, thanks!

I'd try fixing it myself, but I have maybe 5 minutes of experience with Python so far. ;)
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #262 on: December 02, 2015, 12:52:46 pm »

Don't underestimate what you can do! This is where I learned python (http://www.diveintopython.net/), though I did have some limited knowledge from before. The script uses regular expressions, which are just ways to see patterns in text and get out the information you want. Feel free to dig through the code (I could also comment it?) and let me know if you've got any questions!

Dive Into Python is cute, but I know there are also a bunch of really cool, interactive tutorials around the web. Definitely worth doing. It can be a lot more fun if you see something visual happening, so you could try to use fancy things like the Unity engine to see your programming in action :)

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #263 on: December 02, 2015, 01:42:38 pm »

Yeah, it's a question of when I get free time at work. I work with Powershell, C# and a custom language at work, along with QA Wizard Pro. Luckily, playing around with something like Python can go under training :)
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #264 on: December 02, 2015, 05:48:53 pm »

Sweet! If you already know how to do imperative languages, jumping into Python will be easy! It's just so much easier and faster to write in it :D And incredibly useful for these kinds of scripts. I've been using Powershell and a Notepad++ for programming in Python. Figured I wouldn't need anything more fancy than that :)

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #265 on: December 03, 2015, 03:47:23 am »

Episode 7 – Trial By Fire

Spoiler: Setup – Round 2 (click to show/hide)

Spoiler: Round 3 (click to show/hide)

Spoiler: Round 4 (click to show/hide)

Spoiler: Round 5 (click to show/hide)

Spoiler: Round 6 (click to show/hide)

Spoiler: Round 7 (click to show/hide)

Spoiler: Round 8 (click to show/hide)

Spoiler: Victory (click to show/hide)

Spoiler: Repairs (click to show/hide)
Logged

Rince Wind

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #266 on: December 03, 2015, 05:15:02 am »

Yes,  kick 'em good!

Also, I really like to switch that rear facing laser to the front in Centurions. It makes them a lot better in my opinion. And the heat is still fine.

Something still seemed to be off with the script, in the first round of combat the Hetzers are noted to have shot twice, which is clearly impossible.


One advice regarding the immobile vees: It seems, that even if you repair the motive system, the game doesn't acknowlegde that. It will show as fine in all screens, but still be immobile. You'll have to edit the damage in the hangar, then save, quit and reload.
Logged

Hanzoku

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #267 on: December 03, 2015, 08:09:16 am »

Yeah, I noticed that in the next game I was playing, it seems to double up its count most, but not all of the time.

Thanks for the advice, if I ever get a mechanic, I'll keep that in mind, and how to fix the problem. Of course, we need to manage to roll a mechanic first. :P
Logged

GentlemanRaptor

  • Bay Watcher
  • Got a present for ya!
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #268 on: December 03, 2015, 09:18:57 am »

Ow. My mech. Well, at least I tried. Gonna have to hope and pray for good repair rolls...
Logged
Amusingly, he's a Marksdwarf, which gives me the mental image of him conducting medical malpractice an appendectomy from fifty paces with a crossbow.
On bay12, a poll option of basically 'nuke the world' named 'Apocalypse Hitler' is like asking an alcoholic if they want some whiskey.

Knave

  • Bay Watcher
    • View Profile
Re: Let's Play MegaMek (Against the Bot campaign)
« Reply #269 on: December 03, 2015, 09:44:15 am »

Poor Quickdraw - hopefully we'll get it working in time for our next kick fest :)

Glad I was able to crush those pegasus'! Now I just need to have a rematch with that tricksy blackjack and my revenge will be complete.
Logged
Pages: 1 ... 16 17 [18] 19 20 ... 40