Skip to content

Commit

Permalink
chore: use suspend function instead of runblocking method
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomoaccursi committed Jan 27, 2024
1 parent 6043148 commit 824afc4
Showing 1 changed file with 90 additions and 102 deletions.
192 changes: 90 additions & 102 deletions src/main/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,120 +18,108 @@ import entity.NodeImpl
import entity.Position
import entity.PositionLinkingRule
import entity.SumAction
import kotlinx.coroutines.runBlocking

/**
* Max num of steps in simulation.
*/
const val MAX_STEPS = 10
const val MAX_STEPS = 1000

/**
* Main Function.
*/
fun main() {
runBlocking {
// Simple initialization of a simulation.
val time = DoubleTime(0.0)
val condition = DummyCondition()
suspend fun main() {
// Simple initialization of a simulation.
val time = DoubleTime(0.0)
val condition = DummyCondition()

val environment = EnvironmentImpl()
val linkingRule = PositionLinkingRule(1.0, environment = environment)
environment.setLinkingRule(linkingRule)
val node1 = NodeImpl(1)
node1.addContent(ContentImpl(1))
val node2 = NodeImpl(2)
node2.addContent(ContentImpl(1))
val node3 = NodeImpl(3)
node3.addContent(ContentImpl(1))
val node4 = NodeImpl(4)
node4.addContent(ContentImpl(1))
listOf(node1, node2, node3, node4).forEach { node ->
environment.addNode(
node,
Position(0.0, 0.0),
)
}
val moveAction = MoveNodeAction(environment)
val sumAction = SumAction(environment)
val environment = EnvironmentImpl()
val linkingRule = PositionLinkingRule(1.0, environment = environment)
environment.setLinkingRule(linkingRule)
val node1 = NodeImpl(1)
node1.addContent(ContentImpl(1))
val node2 = NodeImpl(2)
node2.addContent(ContentImpl(1))
val node3 = NodeImpl(3)
node3.addContent(ContentImpl(1))
val node4 = NodeImpl(4)
node4.addContent(ContentImpl(1))
listOf(node1, node2, node3, node4).forEach { node ->
environment.addNode(
node,
Position(0.0, 0.0),
)
}
val moveAction = MoveNodeAction(environment)
val sumAction = SumAction(environment)

val scheduler = ListScheduler()
val engine = EngineImpl(environment, scheduler, MAX_STEPS, time)
val scheduler = ListScheduler()
val engine = EngineImpl(environment, scheduler, MAX_STEPS, time)

val event1 = EventImpl(
node1,
arrayListOf(condition),
arrayListOf(moveAction, sumAction),
engine = engine,
environment = environment,
)
val event2 = EventImpl(
node1,
arrayListOf(condition),
arrayListOf(moveAction, sumAction),
engine = engine,
environment = environment,
)
node1.addEvent(event1)
node1.addEvent(event2)
val event1 = EventImpl(
node1,
arrayListOf(condition),
arrayListOf(moveAction, sumAction),
environment = environment,
)
val event2 = EventImpl(
node1,
arrayListOf(condition),
arrayListOf(moveAction, sumAction),
environment = environment,
)
node1.addEvent(event1)
node1.addEvent(event2)

val event3 = EventImpl(
node2,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
val event4 = EventImpl(
node2,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
node2.addEvent(event3)
node2.addEvent(event4)
val event3 = EventImpl(
node2,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
val event4 = EventImpl(
node2,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
node2.addEvent(event3)
node2.addEvent(event4)

val event5 = EventImpl(
node3,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
val event6 = EventImpl(
node3,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
node3.addEvent(event5)
node3.addEvent(event6)
val event5 = EventImpl(
node3,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
val event6 = EventImpl(
node3,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
node3.addEvent(event5)
node3.addEvent(event6)

val event7 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
val event8 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
val event9 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
engine = engine,
environment = environment,
)
node4.addEvent(event7)
node4.addEvent(event8)
node4.addEvent(event9)
engine.start()
}
val event7 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
val event8 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
val event9 = EventImpl(
node4,
arrayListOf(condition),
arrayListOf(moveAction),
environment = environment,
)
node4.addEvent(event7)
node4.addEvent(event8)
node4.addEvent(event9)
engine.start()
}

0 comments on commit 824afc4

Please sign in to comment.