Example #1
0
def mainloop(player0, player1):
    player0_char = attack.characters[player0]
    player1_char = attack.characters[player1]

    player0_char["health"] = attack.max_health(player0)
    player1_char["health"] = attack.max_health(player1)

    dmg = round(attack.attack(player0, player1, True, True),1)
    print player0, "sneak-attacks", player1, "for", dmg, "damage!", "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
    time.sleep(1)

    while round(player0_char["health"],1) > 0 and round(player1_char["health"],1) > 0:
        if round(player1_char["health"],1) > 0:
            dmg = round(attack.attack(player1, player0, False, True),1)
            if dmg > 0:
                print random.choice(ATTACKS).replace("%e",player0).replace("%p",player1).replace("%d",str(dmg)), "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
            else:
                print player1, "misses", player0, "completely!", "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
            time.sleep(1)
        if round(player0_char["health"],1) > 0:
            spell = ""
            if _MAGIC:
                spell = raw_input("Spell: ")
                
            if spell == "":
                dmg = round(attack.attack(player0, player1, False, True),1)
                if dmg > 0:
                    print random.choice(ATTACKS).replace("%e",player1).replace("%p",player0).replace("%d",str(dmg)), "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
                else:
                    print player0, "misses", player1, "completely!", "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
                time.sleep(1)
            else:
                dmg = round(attack.attack(player0, player1, False, True, spell),1)
                if dmg > 0:
                    print random.choice(MAGIC).replace("%e",player1).replace("%p",player0).replace("%d",str(dmg)), "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
                else:
                    print player0, "misses", player1, "completely!", "\n", player0 + ":", round(player0_char["health"],1), "hp,", player1 + ":", round(player1_char["health"],1), "hp\n"
                time.sleep(1)

    if round(player0_char["health"],1) > 0:
        print random.choice(KILLS).replace("%e",player1).replace("%p",player0)

        print "VICTOR:", player0
    elif round(player1_char["health"],1) > 0:
        print random.choice(KILLS).replace("%e",player0).replace("%p",player1)

        print "VICTOR:", player1
    else:
        print player0, "and", player1, "killed each other!"
        print "VICTOR: no-one"
Example #2
0
def buildDatabase(monFilePath, elementFilePath, attacksFilePath):
    #open files
    monFile = open(monFilePath, 'r')
    elementFile = open(elementFilePath, 'r')
    attackFile = open(attacksFilePath, 'r')
    
    #create monList
    #ignore first line
    monFile.readline()
    #readlines
    lines = monFile.readlines()
    monList = []
    #split line and append new mon to monList
    for member in lines:
        mLineInfo = member.split()
        monList.append(databaseMon(mLineInfo[0], mLineInfo[1], mLineInfo[2], mLineInfo[3], mLineInfo[4], mLineInfo[5], mLineInfo[6], mLineInfo[7], mLineInfo[8], mLineInfo[9] ))
    #print ("MonList[3] points: %s" % (monList[3].points))

    #create elementList
    #ignore first line
    elementFile.readline()
    #readlines
    lines = elementFile.readlines()
    elementList = []
    #split line and append new element to elementList
    for member in lines:
        eLineInfo = member.split()
        elementList.append(element(eLineInfo[0], eLineInfo[1], eLineInfo[2] ))
    #test
    #for member in elementList:
        #print ("name: %s strength: %s weakness: %s " %( member.name, member.strength, member.weakness))

    #create attackList
    #ignore first line
    attackFile.readline()
    #readlines
    lines = attackFile.readlines()
    attackList = []
    #split line and append new attack to attackList
    for member in lines:
        aLineInfo = member.split()
        #print"%s %s %s %s %s %s %s "%(aLineInfo[0], aLineInfo[1], aLineInfo[2], aLineInfo[3], aLineInfo[4], aLineInfo[5], aLineInfo[6])
        attackList.append(attack(aLineInfo[0], aLineInfo[1], aLineInfo[2], aLineInfo[3], aLineInfo[4], aLineInfo[5], aLineInfo[6]))
    #test
    #for member in attackList:
        #print ("name: %s element: %s : accuracy%s " %( member.name, member.element, member.accuracy))

    return monList, elementList, attackList
Example #3
0
        attacker_char["armor"] = atkarmor

        prev_dmg = 0
        i = 0

        for weapon in attack.weapons:
            target_char["weapon"] = weapon
            
            for armor in attack.materials:
                if armor == "cloth":
                    continue
                target_char["armor"] = armor

                good_dmg = 0
                for i in xrange(100):
                    good_dmg += attack.attack(attacker, target, False)
                good_dmg /= 100

                bad_dmg = 0
                for i in xrange(100):
                    bad_dmg += attack.attack(target, attacker)
                bad_dmg /= 100

                #print weapon, armor, dmg, bad_dmg

                dmg = good_dmg - bad_dmg

                #print weapon, armor, dmg

                prev_dmg += dmg
                i += 1
Example #4
0
#!/usr/bin/env python3
import attack
import sys
seed = 0
attempts = 0
for i in range(1, 10000):
    _, rc = attack.attack("wotsp_faulty_sigmas.txt", 20, 100, seed)
    if rc == -1:
        print("ERROR: forgery failed!")
    else:
        attempts += rc
    print(f"{rc};{attempts};{attempts/i};")
    sys.stdout.flush()
    seed += 1
Example #5
0
    their_health = 100
elif(new_or_load == 'l'):
    health_values = []
    with open("save_file.txt","r") as load_file:
        for item in load_file.read().split("\n"):
            health_values.append(item)
    my_health = int(health_values[0])
    their_health = int(health_values[1])
else:
    print("New Game then")
attack.print_status(my_health, their_health)
while(win == False):
    my_pick = input("Pick attack(a), block(b), quit(q) save(s): ")
    their_pick = attack.their_pick()
    if(my_pick =='a' and their_pick == 'a'):
        their_health = attack.attack(their_health,my_damage)
        my_health = attack.attack(my_health,their_damage)
    elif(my_pick == 'a' and their_pick == 'b'):
        their_health = attack.block(their_health,my_damage)
    elif(my_pick == 'b' and their_pick == 'a'):
        my_health = attack.block(my_health,their_damage)
    elif(my_pick =='b' and their_pick =='b'):
        print ("Whoosh!")
    elif(my_pick == 's'):
        with open("save_file.txt","w+") as save_file:
            save_file.write(str(my_health)+"\n")
            save_file.write(str(their_health)+"\n")
        break
    elif(my_pick =='q'):
        print("Quit!")
        break
Example #6
0
attacker = "septeract"
attacker_char = attack.characters[attacker]

prev_dmg = -1000000
best_weapon = "ERROR"
best_armor = "ERROR"

for weapon in attack.weapons:
    attacker_char["weapon"] = weapon
    
    for armor in attack.materials:
        attacker_char["armor"] = armor

        dmg = 0
        for i in xrange(100):
            dmg += attack.attack(attacker, target)
        dmg /= 100

        bad_dmg = 0
        for i in xrange(100):
            bad_dmg += attack.attack(target, attacker)
        bad_dmg /= 100

        #print weapon, armor, dmg, bad_dmg

        dmg -= bad_dmg

        #print weapon, armor, dmg

        if dmg > prev_dmg:
            prev_dmg = dmg
Example #7
0
smodel = resnext50_32x4d()
smodel = NormalizedModel(smodel, image_mean, image_std)
state_dict = torch.load(args.surrogate_model_path)
smodel.load_state_dict(state_dict)
smodel.eval().to(device)

# Sanity check: image correctly labeled by surrogate classifier:
assert smodel(t_img).argmax() == label

surrogate_models = [smodel]
attacks = [DDN(100, device=device), FGM_L2(1)]

adv = attack(black_box_model,
             surrogate_models,
             attacks,
             img,
             label,
             targeted=False,
             device=device)

pred_on_adv = black_box_model(adv)

print('True label: {}; Prediction on the adversarial: {}'.format(
    label, pred_on_adv))

# Compute l2 norm in range [0, 1]
l2_norm = np.linalg.norm(((adv - img) / 255))
print('L2 norm of the attack: {:.4f}'.format(l2_norm))
print('Saving adversarial image to "data/adv.png"')

imsave('data/adv.png', adv)