Stats 20 - Lab 1
For this lab you are going to focus on outlining your IDEAS for your code prior to writing
your code. You can see an example different levels of pseudocode in week 3 of the TA
site on CCLE for this course. This lab will be due May 6, before the start of class.
Your lab should be done in R Markdown and knitted as an HTML or PDF document.
You’ll need to submit both a .Rmd file which knits as well as your final output file.
1. Fibonacci
The Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, …) is defined as F(1) = 1, F(2) =
1, F(n) = F(n-1) + F(n-2).
a. Write pseudocode to calculate F(n)
b. Write pseudocode to construct a vector of the first n numbers in the Fibonacci
sequence.
c. Write a function:
fibo(n = 1){
# Your code here
}
which takes one parameter n and returns the nth fibonacci number.
d. Use the function you wrote to calculate the 58th Fibonacci number. Include your
R code in your report.
2. Tic-Tac-Toe
a. Write rules of the game.
b. Write high-level pseudocode for playing one game between two human players.
i. Include pseudocode for what happens before, during, and after the game.
c. Identify which elements of the game need to be tracked.
i. For each element which you will track:
1. Describe the type of object you think is appropriate to store the
game element. (e.g. A numeric vector, a character matrix, a
data.frame, etc.). Describe in as much detail as possible how you
would use each object to store its associated game element.
d. Identify parts of your pseudocode which could be turned into individual functions.
i. For each function you identify:
1. List required function inputs.
2. List desired function output.
3. pseudocode each function.
e. A game of tic-tac-toe has, at most 9 turns, write out the turns of a single game,
move by move, in language a (normal) human would use to describe the game.
Annotate each turn with an explanation of what the repercussions of each move
are with regard to which functions would be called leading up to, during, and after
each turn, what their input and output values should be, and list what the game
element variables contain after the turn.
A good way to represent the game values is in a table, i.e.:
Turn Var1 Var2 Var3 Var4
0 1 FALSE c() c()
1 2 FALSE c(3) c()
2 1 FALSE c(3,5) c()
... ... ... ... ...
f. Discuss what you would need to change or add to create an AI to play tic-tac-toe
against you.
i. What would the simplest AI opponent do?
1. pseudocode the simplest AI.
a. List the functions this AI would need to call to take its turn
and for each:
i. Describe the required inputs.
ii. Describe the desired output.
ii. What would a sophisticated tic-tac-toe AI do?
1. pseudocode a sophisticated AI.
a. List the functions this AI would need to call to take its turn
and for each:
i. Describe the required inputs.
ii. Describe the desired output.
g. Discuss how you would add the functionality to have two AI (the simple and
sophisticated) AI play against each other.
i. Write pseudocode to play one AI vs AI game.
ii. Extend this to allow an arbitrary number of AI games to be played.
h. Put all of your pseudocode together into a comprehensive outline for
programming a complete tic-tac-toe game.
i. ATTEMPT to write as much as you can of the actual game of tic-tac-toe between
two human players as possible. You do NOT need to write a fully functioning
tic-tac-toe game to get full credit on this lab.
i. Construct the objects to hold game elements.
ii. Write, in R, any functions you are comfortable trying to write.
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。