Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

python - BFS function not returning path right -


hey guys, what's ya'll. this, have create bfs function finds shortest path between destination , source game called quoridor, i'm sure of ya'll played before. when run it, no errors found want shortest path function return path 1 did in searchbfs function. also, sorry sloppy post, it's first one.

here's code....

from interface import * import engine  #public routines  def init(gamefile, playerid, numplayers, playerhomes, wallsremaining):  """     parts engine calls method player can initialize data.         gamefile - string file containing initial board state.         playerid - numeric id of player (0-4).         numplayers - number of players (2 or 4).         playerhomes - list of coordinates each players starting cell (po-p4).         wallsremaining - number of walls remaining (same players @ start)."""      # log message string standard output , current log file     engine.log_msg("player.init called player " + str(playerid) + " file=" + gamefile +                    ', playerid=' + str(playerid) + ', numplayers=' + str(numplayers) + ', playerhomes=' +                    str(playerhomes) + ', wallsremaining=' + str(wallsremaining))      playerdata = none      # initialize data structure here, , return it.      # passed 'playerdata' in shortest_path function.      return playerdata  def shortest_path(playerdata, source, dest):  """returns list of coordinates representing shortest path on     board between start , finish coordinates.         playerdata - player's data         source - start coordinate         dest - end coordinate"""      engine.log_msg("player.shortest_path called.  source: " + str(source) +                     ", dest: " + str(dest))      path = []  def searchbfs(graph, source, dest):  """performs bfs search between source , destination nodes using queue.     returns path list of graph nodes (or empty list if no path exists)."""      dispenser = myqueue.queue()     myqueue.enqueue(source, dispenser)      #construct visited list.      visited = set()     visited.add(source)      #loop untill either destination found or dispenser     #is empty (no path)      while not myqueue.empty(dispenser):         current = myqueue.front(dispenser)         myqueue.dequeue(dispenser)         if current == dest:             break         # loop on neighbors of current         neighbor in current.neighbors:             # process unvisited neighbors             if neighbor not in visited:                 neighbor.previous = current                 visited.add(neighbor)                 myqueue.enqueue(neighbor, dispenser)     return constructpath(visited, source, dest)  def constructpath(visited, source, dest):  """returns path list of nodes source destination"""      #construct path using stack , traversing destination     #node source node using node's previous     stack = mystack.stack()     if dest in visited:         temp = dest         while tmp != source:             mystack.push(tmp, stack)             tmp = tmp.previous         mystack.push(source, stack)      path = []     while not mystack.empty(stack):         path.append(mystack.top(stack))         mystack.pop(stack)     return path 

stack = mystack.stack() if dest in visited:     temp = dest     while tmp != source:         mystack.push(tmp, stack)         tmp = tmp.previous 

i think tmp , temp variables here should same? although expect error since tmp isn't assigned before use it.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -