modified maze example but could not get it to compile

This commit is contained in:
Pavel Talanov
2012-02-05 15:52:29 +04:00
parent 6b23bd1ac8
commit 2f5baf8934
@@ -18,9 +18,6 @@
* I want to get the prize, and this program helps me do so as soon * I want to get the prize, and this program helps me do so as soon
* as I possibly can by finding a shortest path through the maze. * as I possibly can by finding a shortest path through the maze.
*/ */
package maze
import java.util.Collections.*
import java.util.* import java.util.*
/** /**
@@ -31,10 +28,10 @@ import java.util.*
fun findPath(maze : Maze) : List<#(Int, Int)>? { fun findPath(maze : Maze) : List<#(Int, Int)>? {
val previous = HashMap<#(Int, Int), #(Int, Int)> val previous = HashMap<#(Int, Int), #(Int, Int)>
val queue = ArrayList<#(Int, Int)> val queue = LinkedList<#(Int, Int)>
val visited = HashSet<#(Int, Int)> val visited = HashSet<#(Int, Int)>
queue.add(maze.start) queue.offer(maze.start)
visited.add(maze.start) visited.add(maze.start)
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
val cell = queue.poll() val cell = queue.poll()
@@ -155,6 +152,7 @@ fun printMaze(str : String) {
println("") println("")
} }
/** /**
* A maze is encoded in the string s: the big 'O' letters are walls. * A maze is encoded in the string s: the big 'O' letters are walls.
* I stand where a big 'I' stands and the prize is marked with * I stand where a big 'I' stands and the prize is marked with
@@ -207,26 +205,15 @@ fun makeMaze(s : String) : Maze {
return Maze(w.size, lines.size, data, start.sure(), end.sure()) return Maze(w.size, lines.size, data, start.sure(), end.sure())
} }
// An excerpt from the Standard Library // An excerpt from the Standard Library
val String?.indices : IntRange get() = IntRange(0, this.sure().size) val String?.indices : IntRange get() = IntRange(0, this.sure().size)
val String.size : Int
get() = length
fun <K, V> Map<K, V>.set(k : K, v : V) { put(k, v) } fun <K, V> Map<K, V>.set(k : K, v : V) { put(k, v) }
fun comparator<T> (f : (T, T) -> Int) : Comparator<T> = object : Comparator<T> { fun comparator<T> (f : (T, T) -> Int) : Comparator<T> = object : Comparator<T> {
override fun compare(o1 : T, o2 : T) : Int = f(o1, o2) override fun compare(o1 : T, o2 : T) : Int = f(o1, o2)
} override fun equals(p : Any?) : Boolean = false
fun String.split(s : String) = (this as java.lang.String).split(s)
fun println(message : Any?) {
System.out?.println(message)
}
fun print(message : Any?) {
System.out?.print(message)
} }
fun <T, C: Collection<T>> Array<T>.to(result: C) : C { fun <T, C: Collection<T>> Array<T>.to(result: C) : C {
@@ -234,5 +221,3 @@ fun <T, C: Collection<T>> Array<T>.to(result: C) : C {
result.add(elem) result.add(elem)
return result return result
} }
fun <T> Array<T>.toList() : List<T> = this.to(ArrayList<T>())