Skip to content

Commit

Permalink
fix: limit in Environnement
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymax25 committed Jan 9, 2022
1 parent 0fde58c commit 45562a1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 24 deletions.
22 changes: 10 additions & 12 deletions projet/funprog-al/src/main/scala/progfun/Environnement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package fr.esgi.al.funprog
import play.api.libs.json._

class Environnement(
val limit_x: Int,
val limit_y: Int,
val limit: Point,
val mowers: List[Mower],
val isVerbose: Boolean,
val delay: Int
) {

def display(): Unit = {
println("Display environnement:")
for (y <- limit_y to 0 by -1) {
for (x <- 0 to limit_x) {
for (y <- limit.y to 0 by -1) {
for (x <- 0 to limit.x) {
print(mowers.find(m => m.point.x == x && m.point.y == y) match {
case Some(m) => " " + m.direction.toString + " "
case None => " - "
Expand Down Expand Up @@ -54,7 +53,7 @@ class Environnement(
def runAction(mower: Mower, action: Action): Mower = action match {
case Left(_) => mower.turnLeft
case Right(_) => mower.turnRight
case Advance(_) => mower.advance(new Point(limit_x, limit_y), mowers)
case Advance(_) => mower.advance(limit, mowers)
case _ => mower
}
}
Expand All @@ -71,8 +70,7 @@ object Environnement {
}
execute(
new Environnement(
env.limit_x,
env.limit_y,
env.limit,
env.play,
env.isVerbose,
env.delay
Expand All @@ -91,11 +89,11 @@ object Environnement {
implicit val environnementWrites = new Writes[Environnement] {
def writes(env: Environnement): JsValue = {
Json.obj(
"limit" -> Json.obj(
"x" -> env.limit_x,
"y" -> env.limit_y
"limite" -> Json.obj(
"x" -> env.limit.x,
"y" -> env.limit.y
),
"tondeuse" -> env.mowers.map(m => Mower.mowersWrites.writes(m))
"tondeuses" -> env.mowers.map(m => Mower.mowersWrites.writes(m))
)
}
}
Expand Down
6 changes: 2 additions & 4 deletions projet/funprog-al/src/main/scala/progfun/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ object Main extends App {

val inputLoader = new InputLoader(conf.getString("application.input-file"))
val inputs = inputLoader.parseInput()
val x: Int = inputs._1
val y: Int = inputs._2
val limit: Point = new Point(inputs._1, inputs._2)
val mowers: List[Mower] = inputs._3

val env =
new Environnement(
x,
y,
limit,
mowers,
conf.getString("application.is-env-verbose").toBoolean,
conf.getString("application.turn-delay").toInt
Expand Down
2 changes: 1 addition & 1 deletion projet/funprog-al/src/main/scala/progfun/mower/Point.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Point(
}

object Point {

implicit val pointWrites = new Writes[Point] {
def writes(point: Point): JsValue = {
Json.obj(
Expand Down
2 changes: 1 addition & 1 deletion projet/funprog-al/src/test/scala/progFun/ActionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fr.esgi.al.funprog._

class ActionSpec extends AnyFunSuite {

test("Parse action string to action sub type-class") {
test("Should parse action string to action sub type-class") {
val actionStr = "A"
val action = Action(actionStr)
val test = action match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class EnvironnementSpec extends AnyFunSuite {
val env = SpecHelper.getTestEnv()

assert(env.mowers.length == 2)
assert(env.limit_x == 5)
assert(env.limit_y == 5)
assert(env.limit.x == 5)
assert(env.limit.y == 5)
}

test("Env should be executed and run all the mower actions turns") {
Expand Down
3 changes: 1 addition & 2 deletions projet/funprog-al/src/test/scala/progFun/SpecHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ object SpecHelper {
val limit = new Point(5, 5)

new Environnement(
limit.x,
limit.y,
limit,
mowers,
false,
0
Expand Down
4 changes: 2 additions & 2 deletions projet/funprog-al/tmp/output.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"limit" : {
"limite" : {
"x" : 5,
"y" : 5
},
"tondeuse" : [ {
"tondeuses" : [ {
"id" : 1,
"debut" : {
"point" : {
Expand Down

0 comments on commit 45562a1

Please sign in to comment.