Created
June 3, 2021 19:21
-
-
Save b-reich/efddf3cd0608c0054dbe086ed2810cf5 to your computer and use it in GitHub Desktop.
Coding Game: Skynet Revolution
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 sys | |
import math | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
# n: the total number of nodes in the level, including the gateways | |
# l: the number of links | |
# e: the number of exit gateways | |
links : dict = dict() | |
gates : list = list() | |
n, l, e = [int(i) for i in input().split()] | |
for i in range(n): | |
links.setdefault(i, []) | |
print(links,file=sys.stderr) | |
for i in range(l): | |
# n1: N1 and N2 defines a link between these nodes | |
n1, n2 = [int(j) for j in input().split()] | |
links[n1].append(n2) | |
links[n2].append(n1) | |
print(links, file=sys.stderr) | |
for i in range(e): | |
ei = int(input()) # the index of a gateway node | |
gates.append(ei) | |
def find(si, gates): | |
for gate in gates: | |
if gate in links[si]: | |
return[si, gate] | |
for gate in gates: | |
if len(links[gate]) > 0: | |
return [gate, links[gate][0]] | |
return [0, 0] | |
# game loop | |
while True: | |
si = int(input()) # The index of the node on which the Skynet agent is positioned this turn | |
c1, c2 = find(si, gates) | |
# Write an action using print | |
# To debug: print("Debug messages...", file=sys.stderr) | |
# Example: 0 1 are the indices of the nodes you wish to sever the link between | |
#print("0 1") | |
#print("1 2") | |
print(f"{c1} {c2}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment