from __future__ import annotations from r6_guided import Graph, S, T, Gen1, Gen2, Generic, Optional from queue import PriorityQueue from typing import Tuple, TYPE_CHECKING def a_star( graph: Graph[ T ], start: T ) -> Gen2[ T, int ]: q : PriorityQueue[ Tuple[ int, T ] ] = PriorityQueue() q.put( ( 0, start ) ) while not q.empty(): prio, item = q.get() for succ in graph[ item ]: nprio = yield succ q.put( ( nprio, succ ) ) class cor_iter( Generic[ T, S ] ): def __init__( self, cor: Gen2[ T, S ] ) -> None: self.to_send : Optional[ S ] = None self.cor = cor def __iter__( self ) -> cor_iter[ T, S ]: return self def __next__( self ) -> T: if self.to_send is not None: return self.cor.send( self.to_send ) else: return next( self.cor ) def reply( self, v: S ) -> None: self.to_send = v if TYPE_CHECKING: def bfs( graph: Graph[ T ], start : T ) -> Gen1[ T ]: pass