1package aud.example.graph;
4import java.util.Random;
5import java.util.Scanner;
15 boolean hints_ =
false;
16 Scanner input =
new Scanner(System.in);
27 (
"You find youself in a maze, and you have to find the exit.\n"+
28 "You start in room "+entry_.
getLabel()+
29 " and the exit is in room "+exit_.
getLabel()+
".\n"+
32 while (room_!=exit_) {
35 System.out.println(
"Congratulations you found the exit!");
40 (
"You are in room "+room_.
getLabel()+
41 ((hints_ && room_.
ord>=0) ?
" (been there)" :
"")+
".\n"+
42 "There are corridors leading to the following rooms:\n");
46 MyNode node=(MyNode) e.destination();
48 node=(MyNode) e.source();
53 (
"["+i+
"] "+node.getLabel()+
54 ((node==exit_ ?
" with big sign saying \"EXIT\"" :
""))+
55 ((hints_ && node.ord>=0) ?
"(been there)" :
""));
61 System.out.print(
"Which way to go now? ('0' toggles hints)\n> ");
69 System.out.println(
"Give up?\n");
79 static MyNode pickNode(MyGraph g) {
81 int i=(
new Random()).nextInt()%g.getNumNodes();
82 for (MyNode node : g) {
89 public static void main(String[] args) {
98 MyNode entry=pickNode(g), exit=
null;
99 while ((exit=pickNode(g))==entry) {}
Implementation of an unordered map based on a hash table.
Value insert(Key key, Value value)
insert key-value pair
Value find(Key key)
find value for key @endiliteral
undirected (weighted or unweighted )example graph (Sedgewick, Algorithms in Java.
Parse text to build graph.
void parse(String input)
parse input
graph based on aud.graph.GraphAM
AbstractGraph< AbstractNode, AbstractEdge > getAbstractGraph()
view this graph as an AbstractGraph
node with all possible attributes that we require ;-)
int ord
time when node is (first marked/put into front)
a really simple game, which lets you explore a maze... pardon: a graph
static void main(String[] args)
RetroMaze(MyGraph g, MyNode entry, MyNode exit)
Vector< Edge > getOutEdges(Node node)
String getLabel()
get text description
AuD lecture: Data structures, algorithms, examples.