Пример #1
0
monitor = {
    "top": gameStartY,
    "left": gameStartX,
    "width": gameWidth,
    "height": gameHeight
}

#Image variables
NEW_SIZE = (400, 220)

#Model Variables
MODEL_NAME = "Self Driving Car.model"
model = SelfDrivingCarModel(inputShape=(NEW_SIZE[1], NEW_SIZE[0], 3))
model.load_weights(MODEL_NAME)

controller = vJoy()
controller.open()
resetController(controller)

AI_ENABLED = True
MIN_WORKING_RANGE_LEFT = 0.45
MIN_WORKING_RANGE_RIGHT = 0.55

numImages = 2
stackedImages = deque(maxlen=numImages)
previousTime = time.time()

index = 0

print("Running")
with mss.mss() as sct:
import time
import numpy as np
import buttonmap as bm
import vjoy

# initialize
vj = vjoy.vJoy()
vj.open()


def random_actions(array):
    xmove = array[:3]
    ymove = array[3:6]
    push = array[6:]
    xmove_index = np.where(array == max(xmove))[0]
    ymove_index = np.where(array == max(ymove))[0]
    push_index = np.where(array == max(push))[0]
    if xmove_index == 0:
        mvx = bm.xmax
    if xmove_index == 1:
        mvx = bm.xcent
    if xmove_index == 2:
        mvx = bm.xmin
    if ymove_index == 3:
        mvy = bm.ymax
    if ymove_index == 4:
        mvy = bm.ycent
    if ymove_index == 5:
        mvy = bm.ymin
    if push_index == 6:
        pb = bm.firergun
from vjoy import vJoy, ultimate_release
import numpy as np
import time
from getKeys import key_check

"""
    Run this code to check the connection between the virtual controller and the game.
    The vehicle should keep making circles in counter clock direction when the connection is successful
    ** Note that you need to press P to break the connection rather than terminating the code, as this could result in 
    crashing the vjoy driver  
"""

vj = vJoy()

x_range = 16393
z_range = 32786

wAxisX = 16393
wAxisY = 16393
wAxisZ = 0
wAxisXRot = 16393
wAxisYRot = 16393
wAxisZRot = 0

keys = key_check()
ultimate_release()

while True:
    vj.open()
    btn = 1
    joystickPosition = vj.generateJoystickPosition(wAxisX=12000, wAxisZ=32000, wAxisZRot=0)
Пример #4
0
import numpy as np
from grabscreen import grab_screen
import cv2
import time
from directkeys import PressKey,ReleaseKey, W, A, S, D
from models import inception_v3 as googlenet
from getkeys import key_check
from collections import deque, Counter
import random
from statistics import mode,mean
import numpy as np
from vjoy import vJoy, ultimate_release

vj = vJoy()

GAME_WIDTH = 1920
GAME_HEIGHT = 1080

how_far_remove = 800
rs = (20,15)
log_len = 25

motion_req = 800
motion_log = deque(maxlen=log_len)

WIDTH = 160
HEIGHT = 90
LR = 1e-3
EPOCHS = 10

DELTA_COUNT_THRESHOLD = 1000