Difference between revisions of "Tutorial"

From AgentCubes
Jump to navigation Jump to search
imported>Loon911
imported>Loon911
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
Loops in AgentCubes online version 1.7
+
Welcome to AgentCubes wiki! The AgentCubes wiki was made to help you learn AgentCubes.
  
AgentCubes 1.7 introduces the new Repeat loop commands to comply with ISTE/CSTA K-12 Programming requirements.
+
== Tutorial Links ==
  
== Philosophy  ==
+
* Videos
 +
* [[:Category:AgentCubes Conditions|Conditions]]
 +
* [[:Category:AgentCubes Actions|Actions]]
  
You may just want to know how to use loops and not care so much why one should, or should not, use them. In that case you may safely skip to the next section of this document. If, however, you are asking yourself why we did we wait with the introduction of Loops in AgentSheets/AgentCubes for about 22 years here is the philosophy for not providing a loop command earlier. First, this was never an issue of labor. The original drag and drop language developed in AgentSheets prototyped in 1994 actually did have a loop command but we decided to remove it from AgentSheets. Reasons to have loop in computer science are manifold but the short story is that loops and parallel programming have a difficult relationship. Simple examples of using loops, such as the many examples of loops introduced in code.org tutorials, e.g., Angry Bird getting the pig, provide somewhat plausible use cases of loops, but there are many use cases of using loops interfering with the opportunity to employ parallelism. Many algorithms, for instance the sorting of numbers through bubble sort, or operations on very data vectors such as DNA described in programming for biologist textbooks, will strongly suggest the use of a FOR loop implying sequentiality, i.e., the execution of computing one at a time, and order, e.g., comparing bubbles in bubble sort left to right. Not only is this not necessary in many cases, it will also likely ruin the opportunity for parallel execution. For instance, there is really no reason why in bubble sort bubbles should be sorted left to right nor is it necessary to do this sequentially. Modern computers have multiple cores that can execute code parallel. Using these kinds of unnecessary loops can completely ruin parallel executing wasting the power that your computer is capable of to solve problems efficiency. AgentSheets/AgentCubes core ideas go back to massively parallel computing. The original prototype of AgentSheets was running on Connection Machines with up to 64,000 CPUs in 1990. The ideas developed back then carry over to modern architectures including multi core CPUs, which these days can even be found on low end smart phones, or GPUs (Graphical Processing Units used for computer graphics). For many applications loops are considered harmful for parallel operations.
+
== Agents ==
  
The AgentSheets/AgentCubes model makes it simple to express a massive parallelism precisely because it tries to avoid forms of unnecessary looping. For instance, create a large set of agents and make them move around randomly. They will do so in parallel, figuring out how to properly stack up without the need of complex user code. This is not to say that AgentSheets/AgentCubes did not support loops before the introduction of the repeat action but it did it carefully to minimize potential harm to parallel programming. The two mechanisms of looping in AgentSheets/AgentCubes are:
+
[[Image:Creating.PNG|thumb|right|400px|When creating a Agent you can choose many pre-made assets.]][[Image:Custom.PNG|thumb|right|400px|When creating a custom agent all these tools are available to you.]]In AgentCubesonline you can make Agents. Agents are world assets, world assets are objects that you can put in your world. For example, tree, bugs, spaceships, monster and anything else you can think of creating is an Agent.
  
#'''Implicit Loops''': All the rules executed in the While-Running method are, conceptually speaking, part of a simulation loop.
+
=== Creating ===
#'''Recursion''': A method may, directly, or indirectly through some additional methods, call itself again.
 
  
== Using Loops  ==
+
* To start creating an Agent click the bottom left on AgentCubesOnline where it says "+ Agent"
 +
* Then name the agent on the top
 +
* Finally select a pre-made asset or select an "Inflatable Icon" asset to later customize your own
  
The repeat loop is an action that you find in the bottom of the Actions palette. Use a repeat loop by dragging it into the THEN part of a rule. Add actions to the repeat loop by dragging any kind of action, including repeat actions, into the inside part of the repeat loop.
+
=== Custom Made Agent ===
  
[[File:Loop_action.png|center|Loop action in AgentCubes online]]
+
* When creating a new agent it needs to be a pre-made "Inflatable Icon" asset
 +
* If the agent is an "Inflatable Icon" asset you can double click the Agent and the custom Agent editor will pop up
 +
* You can make 2D Agents or 3D by clicking the more tools button in the agent editor
  
The repeat loop has a ''count expression'', defaulting to “2”, indicating how many times the loop will be run. This count expression may assume a number of forms (sorted from basic to more sophisticated):
+
=== Example ===
  
*Constant: A single constant positive integer value, e.g., “3”, “678” or “10000”
+
FUTURE VIDEO
*Expression with functions but without variables: e.g., “random (3)” will repeat 0, 1, or 2 times.
 
*Expression with agent attributes: e.g., “age”
 
*Expression with simulation property: e.g., “@score”
 
*Expressions with functions, agent attributes and simulation properties, e.g., “age + @score + random (10) + 5”<br>
 
  
== Examples of Loops  ==
 
  
A simple code.org like example ([https://studio.code.org/hoc/6 Angry Birds with Loops]) or in AgentCubes online ([https://www.agentcubesonline.com/Ristretto3D/public/Ristretto3D.html?nid=1197520&mode=edit https://www.agentcubesonline.com/Ristretto3D/public/Ristretto3D.html?nid=1197520&amp;mode=edit]) illustrates two kinds of loops:
 
  
#'''Loops as syntactic shortcut: '''A bug is supposed to move onto the gold coin. The bug would have to move 5 times which could be achieved with 5 separate move actions. Instead of duplicating the move action 5 times a single repeat 5 times action containing a move action will do the trick:
 
  
  
[[File:Loops as syntactic shortcut 1.png|center|300px|Bug has to move forward 5 times to reach its goal]]
 
  
  
[[File:Loops as syntactic shortcut 2.png|center|Redundant listing of action code]]
 
  
  
[[File:Loops as syntactic shortcut 3.png|center|Redundancy resolved with a loop]]
 
  
  
#'''Loops to animate''': Loops can be used to make iterative animations. In the same project, when the bug does reach the gold coin we want it to flash between two different shapes (red bug, blue bug). This could be done using the While-Running method but because we are not interested in the parallel animation of multiple bugs, there is only one in this world, the use of a repeat loop is simpler.
 
  
  
[[File:Loops to animate.png|center| Create an animation with loops]]
 
  
 +
== World ==
  
Notice the use of the wait action. It will delay the switching from one shape to the next. Without this delay the animation would not be visible to the user. There are two actions that can be used inside a loop to make intermediate results such as changing to a new shape visible:<br>
+
[[Image:World.PNG|thumb|right|400px|In this game a bird is flying through the world. The user has to control the bird and make sure the birddoes not hit brick walls. If the user hits a brick wall the user must restart. However, the longer the bird is alive the harder the game gets.]][[Image:World_tools.PNG|thumb|right|400px|These are the tools you can use to make your world.]]In AgentCubesonline you create/design your game or simulation. You can put your Agents in the world and then program them. Once your done programming and designing your world you can then play or run your simulations.
  
#'''Finish-animations''': All the pending animations will be finished. This will sequentialize the execution of agents. <br>
+
=== 3D Worlds ===
#'''Wait''': Wait includes a finish-animations and then waits a user specified number of seconds before the next action continues.<br>
 
  
== Further Experiments  ==
+
In AgentCubesonline you have the ability to either create a 2D world or a 3D world. Creating a 3D world is easy, just click the "+" button on the right where it says "Layers". You can add as many layers as you want to your world. Once you added the layers you can program your Agents to move in between layers, creating a 3D game or a 3D simulation.
  
*Experiment with using finish-animations and wait in the “Loops as Syntactic shortcut” example. <br>
+
=== Example ===
*Explore the use of different expressions for the repeat count. For instance, try the use of agent attributes.
 
  
<br>
+
FUTURE VIDEO
  
[[Category:AgentCubes_Actions]]
+
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
== Programming Environment  ==
 +
 
 +
[[Image:VAT.PNG|thumb|right|400px|The Programming Environment looks like this. All Conditions are on the left and all Actions are on the right. The Rule is in the middle in between the Conditions and Actions.]][[Image:Rule.PNG|thumb|right|400px|Empty rules look like this.]][[Image:Rule ca.PNG|thumb|right|400px|The rules has two Conditions on the left. One Condition is pressing the right key and the last Condition is seeing if grass is right. If both those Conditions are met than the rule will execute the Action on the right. The Action on the right says that the agent should move right once.]]The Programming Environment for AgentCubesonline looks like the image on the right. In the Programming Environment you can program the agents that you have created. To program your agents you drag and drop [[:Category:AgentCubes Conditions|Conditions]] and [[:Category:AgentCubes Actions|Actions]] into the rule sections. When all your [[:Category:Age|Conditions]] are met the Programming Environment will then execute all your [[:Category:AgentCubes Actions|Actions]].
 +
 
 +
=== Methods ===
 +
 
 +
A method is a segment of the agent's behavior that contains a set of rules. A trigger is at the head of every method and determines when the method will be called. The image on the right are using the "while-running" method.
 +
 
 +
 
 +
[[Methods|Click here to view a list of all Methods]] 
 +
 
 +
=== Rules  ===
 +
 
 +
Rules contain [[:Category:AgentCubes Conditions|Conditions]] on the left side and [[:Category:AgentCubes Actions|Actions]] on the right side. Users may drag the [[:Category:AgentCubes Conditions|Conditions]] to the left side and users may drag Actions to the right side of the rule container. If all [[:Category:AgentCubes Conditions|Conditions]] are met than all [[:Category:AgentCubes Actions|Actions]] will be executed.
 +
 
 +
=== Conditions  ===
 +
 
 +
Conditions are the requirements that need to be met for the actions to be executed. For example, a condition could be if an agent see something to the right. If a condition is met than the rule will execute the actions. A real world example of conditions is an if function in many programming languages. Condition(s) are the requirements that need to be met for the if functions body to get executed.
 +
 
 +
 
 +
[[:Category:AgentCubes Conditions|Click here to view a list of all Conditions and their parameters]]
 +
 
 +
=== Actions  ===
 +
 
 +
In AgentCubes actions are the things you can make the agent(s) execute. For example, one of AgentCubes's actions, is the ability to make a agent move right. A real wold example of this in another programming language is the body of an if statement. If the conditions are met than everything in the if body will be executed.
 +
 
 +
 
 +
[[:Category:AgentCubes Actions|Click here to view a list of all Actions and their parameters]]
 +
 
 +
=== Example ===
 +
 
 +
FUTURE VIDEO
 +
 
 +
== Frogger Game Example ==
 +
Future Video

Latest revision as of 11:37, 21 June 2019

Welcome to AgentCubes wiki! The AgentCubes wiki was made to help you learn AgentCubes.

Tutorial Links

Agents

When creating a Agent you can choose many pre-made assets.
When creating a custom agent all these tools are available to you.

In AgentCubesonline you can make Agents. Agents are world assets, world assets are objects that you can put in your world. For example, tree, bugs, spaceships, monster and anything else you can think of creating is an Agent.

Creating

  • To start creating an Agent click the bottom left on AgentCubesOnline where it says "+ Agent"
  • Then name the agent on the top
  • Finally select a pre-made asset or select an "Inflatable Icon" asset to later customize your own

Custom Made Agent

  • When creating a new agent it needs to be a pre-made "Inflatable Icon" asset
  • If the agent is an "Inflatable Icon" asset you can double click the Agent and the custom Agent editor will pop up
  • You can make 2D Agents or 3D by clicking the more tools button in the agent editor

Example

FUTURE VIDEO








World

In this game a bird is flying through the world. The user has to control the bird and make sure the birddoes not hit brick walls. If the user hits a brick wall the user must restart. However, the longer the bird is alive the harder the game gets.
These are the tools you can use to make your world.

In AgentCubesonline you create/design your game or simulation. You can put your Agents in the world and then program them. Once your done programming and designing your world you can then play or run your simulations.

3D Worlds

In AgentCubesonline you have the ability to either create a 2D world or a 3D world. Creating a 3D world is easy, just click the "+" button on the right where it says "Layers". You can add as many layers as you want to your world. Once you added the layers you can program your Agents to move in between layers, creating a 3D game or a 3D simulation.

Example

FUTURE VIDEO











Programming Environment

The Programming Environment looks like this. All Conditions are on the left and all Actions are on the right. The Rule is in the middle in between the Conditions and Actions.
Empty rules look like this.
The rules has two Conditions on the left. One Condition is pressing the right key and the last Condition is seeing if grass is right. If both those Conditions are met than the rule will execute the Action on the right. The Action on the right says that the agent should move right once.

The Programming Environment for AgentCubesonline looks like the image on the right. In the Programming Environment you can program the agents that you have created. To program your agents you drag and drop Conditions and Actions into the rule sections. When all your Conditions are met the Programming Environment will then execute all your Actions.

Methods

A method is a segment of the agent's behavior that contains a set of rules. A trigger is at the head of every method and determines when the method will be called. The image on the right are using the "while-running" method.


Click here to view a list of all Methods

Rules

Rules contain Conditions on the left side and Actions on the right side. Users may drag the Conditions to the left side and users may drag Actions to the right side of the rule container. If all Conditions are met than all Actions will be executed.

Conditions

Conditions are the requirements that need to be met for the actions to be executed. For example, a condition could be if an agent see something to the right. If a condition is met than the rule will execute the actions. A real world example of conditions is an if function in many programming languages. Condition(s) are the requirements that need to be met for the if functions body to get executed.


Click here to view a list of all Conditions and their parameters

Actions

In AgentCubes actions are the things you can make the agent(s) execute. For example, one of AgentCubes's actions, is the ability to make a agent move right. A real wold example of this in another programming language is the body of an if statement. If the conditions are met than everything in the if body will be executed.


Click here to view a list of all Actions and their parameters

Example

FUTURE VIDEO

Frogger Game Example

Future Video