Last active
February 20, 2023 21:12
-
-
Save kjmehta01/3fd22ba247317a5a35fe94200c9e082a to your computer and use it in GitHub Desktop.
Data Collection from PandaBomber
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
// ==UserScript== | |
// @name Data Collection from PandaBomber | |
// @namespace https://pandabomber.gg/ | |
// @version 0.1 | |
// @description Demo on how to collect data from a PandaBomber game for AI research purposes. | |
// @author Kunal Mehta | |
// @match https://pandabomber.gg/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=pandabomber.gg | |
// @grant none | |
// ==/UserScript== | |
const boardHeight = 13; | |
const boardWidth = 19; | |
// called 20 times per second while game is going | |
pandabomber.socket.on('tick', (board, players) => { | |
// GATHER BOARD DATA SNAPSHOT FOR TICK | |
let boardData = []; | |
for(let row = 0; row < boardHeight; row++){ | |
let rowBoard = []; | |
for(let col = 0; col < boardWidth; col++){ | |
rowBoard.push(pandabomber.board.getBlock(row, col)); | |
} | |
boardData.push(rowBoard); | |
} | |
console.log(boardData); | |
// LEGEND: | |
// 'S' = stone | |
// 'W' = wood | |
// 'B' = bomb | |
// 'SPE' = speed pup | |
// 'STR' = strength pup | |
// 'NUM' = num bombs pup | |
// 'E' = empty | |
// GATHER PLAYER DATA SNAPSHOT FOR TICK | |
let playerData = []; | |
for(let i = 0; i < players.length; i++){ | |
playerData.push({ | |
y: players[i][0], | |
x: players[i][1], | |
isStunned: players[i][2], | |
isDead: players[i][3], | |
moveSpeed: players[i][4], | |
bombPower: players[i][5], | |
maxBombs: players[i][6] | |
}); | |
} | |
console.log(playerData); | |
let playerId = pandabomber.playerId; // num from 1 to 4 | |
// playerId - 1 is the index of the user player in the players array | |
}); | |
// called once at end of game | |
pandabomber.socket.on('game over', (gameWon, playerRank, timeElapsed) => { | |
// IF IN TIME TRIAL, use gameWon (true/false) and timeElapsed (number of seconds). gameWon to see if you completed the time trial and didnt die, timeElapsed to see how long it took | |
// IF MULTIPLAYER, look at playerRank. Array of player names sorted with the winner first. gameWon IS NOT ACCURATE HERE, it will always be false. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment