- As you're watching the replay on the website (e.g. this http://ai-contest.com/visualizer.php?game_id=4738603), pause it just before the move in question.
- Copy and paste the code below into the website's URL bar (including the "javascript:" part in the begining; tested on Chrome and FF) :
- Code: Select all
javascript: (function() {
var povSelectorString = '<select id="me_povSelector" style="margin:10px;"></select>';
var refreshButton = '<input id="me_refresh" type="Submit" value="Refresh" style="margin-left:50px;"/>';
var wholeReplayCheckbox = '<input id="me_whole_replay" type="checkbox" style="margin: 10px 3px 15px 50px;"/> Whole Replay';
var povContainerString = '<p>Point of view: ' + povSelectorString +
refreshButton + wholeReplayCheckbox +'</p>';
var textAreaString = '<textarea id="me_mapState" cols="80" rows="30"' +
' style="margin-top: 10px;"></textarea>';
var formString = '<form style="margin-top: 10px;">' + povContainerString +
textAreaString + '</form>';
var visualizerContainer = $("#visualizer");
if (visualizerContainer.length == 0) {
visualizerContainer = $("#main");
}
visualizerContainer.append(formString);
var povSelector = $('#me_povSelector');
var refreshButton = $("#me_refresh");
var mapElement = $('#me_mapState');
var wholeReplayCheckbox = $('#me_whole_replay');
povSelector.append('<option value="1">' + Visualizer.players[0] + '</option>');
povSelector.append('<option value="2">' + Visualizer.players[1] + '</option>');
var mapElement = $('#me_mapState');
function getMapState(pov) {
var mapText = "";
var planets = Visualizer.planets;
var numPlanets = planets.length;
for (var p = 0; p < numPlanets; p++) {
var planet = planets[p];
var actual_owner = planet.owner;
var pov_owner = 0;
if (actual_owner != 0) {
pov_owner = (pov == actual_owner ? 1 : 2);
}
mapText += "P " + planet.x + " " + planet.y + " " + pov_owner +
" " + planet.numShips + " " + planet.growthRate + "\n";
}
var frame = Math.floor(Visualizer.frame);
var fleets = Visualizer.moves[frame].moving;
var numFleets = fleets.length;
var i = 0;
for (var f = 0; f < numFleets; f++) {
var fleet = fleets[f];
var actual_owner = fleet.owner;
var pov_owner = (pov == actual_owner ? 1 : 2);
var sourceX = fleet.source.x;
var sourceY = fleet.source.y;
var destinationX = fleet.destination.x;
var destinationY = fleet.destination.y;
var source = -1;
var destination = -1;
var foundSource = false;
var foundDestination = false;
for (i = 0; i < numPlanets; i++) {
var planet = planets[i];
if (planet.x == sourceX && planet.y == sourceY) {
source = i;
} else if (planet.x == destinationX && planet.y == destinationY) {
destination = i;
}
}
mapText += "F " + pov_owner + " " + fleet.numShips + " " +
source + " " + destination + " " + fleet.tripLength +
" " + (fleet.tripLength - fleet.progress) + "\n";
}
mapText += "go\n\n";
return mapText;
}
function getGameReplay(pov) {
var upToTurn = Math.floor(Visualizer.frame);
var wholeFrame = true;
var replayText = "";
for (var t = 0; t <= upToTurn; t++) {
Visualizer.setFrame(t, wholeFrame);
Visualizer.drawFrame(Visualizer.frame);
replayText += getMapState(pov);
}
return replayText;
}
povSelector.change(function() {
var pov = $(this).val();
var outputText = '';
if ($('#me_whole_replay:checked').length > 0) {
outputText = getGameReplay(pov);
} else {
outputText = getMapState(pov);
}
mapElement.text(outputText);
});
refreshButton.click(function() {
povSelector.change();
return false;
});
wholeReplayCheckbox.change(function() {
povSelector.change();
});
povSelector.change();
})();
- Scroll down to the bottom where the new textarea appears; there you will see the map data as (theoretically) accepted by game engine. The map is from point of view of the player in the drop-down box (i.e. that player is player 1 in the map data). You can change that by changing the player. Also, you can forward/reverse the game any number of steps and click "refresh" -- that should update the map data in the textarea.
- Start your bot in debug mode (without the game engine; just run it, a blank console screen should appear), and then paste the map directly as the bot's input, including the "go" at the end of the game state data.
- If you'd like your bot to replay the game all the way from the start to the turn in question, check the "Whole Replay" check box, copy everything in the text area, start your bot (by itself, without a game engine), and paste everything into it. It should then (hopefully) replay the game from start all the way to the turn of interest.
- Alternatively, copy the map data in the text area (minus the "go" at the end), create a new map file ("new_map.txt"), paste it there. Feed it to the game engine, or your favourite bot debugging tool (e.g. mine, but if you're gonna use it make sure to download a newer version here or it'll crash.). Debug your bot as usual.
- if you don't feel like copying the code above every time, you can create a bookmarklet by creating a browser bookmark with the code above instead of a URL. Then next time you're on the game replay page, you can just click on the bookmark.