-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
101eac8
commit 4812534
Showing
4 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
appplication { | ||
application { | ||
name = "FunProg" | ||
name = ${?APP_NAME} # Pour surcharger la valeur par un variable d'environnement | ||
# name = ${?APP_NAME} # Pour surcharger la valeur par un variable d'environnement | ||
|
||
input-file = "/tmp/input.txt" | ||
input-file = ${?INPUT_FILE} | ||
input-file = "tmp/input.txt" | ||
# input-file = ${?INPUT_FILE} | ||
|
||
output-json-file = "/tmp/output.json" | ||
output-json-file = ${?OUTPUT_JSON_FILE} | ||
output-json-file = "tmp/output.json" | ||
# output-json-file = ${?OUTPUT_JSON_FILE} | ||
|
||
output-csv-file = "/tmp/output.csv" | ||
output-csv-file = ${?OUTPUT_CSV_FILE} | ||
} | ||
|
||
# A supprimer | ||
example { | ||
message = "hi buddy" | ||
message = ${?EXAMPLE_MESSAGE} | ||
|
||
one = 1 | ||
one = ${?EXAMPLE_ONE} | ||
|
||
yes = "true" | ||
yes = ${?EXAMPLE_YES} | ||
} | ||
output-csv-file = "tmp/output.csv" | ||
# output-csv-file = ${?OUTPUT_CSV_FILE} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,131 @@ | ||
package fr.esgi.al.funprog | ||
|
||
import better.files._ | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
|
||
final case class DonneesIncorectesException( | ||
val message: String | ||
) extends Exception(message) | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.Throw")) | ||
object Main extends App { | ||
println("Ici le programme principal") | ||
// Le code suivant ne compilera pas. | ||
// var tmp = null; | ||
// var tmp2 = if (tmp == 1) "yes" else 1 | ||
|
||
// println(s"tmp: $tmp, tmp2: $tmp2") | ||
val conf: Config = ConfigFactory.load() | ||
val inputFilePath: String = conf.getString("application.input-file") | ||
|
||
val f: File = File(inputFilePath) | ||
|
||
def getFirstLine(lines: List[String]) = lines match { | ||
case Nil => throw DonneesIncorectesException("No lines in the file!") | ||
case first :: Nil => first | ||
case first :: rest => first | ||
} | ||
def getMowersLines(lines: List[String]) = lines match { | ||
case Nil => throw DonneesIncorectesException("No mower lines in the file!") | ||
case first :: Nil => | ||
throw DonneesIncorectesException("No mower lines in the file!") | ||
case first :: rest => rest | ||
} | ||
|
||
val sizeLine = getFirstLine(f.lines.toList) | ||
val mowerLines = getMowersLines(f.lines.toList) | ||
|
||
val sizes: List[Int] = sizeLine.split(" ").toList.map(s => s.toInt) | ||
if (sizes.size != 2) { | ||
throw DonneesIncorectesException( | ||
"You must have two numbers separated by a space in the first line of the input, height and width of the area!" | ||
) | ||
} | ||
|
||
if (mowerLines.size % 2 != 0) { | ||
throw DonneesIncorectesException( | ||
"even number of lines, each mower must have 1 line for its initial postion and 1 line fir his directions list!" | ||
) | ||
} | ||
val mowersLinesGrouped = mowerLines.grouped(2).toList | ||
val mowers: List[Mower] = mowersLinesGrouped.map(l => { | ||
val coords = l(0).split(" ").toList | ||
if (coords.size != 3) { | ||
throw DonneesIncorectesException( | ||
"wrong line for mower init position!" | ||
) | ||
} | ||
val actions = l(1).split("").toList | ||
new Mower( | ||
coords(0).toInt, | ||
coords(1).toInt, | ||
Direction.getFromString(coords(2)) | ||
) | ||
}) | ||
|
||
mowers.foreach(m => println(m)) | ||
|
||
val env = new Environnement(sizes(0), sizes(1), mowers) | ||
|
||
env.display() | ||
|
||
} | ||
|
||
class Environnement(height: Int, width: Int, mowers: List[Mower]) { | ||
|
||
def display(): Unit = { | ||
println("Display environnement:") | ||
for (y <- height to 0 by -1) { | ||
for (x <- 0 to width) { | ||
|
||
val toPrint = mowers.find(m => m.x == x && m.y == y) match { | ||
case Some(m) => " " + m.direction.toString + " " | ||
case None => " - " | ||
} | ||
print(toPrint) | ||
} | ||
println() | ||
} | ||
} | ||
} | ||
|
||
case class Mower(x: Int, y: Int, direction: Direction) {} | ||
|
||
class Action {} | ||
|
||
case class Left() extends Action { | ||
val str = "G" | ||
} | ||
|
||
case class Right() extends Action { | ||
val str = "D" | ||
} | ||
|
||
case class Advance() extends Action { | ||
val str = "A" | ||
} | ||
|
||
abstract class Direction { | ||
def toString(): String | ||
} | ||
|
||
object Direction { | ||
def getFromString(direction: String): Direction = direction match { | ||
case "N" => new North() | ||
case "S" => new South() | ||
case "W" => new West() | ||
case "E" => new East() | ||
} | ||
|
||
} | ||
|
||
case class North() extends Direction { | ||
override def toString: String = "N" | ||
} | ||
|
||
case class South() extends Direction { | ||
override def toString: String = "S" | ||
} | ||
|
||
case class East() extends Direction { | ||
override def toString: String = "E" | ||
} | ||
|
||
case class West() extends Direction { | ||
override def toString: String = "W" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
9 5 | ||
1 2 N | ||
GAGAGAGAA | ||
3 3 E | ||
AADAADADDA |