Skip to content

Commit

Permalink
Merge pull request #12 from davidedomini/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
Zimon99 authored Aug 29, 2022
2 parents 891bad6 + a3ff7eb commit f7f203b
Show file tree
Hide file tree
Showing 24 changed files with 717 additions and 266 deletions.
8 changes: 4 additions & 4 deletions src/main/resources/prolog/basetrack.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

%startingPoint(id, x_position, y_position)
%Query: startingPoint(id(ID), position(X, Y)).
startingPoint(id(1), position(453, 115)).
startingPoint(id(2), position(473, 129)).
startingPoint(id(3), position(493, 142)).
startingPoint(id(4), position(513, 155)).
startingPoint(id(1), position(313, 115)).
startingPoint(id(2), position(293, 129)).
startingPoint(id(3), position(273, 142)).
startingPoint(id(4), position(253, 155)).
14 changes: 14 additions & 0 deletions src/main/resources/prolog/cars.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
car(path("/cars/0-hard.png"), name("Ferrari"), tyre("Soft"), driver(1,1), maxSpeed(200), acceleration(2),
actualSector(1), fuel(130), color("Red")).

car(path("/cars/1-hard.png"), name("Mercedes"), tyre("Soft"), driver(1,1), maxSpeed(200), acceleration(2),
actualSector(1), fuel(130), color("Cyan")).

car(path("/cars/2-hard.png"), name("Red Bull"), tyre("Soft"), driver(1,1), maxSpeed(200), acceleration(2),
actualSector(1), fuel(130), color("Blue")).

car(path("/cars/3-hard.png"), name("McLaren"), tyre("Soft"), driver(1,1), maxSpeed(200), acceleration(2),
actualSector(1), fuel(130), color("Green")).

%Query --> Get all cars params
%car(path(P), name(N), tyre(T), driver(A, D), maxSpeed(MS), acceleration(ACC), actualSector(ASe), fuel(F), color(C))
6 changes: 4 additions & 2 deletions src/main/resources/prolog/movements.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

computeNewPositionForStraight(Coord, Vel, Time, Acc, I, Np) :- pow(Time, 2, TimeSquared), Np is Coord + (((Vel * Time + 0.5 * Acc * TimeSquared) / 40) * I).

computeNewVelocity(Speed, Acc, Time, Ns) :- Ns is Speed + (Acc * Time).
computeNewVelocity(Speed, Acc, Time, Deg, Fuel, Ns) :- computeZ(Deg, Fuel, Z), Temp is Speed + (Acc * Time), Ns is Temp - (Temp * Z).

computeNewVelocityDeceleration(Speed, Acc, Time, Ns) :- Ns is (Speed + (Acc * Time))*0.6.
computeZ(Deg, Fuel, Z) :- Z is (Deg + Fuel) / 180.

computeNewVelocityDeceleration(Speed, Acc, Time, Deg, Fuel, Ns) :- computeZ(Deg, Fuel, Z), Temp is (Speed + (Acc * Time)), Ns is (Temp - (Temp * Z))*0.9.

pow(X, Esp, Y):- pow(X, X, Esp, Y).
pow(X, Temp, Esp, Y):- Esp=:=0, !, Y=1.
Expand Down
41 changes: 36 additions & 5 deletions src/main/scala/it/unibo/pps/controller/ControllerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import monix.execution.Scheduler.Implicits.global
import monix.execution.Cancelable
import it.unibo.pps.utility.PimpScala.RichOption.*
import it.unibo.pps.view.simulation_panel.DrawingCarParams

import monix.eval.Task
import monix.execution.{Ack, Cancelable}
import java.awt.Color
import scala.collection.mutable
import scala.collection.mutable.Map
Expand All @@ -17,22 +18,28 @@ object ControllerModule:
trait Controller:
def notifyStart(): Unit
def notifyStop(): Unit
def notifyDecreseSpeed(): Unit
//def notifyFinish(): Unit
def notifyDecreaseSpeed(): Unit
def notifyIncreaseSpeed(): Unit
def startingPositions: Map[Int, Car]
def currentCar: Car
def currentCarIndex: Int
def standings: Standing
def totalLaps: Int
def currentCarIndex_=(index: Int): Unit
def totalLaps_=(lap: Int): Unit
def setPath(path: String): Unit
def setTyre(tyre: Tyre): Unit
def setMaxSpeed(speed: Int): Unit
def setAttack(attack: Int): Unit
def setDefense(defense: Int): Unit
def displaySimulationPanel(): Unit
def displayStartingPositionsPanel(): Unit
def displayEndRacePanel(): Unit
def updateParametersPanel(): Unit
def updateDisplayedCar(): Unit
def invertPosition(prevIndex: Int, nextIndex: Int): Unit
def registerReactiveChartCallback(): Unit

trait Provider:
val controller: Controller
Expand All @@ -59,10 +66,16 @@ object ControllerModule:
)

override def notifyStop(): Unit =
println("hdfghuefgheuygfe")
stopFuture --> (_.cancel())
stopFuture = None

override def notifyDecreseSpeed(): Unit =
//override def notifyFinish(): Unit =
//notifyStop()

//displayEndRacePanel()

override def notifyDecreaseSpeed(): Unit =
context.simulationEngine.decreaseSpeed()

override def notifyIncreaseSpeed(): Unit =
Expand All @@ -74,8 +87,14 @@ object ControllerModule:

override def currentCarIndex: Int = context.model.currentCarIndex

override def totalLaps: Int = context.model.totalLaps

override def standings: Standing = context.model.standing

override def currentCarIndex_=(index: Int): Unit = context.model.currentCarIndex = index

override def totalLaps_=(lap: Int): Unit = context.model.totalLaps_(lap)

override def setPath(path: String): Unit = context.model.cars(context.model.currentCarIndex).path = path

override def setTyre(tyre: Tyre): Unit = context.model.cars(context.model.currentCarIndex).tyre = tyre
Expand All @@ -89,15 +108,18 @@ object ControllerModule:
defense

override def displaySimulationPanel(): Unit =
context.model.updateStanding()
context.model.createStanding()
context.model.initSnapshot()
context.view.updateDisplayedStanding()
context.view.displaySimulationPanel(context.model.track, context.model.standing)
context.view.updateCars(context.model.standing._standing)
context.view.updateCars(context.model.standing._standing.values.toList, context.model.actualLap, context.model.totalLaps)

override def displayStartingPositionsPanel(): Unit =
context.view.displayStartingPositionsPanel()

override def displayEndRacePanel(): Unit =
context.view.displayEndRacePanel()

override def updateParametersPanel(): Unit =
context.view.updateParametersPanel()

Expand All @@ -114,5 +136,14 @@ object ControllerModule:
context.model.startingPositions(nextIndex).drawingCarParams.position
context.model.startingPositions(nextIndex).drawingCarParams.position = position

override def registerReactiveChartCallback(): Unit =
val onNext = (l: List[Snapshot]) => {
context.view.updateCharts(l)
Ack.Continue
}
val onError = (t: Throwable) => ()
val onComplete = () => ()
context.model.registerCallbackHistory(onNext, onError, onComplete)

trait Interface extends Provider with Component:
self: Requirements =>
13 changes: 7 additions & 6 deletions src/main/scala/it/unibo/pps/engine/PrologMovements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ given Conversion[String, Theory] = Theory.parseLazilyWithStandardOperators(_)

trait PrologMovements:
def newPositionStraight(x: Int, velocity: Double, time: Int, acceleration: Double, i: Int): Int
def newVelocityStraightAcc(car: Car, time: Int, acceleration: Double): Int
def newVelocityStraightDec(car: Car, time: Int, acceleration: Double): Int
def newVelocityStraightAcc(car: Car, time: Int): Int
def newVelocityStraightDec(car: Car, time: Int): Int

def newPositionTurn(): Unit

Expand All @@ -30,16 +30,17 @@ object PrologMovements:
.toDouble
.toInt

override def newVelocityStraightAcc(car: Car, time: Int, acceleration: Double): Int =
engine(s"computeNewVelocity(${car.actualSpeed}, $acceleration, $time, Ns)")
override def newVelocityStraightAcc(car: Car, time: Int): Int =
engine(s"computeNewVelocity(${car.actualSpeed}, ${car.acceleration}, $time, ${car.degradation}, ${car.fuel}, Ns)")
.map(Scala2P.extractTermToString(_, "Ns"))
.toSeq
.head
.toDouble
.toInt

override def newVelocityStraightDec(car: Car, time: Int, acceleration: Double): Int =
engine(s"computeNewVelocityDeceleration(${car.actualSpeed}, $acceleration, $time, Ns)")
override def newVelocityStraightDec(car: Car, time: Int): Int =
//println(s"${car.name} ----- maxspeed: ${car.maxSpeed} ----- speed: ${car.actualSpeed} ---- $car.")
engine(s"computeNewVelocityDeceleration(${car.actualSpeed}, 1, $time, ${car.degradation}, ${car.fuel}, Ns)")
.map(Scala2P.extractTermToString(_, "Ns"))
.toSeq
.head
Expand Down
Loading

0 comments on commit f7f203b

Please sign in to comment.