This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getwindowgeometry(): | |
| while True: | |
| output = subprocess.getstatusoutput(f'xdotool search --name Counter-Strike getwindowgeometry') | |
| if output[0] == 0: | |
| t1 = time.time() | |
| LIST = output[1].split("\n") | |
| Window = LIST[0][7:] | |
| Position = LIST[1][12:-12] | |
| x, y = Position.split(",") | |
| x, y = int(x), int(y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while True: | |
| t1 = time.time() | |
| img = np.array(sct.grab({"top": y-30, "left": x, "width": w, "height": h, "mon": -1})) | |
| img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB) | |
| image, detection_list, bboxes = detect_enemy(yolo, np.copy(img), input_size=YOLO_INPUT_SIZE, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) | |
| cv2.circle(image,(int(w/2),int(h/2)), 3, (255,255,255), -1) # center of weapon sight | |
| th_list, t_list = [], [] | |
| for detection in detection_list: | |
| diff_x = (int(w/2) - int(detection[1]))*-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gym | |
| import random | |
| env = gym.make("LunarLander-v2") | |
| def Random_games(): | |
| # Each of this episode is its own game. | |
| for episode in range(10): | |
| env.reset() | |
| # this is each frame, up to 500...but we wont make it that far with random. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Actor_Model: | |
| def __init__(self, input_shape, action_space, lr, optimizer): | |
| X_input = Input(input_shape) | |
| self.action_space = action_space | |
| X = Dense(512, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X_input) | |
| X = Dense(256, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X) | |
| X = Dense(64, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X) | |
| output = Dense(self.action_space, activation="softmax")(X) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Critic_Model: | |
| def __init__(self, input_shape, action_space, lr, optimizer): | |
| X_input = Input(input_shape) | |
| old_values = Input(shape=(1,)) | |
| V = Dense(512, activation="relu", kernel_initializer='he_uniform')(X_input) | |
| V = Dense(256, activation="relu", kernel_initializer='he_uniform')(V) | |
| V = Dense(64, activation="relu", kernel_initializer='he_uniform')(V) | |
| value = Dense(1, activation=None)(V) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_gaes(self, rewards, dones, values, next_values, gamma = 0.99, lamda = 0.9, normalize=True): | |
| deltas = [r + gamma * (1 - d) * nv - v for r, d, nv, v in zip(rewards, dones, next_values, values)] | |
| deltas = np.stack(deltas) | |
| gaes = copy.deepcopy(deltas) | |
| for t in reversed(range(len(deltas) - 1)): | |
| gaes[t] = gaes[t] + (1 - dones[t]) * gamma * lamda * gaes[t + 1] | |
| target = gaes + values | |
| if normalize: | |
| gaes = (gaes - gaes.mean()) / (gaes.std() + 1e-8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def replay(self, states, actions, rewards, predictions, dones, next_states): | |
| # reshape memory to appropriate shape for training | |
| states = np.vstack(states) | |
| next_states = np.vstack(next_states) | |
| actions = np.vstack(actions) | |
| predictions = np.vstack(predictions) | |
| # Get Critic network predictions | |
| values = self.Critic.predict(states) | |
| next_values = self.Critic.predict(next_states) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def run_batch(self): # train every self.Training_batch episodes | |
| state = self.env.reset() | |
| state = np.reshape(state, [1, self.state_size[0]]) | |
| done, score, SAVING = False, 0, '' | |
| while True: | |
| # Instantiate or reset games memory | |
| states, next_states, actions, rewards, predictions, dones = [], [], [], [], [], [] | |
| for t in range(self.Training_batch): | |
| self.env.render() | |
| # Actor picks an action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gym | |
| import random | |
| import numpy as np | |
| env = gym.make("BipedalWalker-v3") | |
| def Random_games(): | |
| # Each of this episode is its own game. | |
| action_size = env.action_space.shape[0] | |
| for episode in range(10): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Actor_Model: | |
| def __init__(self, input_shape, action_space, lr, optimizer): | |
| X_input = Input(input_shape) | |
| self.action_space = action_space | |
| X = Dense(512, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X_input) | |
| X = Dense(256, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X) | |
| X = Dense(64, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X) | |
| output = Dense(self.action_space, activation="tanh")(X) |