Skip to content

Commit

Permalink
start csv stuff, rm example
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymax25 committed Jan 9, 2022
1 parent c9b046c commit 9890513
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 58 deletions.
32 changes: 0 additions & 32 deletions projet/funprog-al/src/main/scala/example/Hello.scala

This file was deleted.

43 changes: 43 additions & 0 deletions projet/funprog-al/src/main/scala/progfun/CSVExporter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.esgi.al.funprog

import fr.esgi.al.funprog._

class CSVExporter {
val sep: String = ","
}

object CSVExporter {

def export(m: Mower): String =
s"${CSVExporter.export(m.id)}${CSVExporter.export(m.startPoint)}${CSVExporter
.export(m.startDirection)}${CSVExporter.export(m.point)}${CSVExporter
.export(m.direction)}${CSVExporter
.export(m.originalActions)}"

def export(p: Point): String = s"${p.x.toString},${p.y.toString},"

def export(i: Int): String = s"${i.toString},"

def export(d: Direction): String = {
val char = d match {
case North() => "N"
case South() => "S"
case East() => "E"
case West() => "W"
}
s"${char},"
}

def export(a: Action): String = {
val char = a match {
case Advance(str) => str
case Left(str) => str
case Right(str) => str
}
s"${char}"
}

def export(actions: List[Action]): String = {
actions.map(a => export(a)).mkString("")
}
}
4 changes: 2 additions & 2 deletions projet/funprog-al/src/main/scala/progfun/Environnement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Environnement(
case first :: rest => {
val updated = runAction(mower, first)
new Mower(
updated.id,
updated.startPoint,
updated.startDirection,
updated.point,
Expand All @@ -64,10 +65,9 @@ object Environnement {
case first :: rest => {
print("\u001b[2J")
env.display()
Thread.sleep(250)
// Thread.sleep(250)
execute(new Environnement(env.limit_x, env.limit_y, env.play))
}
case Nil => env
}
}
// use Writes
49 changes: 26 additions & 23 deletions projet/funprog-al/src/main/scala/progfun/InputLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,33 @@ class InputLoader(filePath: String) {
sizeLine.split(" ").toList.map(s => s.toInt)

def parseMowerLines(mowerLines: List[List[String]]): List[Mower] =
mowerLines.map(l => {
val coords = l(0).split(" ").toList
if (coords.size != 3) {
throw DonneesIncorectesException(
"wrong line for mower init position!"
mowerLines.zipWithIndex.map {
case (l, index) => {
val coords = l(0).split(" ").toList
if (coords.size != 3) {
throw DonneesIncorectesException(
"wrong line for mower init position!"
)
}
val actions: List[Action] =
l(1).split("").toList.map(s => Action.getActionFromString(s))

new Mower(
index,
new Point(
coords(0).toInt,
coords(1).toInt
),
Direction.getFromString(coords(2)),
new Point(
coords(0).toInt,
coords(1).toInt
),
Direction.getFromString(coords(2)),
actions,
actions
)
}
val actions: List[Action] =
l(1).split("").toList.map(s => Action.getActionFromString(s))

new Mower(
new Point(
coords(0).toInt,
coords(1).toInt
),
Direction.getFromString(coords(2)),
new Point(
coords(0).toInt,
coords(1).toInt
),
Direction.getFromString(coords(2)),
actions,
actions
)
})
}

}
6 changes: 5 additions & 1 deletion projet/funprog-al/src/main/scala/progfun/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ object Main extends App {

println(Json.prettyPrint(executed.toJson))


// executed.mowers.headOption match {
// case Some(m) => println(CSVExporter.export(m))
// case None => println("no mowers to print")
// }

}
5 changes: 5 additions & 0 deletions projet/funprog-al/src/main/scala/progfun/mower/Mower.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fr.esgi.al.funprog._
import play.api.libs.json._

class Mower(
val id: Int,
val startPoint: Point,
val startDirection: Direction,
val point: Point,
Expand All @@ -13,6 +14,7 @@ class Mower(
) {

def toJson: JsValue = Json.obj(
"id" -> id,
"debut" -> Json.obj(
"point" -> startPoint.toJson,
"direction" -> startDirection.toString
Expand All @@ -25,6 +27,7 @@ class Mower(
)

def turnRight: Mower = new Mower(
id,
startPoint,
startDirection,
point,
Expand All @@ -34,6 +37,7 @@ class Mower(
)

def turnLeft: Mower = new Mower(
id,
startPoint,
startDirection,
point,
Expand Down Expand Up @@ -80,6 +84,7 @@ class Mower(
}

new Mower(
id,
startPoint,
startDirection,
newPoint,
Expand Down

0 comments on commit 9890513

Please sign in to comment.