Python Forum
Kevin Bacon game with breath-first search
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kevin Bacon game with breath-first search
#1
I am more-less new at Python and I am working on Kevin Bacon game.

I have "movies.txt" text file that looks like:

Quote:Apollo 13 (1995);Bill Paxton;Tom Hanks;Kevin Bacon
Begyndte ombord, Det (1937);Aage Schmidt;Valso Holm
Bersaglio mobile (1967);Dana Young;Bebe Drake
Bezottsovshchina (1976);Yelena Maksimova;Lev Prygunov
Dark, The (1979);Angelo Rossitto;William Devane
etc,...

So in first row we have movie name and in other rows we have actors for that movie.

I am trying to make Kevin Bacon game with breath-first search.

My source code (Python 3.X):

class cvor:
    __slots__ = ('ime','susjed')
    
    
def kreiranjeCvora(ime):
    n = cvor()
    n.ime = ime
    n.susjed = []
    return n

def pronadiCvor(cvorlist, ime):
    for n in cvorlist:
        if n.ime == ime:
            return n
        
        
def ucitajGraf(file):  
    graph = []
    for line in file:
        imeGlumaca = []
        mojaLinija = line.split(";")
        imeFilma = mojaLinija[0]
        for i in range (1,len(mojaLinija)):
            imeGlumaca.insert(len(imeGlumaca), mojaLinija[i])           

        cvorFilm = pronadiCvor(graph, imeFilma)
        if cvorFilm == None:
            cvorFilm = kreiranjeCvora(imeFilma)
            graph.append(cvorFilm)
        for glumac in imeGlumaca:
            glumacCvor = pronadiCvor(graph,glumac)
            if glumacCvor == None:
                glumacCvor = kreiranjeCvora(glumac)
                graph.append(glumacCvor)
            glumacCvor.susjed.append(cvorFilm)
            cvorFilm.susjed.append(glumacCvor)
    return graph


def main():
    f = open("movies.txt")
    graf = ucitajGraf(f)
    print (graf)    
    
main()    
My problem is that when I print graph with "print (graph)" I am getting:

Quote:"[<__main__.cvor object at 0x000001475275EBE0>, <__main__.cvor object at 0x000001475275EEF0>, <__main__.cvor object at 0x000001475275EFD0>, <__main__.cvor object at 0x000001475275EE80>, <__main__.cvor object at 0x000001475275EB70>, <__main__.cvor object at 0x000001475275ED68>,..."

And I know why (I think) but I don't know how to fix it and get correct "names" there.

What would be the best way to perform breath-first search between two entered names and what should be my next step?
Reply


Messages In This Thread
Kevin Bacon game with breath-first search - by gamingingrs - Jan-09-2019, 10:00 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020