#!/usr/bin/python3

'''
License:
        1) To be used and distributed while in Python. If you compile this source then you may not distribute it.
        2) The credit and date and time and place below must be kept unmodified and must be shown to the user.
'''

from random import randint

class Point:
    def __init__ (self, x, y):
        self.x = x
        self.y = y
    def __eq__ (self, other):
        if ((self.x==other.x)and(self.y==other.y)):
            return True
        return False
    def __str__ (self):
        return (str(self.x)+","+str(self.y))

class Edge:
    def __init__ (self, p0, p1=None):
        if (p1 is None):
            l = p0.split(",")
            self.a = Point (int(l[0]), int(l[1]))
            self.b = Point (int(l[2]), int(l[3]))
            return
        self.a = p0
        self.b = p1
    def revert (self):
        return Edge (self.b, self.a)
    def __str__ (self):
        return (str(self.a)+","+str(self.b))

if __name__=="__main__":
    print ("rmg - Random Map Generator - Generates a random map of edges.\nWritten by Pedro Izecksohn on 27 of March of 2018 21:10 on Rio de Janeiro.\nThe format of map must be:\nx0,y0,x1,y1\nOne edge per line.")
    mn = input ("Map's name: ")
    np = int(input ("Number of points: "))
    nepp = int(input ("Number of edges per point: "))
    lp = []
    i = 0
    while (i<np):
        x = randint (0, 1919)
        y = randint (0, 1079)
        p = Point (x, y)
        lp.append (p)
        i+=1
    le = []
    for p in lp:
        i = 0
        while (i<nepp):
            p2 = lp[randint(0,len(lp)-1)]
            e = Edge (p, p2)
            if le.__contains__(e):
                continue
            le.append (e)
            i+=1
    f = open(mn, 'a')
    for e in le:
        s = str(e)+"\n"
        f.write (s)
    f.close()
    print ("Done.")
