generated from CogitoNTNU/README-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Rename WebSocket variables in agentplayer.js for clarity
- Loading branch information
1 parent
0e2a8ef
commit 9c6d280
Showing
4 changed files
with
28 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Tetris AI Demo</title> | ||
<title>TetrisAI</title> | ||
</head> | ||
<body> | ||
<h1>Tetris AI Demo</h1> | ||
<h1>TetrisAI</h1> | ||
|
||
<label for="agent-select">Select Agent:</label> | ||
<select id="agent-select"> | ||
<!-- Agents will be dynamically populated --> | ||
</select> | ||
<!-- Get the options from endpoint --> | ||
<select id="agent-select"></select> | ||
<button id="start-demo">Start Demo</button> | ||
|
||
<canvas id="game-canvas" width="400" height="920"></canvas> | ||
|
||
<!-- Include the common shared logic --> | ||
|
||
<script src="tetris-common.js"></script> | ||
|
||
<!-- Include the single player logic --> | ||
<script src="singleplayer.js"></script> | ||
|
||
<!-- Include the agent demo logic --> | ||
<script src="agentplayer.js"></script> | ||
</body> | ||
</html> |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
// WebSocket connection for single-player mode | ||
const wsSingleplayer = new WebSocket("ws://127.0.0.1:8000/ws/game"); | ||
const singleplayerWebSocket = new WebSocket("ws://127.0.0.1:8000/ws/game"); | ||
|
||
wsSingleplayer.onopen = function () { | ||
singleplayerWebSocket.onopen = () => { | ||
console.log("Single-player WebSocket connection established"); | ||
}; | ||
|
||
wsSingleplayer.onmessage = function (event) { | ||
singleplayerWebSocket.onmessage = (event) => { | ||
const gameState = JSON.parse(event.data); | ||
console.log("Game state received from server:", gameState); | ||
drawBoard(gameState.board); // Render the updated board using shared function | ||
}; | ||
|
||
wsSingleplayer.onclose = function () { | ||
singleplayerWebSocket.onclose = () => { | ||
console.log("Single-player WebSocket connection closed"); | ||
}; | ||
|
||
wsSingleplayer.onerror = function (error) { | ||
singleplayerWebSocket.onerror = (error) => { | ||
console.error("WebSocket error:", error); | ||
}; | ||
|
||
// Sending input events to the server | ||
window.addEventListener("keydown", function (e) { | ||
window.addEventListener("keydown", (e) => { | ||
if (e.key === "ArrowDown") { | ||
wsSingleplayer.send("SOFT_DROP"); | ||
singleplayerWebSocket.send("SOFT_DROP"); | ||
} else if (e.key === "ArrowLeft") { | ||
wsSingleplayer.send("MOVE_LEFT"); | ||
singleplayerWebSocket.send("MOVE_LEFT"); | ||
} else if (e.key === "ArrowRight") { | ||
wsSingleplayer.send("MOVE_RIGHT"); | ||
singleplayerWebSocket.send("MOVE_RIGHT"); | ||
} else if (e.key === " ") { | ||
wsSingleplayer.send("HARD_DROP"); | ||
singleplayerWebSocket.send("HARD_DROP"); | ||
} else if (e.key === "ArrowUp") { | ||
wsSingleplayer.send("ROTATE_CLOCKWISE"); | ||
singleplayerWebSocket.send("ROTATE_CLOCKWISE"); | ||
} | ||
}); |