-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridPathApp.scala
62 lines (53 loc) · 1.92 KB
/
GridPathApp.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import scala.io.StdIn
import stateSearch._
final class GridPathApp() {
val cols: Int = StdIn.readLine().toInt
val rows: Int = StdIn.readLine().toInt
val world = new GridWorld(rows, cols)
private val robot = world.make()
def printWorld(): Unit = world.print()
}
object GridPathApp {
def main(args: Array[String]): Unit = {
if (args.length < 1 || args.length > 2)
println("usage: run.sh <algorithm> < <VacuumWorld>") // Incorrect usage
else {
// read world
val app = new GridPathApp()
// app.printWorld()
val v = app.robot
var result: Option[Robot] = Option.empty
val alg: Option[StateSearch[Robot]] = args(0) match {
case "depth-first" =>
Some(new DepthFirst[Robot](v, Robot.expand, Robot.testGoal))
case "depth-first-id" =>
Some(new DepthFirstId[Robot](v, Robot.expand, Robot.testGoal))
case "uniform-cost" =>
Some(new UniformCost[Robot](v, Robot.expand, Robot.testGoal))
case "a-star" =>
if (args.length != 2) {
println("usage: run.sh a-star <h0, h1, OR h2> < <VacuumWorld>")
Option.empty
}
else args(1) match {
case "h0" =>
Some(new AStar[Robot](
v, Robot.expand, Robot.testGoal, Robot.h0))
case "h1" =>
Some(new AStar[Robot](
v, Robot.expand, Robot.testGoal, Robot.h1))
case "h2" =>
Some(new AStar[Robot](
v, Robot.expand, Robot.testGoal, Robot.h2))
case _ => Option.empty
}
case _ => Option.empty
}
if (alg.isEmpty)
println("usage: run.sh <algorithm type> < <VacuumWorld>") // Incorrect usage
else result = alg.get.find()
if (result.isDefined) result.get.printHist()
else println("Unable to find solution.")
}
}
}