Skip to content

Instantly share code, notes, and snippets.

View MikeShi42's full-sized avatar
💭
🚀

Mike Shi MikeShi42

💭
🚀
View GitHub Profile
@MikeShi42
MikeShi42 / main.py
Created September 18, 2018 03:04
CartPole Main.py Checkpoint 3
import gym
import numpy as np
env = gym.make('CartPole-v1')
def play(env, policy):
observation = env.reset()
done = False
score = 0
@MikeShi42
MikeShi42 / main.py
Created September 18, 2018 03:01
CartPole Main.py Checkpoint 2
import gym
import numpy as np
env = gym.make('CartPole-v1')
def play(env, policy):
observation = env.reset()
done = False
score = 0
@MikeShi42
MikeShi42 / index.html
Last active September 18, 2018 03:37
CartPole Index.html Renderer
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Cart Pole Render</title>
<style>
#container {
background: #ffafbd; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #ffafbd, #ffc3a0); /* Chrome 10-25, Safari 5.1-6 */
@MikeShi42
MikeShi42 / main.py
Created September 18, 2018 02:50
CartPole Main.py Checkpoint 1
import gym
import numpy as np
env = gym.make('CartPole-v1')
def play(env, policy):
observation = env.reset()
done = False
score = 0
class GameManager {
constructor(socket, remotePlayer, size, InputManager, Actuator, StorageManager) {
...
// Add this new if statement
if (this.remotePlayer) {
this.socket.on('move', this.handleRemoteMove.bind(this));
}
// No setup!
class GameManager {
constructor(socket, remotePlayer, size, InputManager, Actuator, StorageManager) {
...
// Add this new if statement
if (this.remotePlayer) {
this.socket.on('move', this.handleRemoteMove.bind(this));
}
// No setup!
window.requestAnimationFrame(function () {
...
localGame = new GameManager(socket, false, 4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
// Add this socket lisetner
socket.on('player-number', function (playerNumber) {
if (playerNumber == 1) {
waitingPlayerTwo(true); // Show waiting message
// On 2nd player connect, start the game
function startGame() {
let seconds = 4; // Number of seconds + 1 to wait
// Start a countdown timer
const intervalId = setInterval(function() {
// Subtract the number of seconds left and update UI
seconds--;
countdownMessage(true, seconds);
if (seconds == 0) { // It's time to start the game!
function waitingPlayerTwo(show) {
const messageContainer = document.querySelector('.waiting-message');
messageContainer.style.display = show ? 'block' : 'none';
}
function countdownMessage(show, number) {
const messageContainer = document.querySelector('.countdown-message');
const countdownNumber = document.querySelector('.countdown-number');
messageContainer.style.display = show ? 'block' : 'none';
@import url(fonts/clear-sans.css);
/* Styling to make the message containers look nice */
.message-container {
background: #8e7967;
color: white;
text-align: center;
padding: 1em;
margin: 1em;
font-weight: bold;