Alice 3.3: различия между версиями
Содержимое удалено Содержимое добавлено
Строка 71: | Строка 71: | ||
while (j < Arr.Length) is true |
while (j < Arr.Length) is true |
||
{ |
{ |
||
if ( |
if (Arr[i] < Arr[j]) is true then |
||
{ |
{ |
||
C = |
C = Arr[i] |
||
Arr[i] = Arr[j] |
|||
Arr[j] = C |
|||
} |
} |
||
j = j + 1 |
j = j + 1 |
||
Строка 81: | Строка 81: | ||
i = i + 1 |
i = i + 1 |
||
} |
} |
||
for each (DecimalNumber n) in |
for each (DecimalNumber n) in Arr |
||
this.alice say "n:" + n |
this.alice say "n:" + n |
||
</source> |
</source> |
Версия от 12:37, 10 декабря 2017
Одновременное движение объектов
Движение в одном направлении
constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
Boolean MoveForward = true
Boolean MoveRight = true
while (true) is true
{
each (Sphere sphere) in (new Sphere[] {this.sphere, this.sphere2, this.sphere3}) together
do together
{
if (MoveForward) is true then
sphere move = FORWARD, Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
else
sphere move = BACKWARD, Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
if (MoveRight) is true
sphere move = RIGHT, Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
else
sphere move = LEFT, Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
}
MoveForward = nextRandomBoolean()
MoveRight = nextRandomBoolean()
}
Броуновское движение
constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
while true is true
{
each (Sphere sphere) in (new Sphere[] {this.sphere, this.sphere2, this.sphere3}) together
do together
{
sphere move = FORWARD, Force - nextRandomRealNumberRange(0.0, 2.0 * Force), duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
sphere move = RIGHT, Force - nextRandomRealNumberRange(0.0, 2.0 * Force), duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY
}
}
Поиск и сортировка
Линейный поиск
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
DecimalNumber X = this.getDoubleFromUser("X")
Boolean Found = false
while (BOTH (NOT Found) and (i < Arr.Length)) is true
{
if (X == Arr[i]) is true then
{
this.alice say "X найден в позиции " + i
Found = true
}
else
i = i + 1
}
if (NOT Found) is true then
this.alice say "X не найден"
Сортировка выбором
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
WholeNumber j = 0
DecimalNumber X = 0.0
while (i < Arr.Length) is true
{
j = i + 1
while (j < Arr.Length) is true
{
if (Arr[i] < Arr[j]) is true then
{
C = Arr[i]
Arr[i] = Arr[j]
Arr[j] = C
}
j = j + 1
}
i = i + 1
}
for each (DecimalNumber n) in Arr
this.alice say "n:" + n