FBP Workshop/Homework

Posted javapythonc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FBP Workshop/Homework相关的知识,希望对你有一定的参考价值。


FBP Workshop/Homework
Predator/Prey
All slides Copyright 2019 by Michael V. Osier. All rights reserved.
Changes in output this week
#include <stdio.h>
int main()
{
int dice = 5;
printf(“%d ”,dice);
}
printf
Symbol… For…
%d or %i Decimal number (i for
integer)
%f float/double
%e float/double with E
notation
%s Null-terminated string
%c Character
getchar
char c;
c = getchar();
This week – Predator/Prey
This week, you get to build a predator/prey
model in C.
For those who took IBP, this is a C version of
your code.
Predator/Prey requirements
Your program will create a 2D array of 10x10.
Each location can host a predator, a prey, or
nothing.
Pick 10 random locations for prey and one for a
predator...make sure that they do not overlap!
Print to the screen the 2D matrix as a matrix.
Wait for the user to press enter before
continuing.
Round 1
Predator
Keeping track of critters
Each creature, predator or prey, has a
non-overlapping position.
Prey also keep track of how much they
have eaten.
How many possible prey can you have?
Keeping track of critters
Each creature, predator or prey, has a
non-overlapping position.
Prey also keep track of how much they
have eaten.
How many possible prey can you have?
– 10x10 = 100 (-1 for the predator)
If you have many prey, what data structure
would be best to contain them?
Predator/Prey requirements
Each round, predator and prey can take an
action.
A predator will choose, in order of preference to:
– Move into the square of a neighboring prey. If it does,
it “eats” the prey, which now disappears.
– Move into a random neighboring square.
Then the prey act.
– “Eat” (increment a counter) and move into a random neighboring
square that is empty.
– If there are no neighboring squares open, stay put. – Think about how to store the total number of “eats”
each prey has...
After each round, print the matrix.
C and random
#include <stdlib.h>
[..]
srand(5432);
int dice;
dice = rand();
C and random
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(0));
int dice;
dice = rand();
printf("%d ",dice);
}
C and random
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(0));
int dice;
dice = rand();
printf("%d ",dice);
}
Randomization
functions
C and random
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(0));
int dice;
dice = rand();
printf("%d ",dice);
}
printf
C and random
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(0));
int dice;
dice = rand();
printf("%d ",dice);
}
time
Predator/Prey requirements
Each round the model will act for each
predator.
– Eaten prey disappear from the original matrix
and array.
The model will then act for all remaining
prey.
Print the matrix.
Wait for user to press Enter
Repeat until there are no prey or no
predators.
Workshop
Create the main model.
Initialize the matrix with predators/prey
and print it.
Keep track of how much prey have
consumed.
Not required to iterate over rounds.
Homework
Iterate over rounds and debug.
HW Bonus points
A) Modify the code to allow prey to reproduce after
eating five times. What happens to the model? (0.2 pts)
B) Modify the code to allow predators to reproduce after
eating five times, but to lose one “eating” for every round
without eating. Predators start with 4 “eats” and die if
their “eat” count goes to 0. What happens to the model?
(0.2 pts)
After implementing bonus A and B, run the simulation 20
times to completion. Record how often the simulation
goes to all predators, how many times to all prey, and
how many times unresolved. (0.2 pts)

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

























































































































































以上是关于FBP Workshop/Homework的主要内容,如果未能解决你的问题,请参考以下文章

js虚拟数字小键盘

机器学习预测足球比赛项目——80%准确率

试着利用BAPI 寻找F-59创建凭证的函数

Facebook iOS SDK,使用 ShareDialog(不是 GraphAPI)分享带有标题的图像

基于代谢网络模型分析改造大肠杆菌生产聚3-羟基丁酸

赛门铁克NBU基于Linux平台,重启客户端服务的命令是啥?