def __init__(self, coreNLPDirectory, port, language, glawiBz2FilePath,
                 glawiPklFilePath, lexiconsDirectory, spacyModelPath):

        print("Start NLP engine...")
        self.nlpEngine = NLPEngine(coreNLPDirectory=coreNLPDirectory,
                                   port=port,
                                   language=language,
                                   ip='',
                                   spacyModelPath=spacyModelPath)
        ## Load Glawi
        print("Load Glawi...")
        self.glawi = Glawi(glawiBz2FilePath=glawiBz2FilePath,
                           glawiPklFilePath=glawiPklFilePath)

        ## Load grammar rules
        print("Create grammatical rules...")
        grammaticalRules = GrammaticalRules()
        self.actionRules = grammaticalRules.getActionRules()
        self.informationRules = grammaticalRules.getInformationRules()
        self.informationYesOrNoRules = grammaticalRules.getInformationYesOrNoRules(
        )

        ## Load ressources
        print("Loading resources...")

        # ressources to get command type
        informationsKeyWords = list()
        informationsYesOrNoKeyWords = list()
        separator = os.sep

        for ruleFile in glob.glob(lexiconsDirectory + "informations" +
                                  separator + "rules" + separator + "*"):
            ResourceLoader.addGrammarResources(ruleFile, self.informationRules)

        for keyWordsFile in glob.glob(lexiconsDirectory + "informations" +
                                      separator + "keywords" + separator +
                                      "*"):
            ResourceLoader.addKeyWordsResources(keyWordsFile,
                                                informationsKeyWords)

        for ruleFile in glob.glob(lexiconsDirectory + "actions" + separator +
                                  "rules" + separator + "*"):
            ResourceLoader.addGrammarResources(ruleFile, self.actionRules)

        for ruleFile in glob.glob(lexiconsDirectory + "informations_yesOrNo" +
                                  separator + "rules" + separator + "*"):
            ResourceLoader.addGrammarResources(ruleFile,
                                               self.informationYesOrNoRules)

        for keyWordsFile in glob.glob(lexiconsDirectory +
                                      "informations_yesOrNo" + separator +
                                      "keywords" + separator + "*"):
            ResourceLoader.addKeyWordsResources(keyWordsFile,
                                                informationsYesOrNoKeyWords)

        self.nlpEngine.setSentenceClassifierKeyWords(
            informationsKeyWords, informationsYesOrNoKeyWords)
Пример #2
0
def show_point():
    global last_pipe, point
    if not bird.isDie and bird.begin_fly:
        arr = list(filter(lambda pipe:
                          bird.rect.x > (pipe.rect.x + pipe.rect.width) > 0,
                          pipes_botom))
        if arr:
            if last_pipe != arr[0]:
                point += 1
                last_pipe = arr[0]
                point_sound.play()

    point_str = str(point)
    num_image_list = []
    for num in point_str:
        num_image_list.append(ResourceLoader.get_image(ResourceLoader.NUMBER_IMAGES[int(num)]))
    numbers_width = len(point_str) * ResourceLoader.get_image(ResourceLoader.NUMBER_IMAGES[0]).get_rect().width
    first_num_x = (SCREEN_WIDTH - numbers_width) / 2

    for i in range(len(num_image_list)):
        SCREEN.blit(num_image_list[i], (first_num_x + i * numbers_width / len(point_str), 50))
Пример #3
0
def main():
    global CLOCK, SCREEN, bird, floor, point, last_pipe, point_sound
    pygame.init()  # 初始化pygame
    pygame.mixer.init()
    point_sound = ResourceLoader.get_sound("point.wav")
    wing_sound = ResourceLoader.get_sound("wing.wav")
    die_sound = ResourceLoader.get_sound("die.wav")
    CLOCK = pygame.time.Clock()
    SCREEN = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])  # 初始化一个用于显示的窗口
    pygame.display.set_caption('flappyBird')  # 设置窗口标题.

    bird = Bird(window_size, wing_sound, die_sound)
    floor = Floor(window_size)
    background = ResourceLoader.get_image("background-day.png")
    message = ResourceLoader.get_image("message.png")
    message_rect = (message.get_rect(centerx=SCREEN_WIDTH / 2, centery=SCREEN_HEIGHT / 2))
    reset()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_SPACE or event.key == K_UP:
                    if not bird.isDie:
                        bird.fly()
                    else:
                        reset()
        if not bird.isDie:
            bird.update()
            floor.update()
        SCREEN.blit(background, (0, 0))
        if not bird.begin_fly and not bird.isDie:
            SCREEN.blit(message, (message_rect.x, message_rect.y))
        else:
            for i in range(COUNT):
                center_y = make_center_y()
                pipe_top = pipes_top[i]
                pipe_botom = pipes_botom[i]
                if not bird.isDie:
                    pipe_top.update(center_y)
                    pipe_botom.update(center_y)
                SCREEN.blit(pipe_top.image, (pipe_top.rect.x, pipe_top.rect.y))
                SCREEN.blit(pipe_botom.image, (pipe_botom.rect.x, pipe_botom.rect.y))

        SCREEN.blit(floor.image, (floor.rect.x, floor.rect.y))
        SCREEN.blit(bird.get_bird_image(), (bird.rect.x, bird.rect.y))
        if bird.isDie:
            game_over = ResourceLoader.get_image("gameover.png")
            SCREEN.blit(game_over, (
                (SCREEN_WIDTH - game_over.get_rect().width) / 2, (SCREEN_HEIGHT - game_over.get_rect().height) / 2))
        if bird.begin_fly:
            show_point()
            if check_conlision():
                bird.die()

        pygame.display.flip()
        CLOCK.tick(FPS)
Пример #4
0
 def __init__(self, window_size, wing_sound, die_sound):
     super().__init__()
     self.images = ResourceLoader.get_images([
         "bluebird-midflap.png", "bluebird-upflap.png",
         "bluebird-downflap.png"
     ])
     self.image = self.images[0]
     self.rect = self.image.get_rect()
     self.currentY = self.rect.y
     self.status = 0
     self.window_size = window_size
     self.isDie = False
     self.begin_fly = False
     self.wing_sound = wing_sound
     self.die_sound = die_sound
     self.reset()
Пример #5
0
 def __init__(self, offset_x, offset_y, window_size, reverse,
              horizontal_distance, vertical_distance, center_y):
     super().__init__()
     self.offset_x = offset_x
     self.offset_y = offset_y
     self.window_size = window_size
     self.image = ResourceLoader.get_image("pipe-green.png")
     self.rect = self.image.get_rect()
     self.reverse = reverse
     self.horizontal_distance = horizontal_distance
     self.vertical_distance = vertical_distance
     self.center_y = center_y
     if reverse:
         self.image = pygame.transform.rotate(self.image, 180)
         self.rect.x = Pipe.top_index * (
             self.rect.width + self.horizontal_distance) + offset_x
         self.rect.y = center_y - self.rect.height - self.vertical_distance / 2
         Pipe.top_index += 1
     else:
         self.rect.x = Pipe.bottom_index * (
             self.rect.width + self.horizontal_distance) + offset_x
         self.rect.y = center_y + self.vertical_distance - self.vertical_distance / 2
         Pipe.bottom_index += 1
from TestingUtils import *

if __name__ == '__main__':
    add_source_folder()
    add_resource_folder()

    from ResourceLoader import *

    loader = ResourceLoader()
    print loader.load_resource_by_name_and_type('bomb', 'audio')

    for cache in loader.cache:
        print cache.name, cache.type
Пример #7
0
import pymongo
import sys
import os
import ResourceLoader
import ClassHandler as ch

#getting maps from DB
brickimg = ResourceLoader.LoadImage('brick.png')
woodimg = ResourceLoader.LoadImage('wood.png')

collection = ''

deflevel = []
for row in range(20):
    deflevel.append([])
    for column in range(25):
        deflevel[row].append(".")


def preInit():
    global collection

    client = pymongo.MongoClient(
        "mongodb+srv://Player:[email protected]/test?retryWrites=true&w=majority"
    )
    db = client['TonksDB']
    collection = db['Levels']


def GetLevelNames():
    request = collection.find({}, {'_id': 0, 'name': 1})
Пример #8
0
import pygame
import colorsys
import math
import random
import ResourceLoader as rs
import GraphicsHelper as gh

bulletimg = rs.LoadImage('bullet.png')

shotsnd = rs.LoadSound('Shot.ogg')
destroysnd = rs.LoadSound('destroy.ogg')
nickfont = pygame.font.Font('freesansbold.ttf', 14)

speed = 2.5
bulletspeed = 5


def FindNearest(tks,me):
    nearest = ''
    nearestdis = 20000000000000
    for tk in tks:
        if(tk != me.nick):
            dis = (me.x-tks[tk].x)**2+(me.y-tks[tk].y)**2
            if(dis < nearestdis):
                nearest = tks[tk]
                nearestdis = dis
    return nearest

def getSqrDistance(pos1,pos2):
    return (pos1[0]-pos2[0])**2+(pos1[1]-pos2[1])**2
Пример #9
0
import random
import threading
import os

pygame.init()

UpdateClock = pygame.time.Clock()
screen = pygame.display.set_mode((600, 600))

titlefont = pygame.font.Font('freesansbold.ttf', 40)
namefont = pygame.font.Font('freesansbold.ttf', 30)
buttonfont = pygame.font.Font('freesansbold.ttf', 26)
levelfont = pygame.font.Font('freesansbold.ttf', 18)
selectedRoom = 1

tonkimg = rs.LoadImage('tonk.png')
bots = []
levels = []
botnames = {
    'Tonkinator': ['hasta la vista, baby'],
    'Bender': ['I\'m gonna make my own tanks,', 'with blackjack and hookers'],
    'Tomas the dank engine': ['Tomas has seen enough'],
    'Копатыч': ['Укуси меня пчела'],
    'GladOS':
    ['Killing you and giving you advice', 'aren\'t mutually exclusive']
}
for i in range(5):
    bots.append(rs.LoadImage('bots/bot' + str(i + 1) + '.png'))

p1col = gh.createcol(0)
p2col = gh.createcol(180)
    from common.Scene import *
    from common.Stage import *
    from common.Transitions import *

    
    from common.gui.Layouts import *
    from common.gui.Buttons import *
    from common.gui.Sliders import *
    from models.ImageModels import *
    from models.TextModels import *
    from views.ImageView import *
    from views.TextViews import *
    from ResourceLoader import *

    loader = ResourceLoader()
    
    chk_image = loader.load_resource_by_name_and_type('check', 'image')
    x_image = loader.load_resource_by_name_and_type('x', 'image')

    chk_view = ImageView(ImageModel(chk_image))
    x_view = ImageView(ImageModel(x_image))

    font = loader.load_resources_by_type('font')[0]

    stage = Stage()

    scene = Scene('Toggle and Slider Test')
    scene.width = stage.width
    scene.height = stage.height
import NetworkHandler as net
import ClassHandler as ch
import GraphicsHelper as gh
import ResourceLoader as rs
import AIhandler as AIH
import json
import pygame
import threading
import random

SplashFont = pygame.font.Font('freesansbold.ttf', 50)
ScoreFont = pygame.font.Font('freesansbold.ttf', 34)
DescFont = pygame.font.Font('freesansbold.ttf', 44)
shotsnd = rs.LoadSound('Shot.ogg')

directions = {'UP': 0, 'RIGHT': 1, 'DOWN': 2, 'LEFT': 3}
token = ''
tonkid = ''
screen = ''
color = gh.createcol(0)
AI = False
AIs = {
    'GladOS': (200, 200),
    'Tomas the dank engine': (500, 100),
    'Копатыч': (10000, 1),
    'Tonkinator': (240, 140),
    'Bender': (300, 140)
}
tonks = {}
bullets = []
scores = {}
Пример #12
0
 def __init__(self, window_size):
     super().__init__()
     self.window_size = window_size
     self.image = ResourceLoader.get_image("base.png")
     self.rect = self.image.get_rect()
     self.rect.y = window_size.height - self.rect.height
Пример #13
0
gamestate = 1
buttonfont = pygame.font.Font('freesansbold.ttf', 26)
titlefont = pygame.font.Font('freesansbold.ttf', 40)
p1col = ''
p2col = ''
play = True
tk1 = ''
tk2 = ''
powertimer = 0
powerup = None
bullets = []
blocks = []
lvl = ''
lvlname = ''
repairsound = rs.LoadSound('Repair.ogg')

brickimg = rs.LoadImage('brick.png')
woodimg = rs.LoadImage('wood.png')


def intersect(colbox1,colbox2):
     return(colbox2[0] <= colbox1[0]+colbox1[2] and colbox2[1] <= colbox1[1]+colbox1[3]) and (colbox2[0]+colbox2[2] >= colbox1[0] and colbox2[1]+colbox2[3] >= colbox1[1])

def Menu():
    global play
    play = False

def Restart():
    global gamestate
    global tk1
Пример #14
0
 def __init__(self, color, position, positionModifier):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = ResourceLoader.load_image(ResourceLoader.getImagePathForColor(color), -1)
     self.position = position
     self.positionModifier = positionModifier
     self.changePosition(position)