Skip to content

Instantly share code, notes, and snippets.

@JohnyDays
Created November 23, 2015 14:25
Show Gist options
  • Save JohnyDays/ebff1435d5ed94e3119b to your computer and use it in GitHub Desktop.
Save JohnyDays/ebff1435d5ed94e3119b to your computer and use it in GitHub Desktop.
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
var inputs = readline().split(' ');
var node_amount = parseInt(inputs[0]); // the total number of nodes in the level, including the gateways
var link_amount = parseInt(inputs[1]); // the number of links
var exit_amount = parseInt(inputs[2]); // the number of exit gateways
//printErr("Nodes: " + node_amount, "Links: " + link_amount, "Exits: " + exit_amount)
var links = []
for (var i = 0; i < link_amount; i++) {
var inputs = readline().split(' ');
links.push([
parseInt(inputs[0]),
parseInt(inputs[1])
])
}
printErr("Links: " + links)
var exits = []
for (var i = 0; i < exit_amount; i++) {
exits.push(parseInt(readline()))
}
printErr("Exits: " + exits)
function decideExit(possible, agent_position, _links, _exits) {
var near_agent = possible.filter(function (exit) {
return exit[0] === agent_position || exit[1] == agent_position
})
if (near_agent.length > 0) {
return near_agent[0]
}
var near_agent_links = _links.filter(function (link) {
return link[0] === agent_position || link[1] == agent_position
})
var near_agent_link_exits = _exits.filter(function (exit) {
for (var i = 0; i < near_agent_links.length; i++) {
var node = near_agent_links[i]
if (exit == node[0] || exit == node[1]) {
return true
}
}
return false
})
if (near_agent_link_exits.length > 0) {
return near_agent_link_exits[0]
}
else{
return possible[0]
}
}
// game loop
while (true) {
var agent_position = parseInt(readline()); // The index of the node on which the Skynet agent is positioned this turn
var possible_exits = links.filter(function (link) {
for (var i = 0; i < exits.length; i++) {
var exit = exits[i]
if (exit == link[0] || exit == link[1]) {
return true
}
}
return false
})
printErr("Possible Exits: " + possible_exits)
var decided_exit = decideExit(possible_exits, agent_position, links, exits)
print(decided_exit.join(" ")); // Example: 0 1 are the indices of the nodes you wish to sever the link between
links = links.filter(function(link){
return link !== decided_exit
})
printErr("Links: " + links)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment