Skip to content

Commit

Permalink
init actions in mower
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymax25 committed Dec 7, 2021
1 parent 89f31db commit 1cc6ee1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions projet/funprog-al/src/main/scala/progfun/InputLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ class InputLoader(filePath: String) {
"wrong line for mower init position!"
)
}
val actions = l(1).split("").toList
val actions: List[Action] = l(1).split("").toList.map(s => new Action(s))
new Mower(
coords(0).toInt,
coords(1).toInt,
Direction.getFromString(coords(2))
Direction.getFromString(coords(2)),
actions
)
})

Expand Down
1 change: 1 addition & 0 deletions projet/funprog-al/src/main/scala/progfun/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object Main extends App {
val loader = new InputLoader(inputFilePath)

val inputs = loader.parseInput()

val x: Int = inputs._1
val y: Int = inputs._2
val mowers: List[Mower] = inputs._3
Expand Down
21 changes: 12 additions & 9 deletions projet/funprog-al/src/main/scala/progfun/mower/Action.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package fr.esgi.al.action
package fr.esgi.al.funprog

abstract class Action {
def getChar(action: Action): String = action match {
case Left() => "G"
case Right() => "D"
case Advance() => "A"
class Action(str: String) {}

object Action {

def apply(str: String): Action = str match {
case "G" => new Left("G")
case "D" => new Right("D")
case "A" => new Advance("A")
}
}

case class Left() extends Action {}
case class Left(str: String) extends Action(str: String) {}

case class Right() extends Action {}
case class Right(str: String) extends Action(str: String) {}

case class Advance() extends Action {}
case class Advance(str: String) extends Action(str: String) {}
4 changes: 3 additions & 1 deletion projet/funprog-al/src/main/scala/progfun/mower/Mower.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package fr.esgi.al.funprog

case class Mower(x: Int, y: Int, direction: Direction) {}
import fr.esgi.al.funprog._

case class Mower(x: Int, y: Int, direction: Direction, actions: List[Action]) {}

0 comments on commit 1cc6ee1

Please sign in to comment.