Algorithm Analysis

advertisement
2D Procedural Dungeon Generation
Jessica Baron & Aurora Silverwood
All Individual Algorithms - Analysis
Random Room Placement Θ Analysis
Variables:
r = number of rooms
k = constant
n = number of iterations in a loop
w = room width
h = room height
Algorithm Analysis:_
- Main while loop: Θ(1) + Θ(r) = Θ(r) = Θ(100) in general, Θ(1) in our case
- generateRandomRoomSize(): Θ(1) (handful of Θ(k) operations)
- while loop calling overlaps(): Θ(n) + Θ((w+3)*(h+3)) = Θ(n*(w+3)*(h+3)) =
Θ(100*(w+3)*(h+3)) in general, Θ(w*h) in our case
- overlaps(): Θ((w+3)*(h+3)) in general, Θ(1) in our case
- if not overlapping, add item to an ArrayList: Θ(1)
- drawRoom(): Θ(w*h) in general, Θ(1) in our case
Conclusion:
-Our specific case with Graph dimension restraints:
Θ(1*(1 + (n * 1) + 1 + 1) = Θ(n)
-In general with no dimension caps:
Θ(100*(1 + (100 * (w+3)*(h+3)) + 1 + (w*h)) = Θ(w*h)
BSP Room Placement Θ Analysis
Variables:
n = number of splits
L = total number of leafs
c = children
k = constant
n = number of iterations in a loop
w = room width
h = room height
Algorithm Analysis:
- BSP Tree instantiation: Θ(n+L) = Θ(n+2n) = Θ(3n) = Θ(n) in general.
Θ(k+2k) = Θ(3k) = Θ(k) = Θ(1) in our case.
(splitting the Graph down to a min Leaf size,
which is at smallest graphW/15 graphH/15)
- splitGraph(): Θ(n) + Θ(1) = Θ(n) in general.
Θ(1) in our case. (as the graph is split a constant number of times)
- getLeafLists(): Θ((L or 1)+1+1) = Θ(L) = Θ(2n) in general.
Θ(1) in our case. (iterating through each BSPLeaf, which is
twice the number of times splitGraph() ran)
- adding to bottomChildren list: Θ(1) ( adding to ArrayList)
- adding to parentsList: Θ(1)
- iterating through children to assign Rooms: Θ(c) + Θ(1) + Θ(1) = Θ(c) in general,
= O(1) in our case.
- generateRandomRoomSize(): Θ(1) operations
- adding to lists: Θ(2) worst case ( in our case there are never more than 20 rooms)
- drawRoom(): for each Room Θ(w*h)
Conclusion:
-Our specific case with Graph dimension restraints:
Θ(1 (tree) + 1 (children) + 1 (drawing)) = Θ(1)
-In general with no dimension caps:
Θ(n (tree) + c (children) + w*h (drawing)) = Θ(n+c+(w*h))
BSP Corridors Θ Analysis
Variables:
r = number of rooms
k = constant
n = number of iterations in a loop
c = children
p = parent (c / 2)
i = corridor parts
w = room width
h = room height
Algorithm Analysis:
- For Each Parent: Θ(n(1+n) = Θ(n2)
Θ(c/2(1+4*(c/2))
= Θ(c/2(1+2*(c)
= Θ(c/2+c)
= Θ(c*(3/2))
= Θ(20 ((max c value)) *3/2)
= Θ(1)
- createACorridor():Θ(1) (many machine operations and 1 or 2 addings to a list: Θ(2)
(worst, in our case) )
- for each corridor part: Θ(i) (imax= 4 (max possible corr parts per room pair) * p)
- for each child: Θ(c)
Θ(20) (There are never more than 20 children) + Θ(1) + Θ(2) = Θ(23) = Θ(1)
- for each room: Θ(3c) in general, Θ(60) = Θ(1) in our case
Updated room list size = c + i (which is 4*p = 4*(c/2)) = c + 2c = 3c = 3 * 20 ((cmax)) =
60 = 1
- drawRoom(): Θ(w*h)
Conclusion:
-Our specific case with Graph dimension restraints:
Θ(1 ((creating each corridor part per parent)) + 1 ((for each child)) + 1 ((drawing
rooms))) = Θ(1)
-In general with no dimension caps:
Θ(1 ((creating each corridor part per parent)) + 1 ((for each child)) + 3c*w*h ((drawing
rooms)))
= Θ(3c*w*h)
Random Point Connect Θ Analysis
Variables:
r = number of rooms
k = constant
n = number of iterations in a loop
w = room width
h = room height
d = room width OR room height
Algorithm Analysis:
- For each room: Θ(r)
Θ(64) (64 max is the possible rooms) = Θ(1)
- pickRandomSidePoint twice (per each room in a pair until a vaild side is found): Θ(n+n) =
Θ(2n) = Θ(n)
- isValidSide(): Θ(1)
- loop ‘til valid side: Θ(n)
- for each Vertex along horizontal/vertical distance Θ(d)
- for each Vertex along horizontal/vertical distance: Θ(d)
- turn vertex “on”
Conclusion:
-Our specific case with Graph dimension restraints:
Θ(1(n ((picking valid side))+1*1 ((going along distances))) = Θ(n+1) = Θ(n)
-In general with no dimension caps:
Θ(1(n ((picking valid side))+w*h ((going along distances))) = Θ(n+w*h) = Θ(w*h)
Drunkard’s Walk Θ Analysis
Variables:
r = number of rooms
k = constant
n = number of iterations in a loop
m = number of iterations in a loop
w = room width
h = room height
Algorithm Analysis:
- for each room: Θ(r) = Θ(64) (64 max possible rooms) = Θ(1)
- pickRandomSidePoint: Θ(n+n) = Θ(2n) = Θ(n)
- while loop til hit 2nd room or cap (which is graphArea/20): Θ(m) in general
Θ(mmax ) = ((max height x max width) / 20)
Θ(mmax ) = ((500*500) / 20) = Θ(12500) = Θ(1) in our case
- draw a horizontal or vertical line: Θ(n)
Conclusion:
-Our specific case with Graph dimension restraints:
Θ(1 ((max 64 rooms ))* ( n + (1 * 1 * 1)) = Θ(n)
-In general with no dimension caps:
Θ(1* ( n + (m * w*h)) = Θ(m* w*h)
Note: For all algorithms, max horizontal/vertical distances are directly related to the Graph w
and h. Therefore, if the Graph w and h are capped, those distances are capped, and drawing
along those distances would be constant: O(1).
Download