This file contains 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 numpy as np | |
env = gym.make('CartPole-v1') | |
def play(env, policy): | |
observation = env.reset() | |
done = False | |
score = 0 |
This file contains 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 numpy as np | |
env = gym.make('CartPole-v1') | |
def play(env, policy): | |
observation = env.reset() | |
done = False | |
score = 0 |
This file contains 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
<!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 */ |
This file contains 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 numpy as np | |
env = gym.make('CartPole-v1') | |
def play(env, policy): | |
observation = env.reset() | |
done = False | |
score = 0 |
This file contains 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 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! |
This file contains 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 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! |
This file contains 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
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 |
This file contains 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
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! |
This file contains 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
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'; |
This file contains 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 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; |
NewerOlder