def __init__(self, cell_size=9):

        self.cell_size = cell_size
        self.map = np.full((cell_size, cell_size), SERVO_MAX, np.uint16)
        self.worm = Worm(self.cell_size)
        self.gold = Gold(self.cell_size)

        #check object is overlapped
        if self.check_overlapped_object():
            self.gold.set_position(self.get_empty_position())
Beispiel #2
0
 def __init__(self, name):
     self.name = name
     self.hand = []
     self.played_cards = []
     for i in Ressources.LISTNAMESRESSOURCES:
         self.__dict__[Ressources(i)] = 0
     self.__dict__[Gold()] = 3
Beispiel #3
0
class Timed(object):
    # This is a self timing game. It takes the start time and takes the end time from it
    def __init__(self, more):
        self.names = more
        self.gold = Gold(self.names)
        self.death = Death("You forever burn in hell.")
        self.test1

    def test1(self):
        sleep(0.5)
        print "\033[34m%r\033[0m You enter a room with a button on a pillar right in the middle of the room" % self.names
        sleep(0.5)
        print "There are a set of instructions. You will need to press the button"
        sleep(0.5)
        print "Then count in your head to ten then press the button again."
        self.begin = raw_input("Press enter ")
        self.start = time.time()
        enter = raw_input("Press enter again after 10 seconds ")
        self.finish = time.time()
        end = int(self.finish) - int(self.start)
        if end <= 9:
            print end
            return self.death.dead()
# This gives you a bit of wigal room so you can go over by a few seconds
        elif end >= 10 and end <= 12:
            sleep(0.5)
            print "Wow you done it. You can count lol."
            sleep(0.5)
            print "Here is your reward."
            sleep(1)
            return self.gold.gold()
        else:
            return self.death.dead()
Beispiel #4
0
 def fight(self, HP, therehp, hitback, picker):
     self.gold = Gold(self.names)
     self.HP = HP
     self.therehp = therehp
     self.hitback = hitback
     self.picker = picker
     self.death = Death("You made it so far, but you died")
     while True:
         self.attacks = {'chop':random.randint(5, 10), 'thunder':random.randint(5, 15)}
         sleep(0.5)
         choose = raw_input("Pick a move 'chop' or 'thunder' > ")
         os.system('clear')
         self.therehp -= self.attacks[choose]
         print "You hit %r with \033[34m%r\033[0m and did \033[34m%r\033[0m damage" % (self.picker, choose, self.attacks[choose])
         sleep(0.5)
         if self.therehp > 0:
             print "%r has \033[34m%r\033[0m damage left" % (self.picker, self.therehp)
             sleep(0.5)
             self.HP -= self.hitback
             print "%r hits you back with a punch and does \033[1;31m%r\033[0m damage" % (self.picker, self.hitback)
             sleep(0.5)
             print "You have \033[1;31m%rHP\033[0m left" % self.HP
             sleep(0.5)
             if self.HP <= 0:
                 self.death()
                 break
         else:
             print "You deliver the final brow and %r faints" % self.picker
             print "You win with \033[34m%rHP\033[0m left" % self.HP
             sleep(1)
             self.gold.gold() 
Beispiel #5
0
class Timed(object):
# This is a self timing game. It takes the start time and takes the end time from it    
    def __init__(self, more):
        self.names = more
        self.gold = Gold(self.names)
        self.death = Death("You forever burn in hell.")
        self.test1
                            
    def test1(self):
        sleep(0.5)
        print "\033[34m%r\033[0m You enter a room with a button on a pillar right in the middle of the room" % self.names
        sleep(0.5)
        print "There are a set of instructions. You will need to press the button"
        sleep(0.5)
        print "Then count in your head to ten then press the button again."
        self.begin = raw_input("Press enter ")
        self.start = time.time()
        enter = raw_input("Press enter again after 10 seconds ")
        self.finish = time.time()
        end = int(self.finish) - int(self.start)
        if end <= 9:
            print end
            return self.death.dead()
# This gives you a bit of wigal room so you can go over by a few seconds
        elif end >= 10 and end <= 12:
            sleep(0.5)
            print "Wow you done it. You can count lol."
            sleep(0.5)
            print "Here is your reward."
            sleep(1)
            return self.gold.gold()
        else:
            return self.death.dead()
Beispiel #6
0
    def test_gold(self):
        fake_json = [{'Class': "Python"}]

        with patch('gold.requests.get') as mock_get:
            mock_get.return_value.status_code = 200
            mock_get.return_value.json.return_value = fake_json

            obj = Gold()
            response = obj.get

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), fake_json)
class Snake:
    def __init__(self, cell_size=9):

        self.cell_size = cell_size
        self.map = np.full((cell_size, cell_size), SERVO_MAX, np.uint16)
        self.worm = Worm(self.cell_size)
        self.gold = Gold(self.cell_size)

        #check object is overlapped
        if self.check_overlapped_object():
            self.gold.set_position(self.get_empty_position())

    def draw_matrix(self):
        self.map = np.full((self.cell_size, self.cell_size), SERVO_MAX,
                           np.uint16)
        for wormBody in self.worm.coordinate:
            self.map[wormBody['y']][wormBody['x']] = SERVO_MIN
        self.map[self.gold.y][self.gold.x] = SERVO_MIN

    def check_overlapped_object(self):
        #check gold
        for wormBody in self.worm.coordinate:
            if wormBody['x'] == self.gold.x and wormBody['y'] == self.gold.y:
                return True

    def get_empty_position(self):
        positions = []
        for x in range(self.cell_size):
            for y in range(self.cell_size):
                positions.append([y, x])

        for wormBody in self.worm.coordinate:
            positions.remove([wormBody['y'], wormBody['x']])

        if [self.gold.y, self.gold.x] in positions:
            positions.remove([self.gold.y, self.gold.x])

        return positions[random.randint(0, len(positions) - 1)]
Beispiel #8
0
 def fight(self, HP, therehp, hitback, picker):
     self.gold = Gold(self.names)
     self.HP = HP
     self.therehp = therehp
     self.hitback = hitback
     self.picker = picker
     self.death = Death("You made it so far, but you died")
     while True:
         self.attacks = {
             'chop': random.randint(5, 10),
             'thunder': random.randint(5, 15)
         }
         sleep(0.5)
         choose = raw_input("Pick a move 'chop' or 'thunder' > ")
         os.system('clear')
         self.therehp -= self.attacks[choose]
         print "You hit %r with \033[34m%r\033[0m and did \033[34m%r\033[0m damage" % (
             self.picker, choose, self.attacks[choose])
         sleep(0.5)
         if self.therehp > 0:
             print "%r has \033[34m%r\033[0m damage left" % (self.picker,
                                                             self.therehp)
             sleep(0.5)
             self.HP -= self.hitback
             print "%r hits you back with a punch and does \033[1;31m%r\033[0m damage" % (
                 self.picker, self.hitback)
             sleep(0.5)
             print "You have \033[1;31m%rHP\033[0m left" % self.HP
             sleep(0.5)
             if self.HP <= 0:
                 self.death()
                 break
         else:
             print "You deliver the final brow and %r faints" % self.picker
             print "You win with \033[34m%rHP\033[0m left" % self.HP
             sleep(1)
             self.gold.gold()
        def generateEncounter():
            enc_dict = {}

            if random.choice([True, False]):  #Generates Gold
                g = Gold()
            else:
                g = None
            enc_dict["gold"] = g

            if random.choice([True, False]):  #Generates items
                i = random.choice([Weapon(), Potion(), Artifact()])
            else:
                i = None
            enc_dict["item"] = i

            if random.choice([True, False]):
                enc_dict["monster"] = Monster()
                enc_dict["trap"] = None
            else:
                enc_dict["trap"] = Trap()
                enc_dict["monster"] = None

            return enc_dict
Beispiel #10
0
 def __init__(self, more):
     self.names = more
     self.gold = Gold(self.names)
     self.death = Death("You forever burn in hell.")
     self.test1
Beispiel #11
0
class SecondAttack(object):
    # Here i load the name and HP from the last class
    def __init__(self, more, name):
        self.HP = more
        self.names = name
        self.mario = 20
        self.luigi = 30
        self.wario = 40
        self.hitback = random.randint(5, 20)
# Here you are asked again who you want to battle

    def battle(self):
        os.system('clear')
        sleep(0.5)
        print "%r You made it to the next room with \033[34m%rHP\033[0m" % (
            self.names, self.HP)
        sleep(0.5)
        print "You need to pick one last contender"
        sleep(0.5)
        print "You have learnt new moves 'chop' and 'thunder'"
        sleep(0.5)
        print "Who do you want to pick \033[1;31m'mario'\033[0m, \033[1;32m'luigi'\033[0m or \033[1;35m'wario'\033[0m."
        sleep(0.5)
        self.picker = raw_input("Pick one > ")
        os.system('clear')
        if self.picker == "mario":
            print "You come up against \033[1;31mmario\033[0m they have %rHP" % self.mario
            self.fight(self.HP, self.mario, self.hitback, self.picker)
        elif self.picker == "luigi":
            print "You come up against \033[1;32mluigi\033[0m they have %rHP" % self.luigi
            self.fight(self.HP, self.luigi, self.hitback, self.picker)
        elif self.picker == "wario":
            print "You come up against \033[1;35mwario\033[0m they have %rHP" % self.wario
            self.fight(self.HP, self.wario, self.hitback, self.picker)
        else:
            print "You need to pick one"
            self.battle()
# This is pritty much the same as the last class but also loads the gold room for if/when i win

    def fight(self, HP, therehp, hitback, picker):
        self.gold = Gold(self.names)
        self.HP = HP
        self.therehp = therehp
        self.hitback = hitback
        self.picker = picker
        self.death = Death("You made it so far, but you died")
        while True:
            self.attacks = {
                'chop': random.randint(5, 10),
                'thunder': random.randint(5, 15)
            }
            sleep(0.5)
            choose = raw_input("Pick a move 'chop' or 'thunder' > ")
            os.system('clear')
            self.therehp -= self.attacks[choose]
            print "You hit %r with \033[34m%r\033[0m and did \033[34m%r\033[0m damage" % (
                self.picker, choose, self.attacks[choose])
            sleep(0.5)
            if self.therehp > 0:
                print "%r has \033[34m%r\033[0m damage left" % (self.picker,
                                                                self.therehp)
                sleep(0.5)
                self.HP -= self.hitback
                print "%r hits you back with a punch and does \033[1;31m%r\033[0m damage" % (
                    self.picker, self.hitback)
                sleep(0.5)
                print "You have \033[1;31m%rHP\033[0m left" % self.HP
                sleep(0.5)
                if self.HP <= 0:
                    self.death()
                    break
            else:
                print "You deliver the final brow and %r faints" % self.picker
                print "You win with \033[34m%rHP\033[0m left" % self.HP
                sleep(1)
                self.gold.gold()
Beispiel #12
0
def main(model, id, text, tokens=False, debug=False):
    level = logging.DEBUG if debug else logging.WARNING
    logging.basicConfig(level=level, format='%(message)s')

    if text:
        CORPUS = [{'id': 1, 'text': text, 'relations': []}]
    elif is_spanish(model):
        CORPUS = CORPUS_ES
    else:
        CORPUS = CORPUS_EN

    if (id <= 0):
        print("Processing %d texts" % len(CORPUS))
    print()

    # start time
    start = timeit.default_timer()

    nlp = Nlpy.load(model)
    gold = Gold(nlp)
    num_docs_processed = 0
    show_warning = False
    for sample in CORPUS:
        doc_id = sample['id']
        if (id > 0 and id != doc_id):
            continue  # skip

        num_docs_processed += 1

        text = sample['text']
        print(text)
        doc = nlp(text)

        if (True == tokens):
            print()
            print('{:20}\t{:10}\t{:10}\t{:10}'.format('NORM', 'POS', 'DEP',
                                                      'LABEL'))
            print()
            for t in doc:
                print('{:20}\t{:10}\t{:10}\t{:10}'.format(
                    t.norm_, t.pos_, t.dep_, t.ent_type_))
            print()

        num_found = 0
        for r in doc._.relations:
            num_found += 1
            if r.w:
                print('({} / {}, {}, {} / {}, {}) [x: {}]'.format(
                    r.s, ent_types(r.s), r.p, r.o, ent_types(r.o), r.w, r.x))
            else:
                print('({} / {}, {}, {} / {}) [x: {}]'.format(
                    r.s, ent_types(r.s), r.p, r.o, ent_types(r.o), r.x))

        if (0 == num_found):
            print('No relations!')

            if (True == debug):
                _DEBUG = True
                if (len(doc.ents) == 0):
                    print('No entities!')
                else:
                    print('entities:')
                    for e in doc.ents:
                        print('  {}/{}'.format(e.text, e.label_))

        # gold scoring for this document
        doc_scoring = gold.add(doc, doc_id, sample['relations'])
        if (None == doc_scoring):
            COLOR = bcolors.FAIL
            print('FAILED to get scoring for doc:', doc_id)
        else:
            COLOR = bcolors.DEFAULT

        if (doc_scoring.f1score() < 1.0):
            show_warning = True
            COLOR = bcolors.WARNING
        else:
            COLOR = bcolors.DEFAULT

        print(COLOR +
              'doc-id: {} f1-score: {} (precision: {}, recall: {})'.format(
                  doc_id, doc_scoring.f1score(), doc_scoring.precision(),
                  doc_scoring.recall()))

        COLOR = bcolors.DEFAULT
        print(COLOR)

    # print summary if processing more than 1 document
    if (num_docs_processed >= 2):
        if (show_warning):
            print(bcolors.WARNING + "some documents didn't pass!")
        else:
            print(bcolors.OKGREEN + 'all OK.')
        # print overall scoring
        overall_scoring = gold.scoring()
        print(
            bcolors.DEFAULT +
            '{} documents, overall scoring: f1-score: {} (precision: {}, recall: {})'
            .format(num_docs_processed, overall_scoring.f1score(),
                    overall_scoring.precision(), overall_scoring.recall()))
        print('timeit: {0:.2f} sec'.format(timeit.default_timer() - start))
# Create a 'list' of everything the sprites could say
all_info = [
    "I have nothing to say.", "I think you should go north.", "Try digging.",
    """It's a figure of speech, Morty. They're bureaucrats. 
            I don't respect them. Just keep shooting!"""
]

# Create Sprites
sprite1 = Sprite()
sprite1.x, sprite1.y = 100, 100
sprite1.image = sprite1.load_image()
screen.blit(sprite1.image, (sprite1.x, sprite1.y))

sprite2 = Sprite()
sprite2.x, sprite2.y = 400, 300
sprite2.image_path = "images/white_square.png"
sprite2.image = sprite2.load_image()
screen.blit(sprite2.image, (sprite2.x, sprite2.y))
sprite2.randomize_info(all_info)

# Create pot(s) of gold
gold1 = Gold(width, height)
gold2 = Gold(width, height)

# collect objects into lists
visible_things = [player1, sprite1, sprite2]
players = [player1]
sprites = [sprite1, sprite2]
golds = [gold1, gold2]
Beispiel #14
0
class SecondAttack(object):
# Here i load the name and HP from the last class
    def __init__(self, more, name):
        self.HP = more
        self.names = name        
        self.mario = 20
        self.luigi = 30
        self.wario = 40
        self.hitback = random.randint(5, 20)
# Here you are asked again who you want to battle        
    def battle(self):
        os.system('clear')
        sleep(0.5)
        print "%r You made it to the next room with \033[34m%rHP\033[0m" % (self.names, self.HP)
        sleep(0.5)
        print "You need to pick one last contender"
        sleep(0.5)
        print "You have learnt new moves 'chop' and 'thunder'"
        sleep(0.5)
        print "Who do you want to pick \033[1;31m'mario'\033[0m, \033[1;32m'luigi'\033[0m or \033[1;35m'wario'\033[0m."
        sleep(0.5)
        self.picker = raw_input("Pick one > ")
        os.system('clear')
        if self.picker == "mario":
            print "You come up against \033[1;31mmario\033[0m they have %rHP" % self.mario
            self.fight(self.HP, self.mario, self.hitback, self.picker)
        elif self.picker == "luigi":
            print "You come up against \033[1;32mluigi\033[0m they have %rHP" % self.luigi
            self.fight(self.HP, self.luigi, self.hitback, self.picker)
        elif self.picker == "wario":
            print "You come up against \033[1;35mwario\033[0m they have %rHP" % self.wario
            self.fight(self.HP, self.wario, self.hitback, self.picker)
        else:
            print "You need to pick one"
            self.battle()
# This is pritty much the same as the last class but also loads the gold room for if/when i win        
    def fight(self, HP, therehp, hitback, picker):
        self.gold = Gold(self.names)
        self.HP = HP
        self.therehp = therehp
        self.hitback = hitback
        self.picker = picker
        self.death = Death("You made it so far, but you died")
        while True:
            self.attacks = {'chop':random.randint(5, 10), 'thunder':random.randint(5, 15)}
            sleep(0.5)
            choose = raw_input("Pick a move 'chop' or 'thunder' > ")
            os.system('clear')
            self.therehp -= self.attacks[choose]
            print "You hit %r with \033[34m%r\033[0m and did \033[34m%r\033[0m damage" % (self.picker, choose, self.attacks[choose])
            sleep(0.5)
            if self.therehp > 0:
                print "%r has \033[34m%r\033[0m damage left" % (self.picker, self.therehp)
                sleep(0.5)
                self.HP -= self.hitback
                print "%r hits you back with a punch and does \033[1;31m%r\033[0m damage" % (self.picker, self.hitback)
                sleep(0.5)
                print "You have \033[1;31m%rHP\033[0m left" % self.HP
                sleep(0.5)
                if self.HP <= 0:
                    self.death()
                    break
            else:
                print "You deliver the final brow and %r faints" % self.picker
                print "You win with \033[34m%rHP\033[0m left" % self.HP
                sleep(1)
                self.gold.gold() 
Beispiel #15
0
 def __init__(self, more):
     self.names = more
     self.gold = Gold(self.names)
     self.death = Death("You forever burn in hell.")
     self.test1