Howdy. 

C212/A592 Introduction to Software Systems

Adrian German dgerman@indiana.edu Lindley Hall 204 (LH204)

Two lectures and one lab

Canvas

Class website: http://www.cs.indiana.edu/classes/c212

What's New? 

What's Due? 

Class Notes

Example of class notes: 

https://www.cs.indiana.edu/classes/c212-dgerman/sum2017/0619a.html

Everybody has a silo account (Unix) 

You connect to silo using SSH (PuTTY)

https://iuware.iu.edu/Windows/List/140

silo.cs.indiana.edu

Minute Paper: 

  Name/Username 

  What's your Major/Minor

  Is this class required? 

  What are some reasons you're taking this class

  What are your expectations

  What would you want to be able to do at the end 
  of this class to feel accomplished.

Any other questions/comments welcome. 

Fears/concerns at this time? 

http://registrar.indiana.edu/browser/soc4178fac/CSCI/CSCI-C212.shtml

To get a grade in this class:

  Attendance              5%
  Labs                   15%
  Homework               15%
  Semester Project       15%
  Early Eval Exam        10% Sep 18 
  Midterm Exam           15% Oct 06 (to be confirmed tomorrow) 
  Project Readiness Exam 10% Nov 06
  Final Exam             15% Dec 13

[jackbarr@silo ~]$ clear
[jackbarr@silo ~]$ pwd
/u/jackbarr
[jackbarr@silo ~]$ ls
bin  README
[jackbarr@silo ~]$ ls -l
total 4
drwx------ 2 jackbarr students  10 Aug 18 13:56 bin
-rw------- 1 jackbarr students 485 Aug 18 13:56 README
[jackbarr@silo ~]$ cat README
This README file is distributed with new accounts and provides pointers to
some basic information about your new School of Informatics and Computing
Linux account.

  - Please see the SoIC Knowledge Base for general information

        http://help.soic.indiana.edu/

  - You can submit a service request for SoIC help at:

        http://help.soic.indiana.edu/request

  - Specific and detailed information about your Linux account is available at:

        https://uisapp2.iu.edu/confluence-prd/x/DAHTBg
[jackbarr@silo ~]$

        July                  August                September
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5                   1  2
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    3  4  5  6  7  8  9
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   10 11 12 13 14 15 16
16 17 18 19 20 21 22   20 21 22 23 24 25 26   17 18 19 20 21 22 23
23 24 25 26 27 28 29   27 28 29 30 31         24 25 26 27 28 29 30
30 31
       October               November               December
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7             1  2  3  4                   1  2
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    3  4  5  6  7  8  9
15 16 17 18 19 20 21   12 13 14 15 16 17 18   10 11 12 13 14 15 16
22 23 24 25 26 27 28   19 20 21 22 23 24 25   17 18 19 20 21 22 23
29 30 31               26 27 28 29 30         24 25 26 27 28 29 30
                                              31

http://enrollmentbulletin.indiana.edu/pages/finexpol.php?t=fall

9:05 and 10:05 a.m. M,W,F,daily 8:00-10:00 a.m., Wed., December 13

http://registrar.indiana.edu/official-calendar/official-calendar-fall.shtml

Auto W    Sun, Oct 22

I think you came here from C211. 

What was your experience with C211. 

http://www.ccs.neu.edu/home/matthias/HtDP2e/

Design Recipe: 

  (a) choose a data representation
  (b) give some examples 
  (c) name function, and arguments
  (d) purpose statement
  (e) examples of how the function works
  (f) choose the right template
  (g) flesh the template out (write code)
  (h) write and run your check-expects

Templates: 

  (a) functional decomposition
  (b) atomic templates
  (c) structural recursion 
  (d) generative recursion (needs a proof of termination) 
  (e) accumulator-passing style (needs invariant for each accumulator) 

Also: there is a hierarchy of languages in that class

It starts with BSL, ISL/ISL+, ASL. Then Racket. 

This class uses Java. 

DrRacket


(require 2htdp/image)
(require 2htdp/universe)

; A Point is a (make-point Number Number)
(define-struct point (x y))

; A Circle is a (make-circl Point Number)
(define-struct circl (center radius))

; A ManyCircl is one of:
;   -- empty

;   -- (cons Circle ManyCircl)

; A World is a ManyCircl 

; (big-bang initial
;           (to-draw ...)
;           (on-tick ...)
;           (on-mouse ...))

(define initial empty)

; render : World -> Image
; (define (render world)
;   (cond ((empty? world) ...)
;         (else (... (first world) ... (render (rest world)) ...))))
(define (render world)
  (cond ((empty? world) (empty-scene 400 400))
        (else (place-image (circle (circl-radius (first world)) "outline" "red")
                           (point-x (circl-center (first world)))
                           (point-y (circl-center (first world)))
                           (render (rest world))))))

(define sample-world (cons (make-circl (make-point 300 300) 30) 
                      (cons (make-circl (make-point 200 100) 80)
                       (cons (make-circl (make-point  50  50) 10) empty))))

; enlarge : circl -> circl
; increases the radius by 1 pixel 
(define (enlarge circl)
  (make-circl (circl-center circl) (add1 (circl-radius circl))))

; update : world -> world

(define (update world)
  (cond ((empty? world) world)
        (else (cons (enlarge (first world))
                    (update (rest world))))))

; meh : world x y event -> world

(define (meh world x y event)
  (cond ((mouse=? "button-down" event) 
         (cons (make-circl (make-point x y) 1)
               world))
        (else world)))

(big-bang sample-world
          (to-draw render)
          (on-tick update)
          (on-mouse meh))



  
; Here's a legitimate and plausible student solution. Joel Bierman and 
; Kristopher Jung get credit for various parts of the code below as well
; as for coming to office hours to discuss this problem. Others too, but
; their influence in the code below is not as apparent. 

; So what can you find below? Let's remember that:

; (a) Homework 05 was solved in lecture twice. 
; (b) snake movement was designed in lecture and posted.
; (c) you were mostly responsible for
;       -- change direction
;       -- eat food
;       -- grow 
;       -- stop when snake steps out or over itself

; I am going to try to mark those spots for you below.
;
;
; Note: use ISL/+ with the code below. 
;

(require 2htdp/image)                                            ; this was given in the problem text
                                                                 ; 
; A World is:                                                    ;
;-- (make-world Snake Food)                                      ;
(define-struct world (snake food))                               ;
                                                                 ;
; A Snake is:                                                    ;
;-- (make-snake Direction Head Body)                             ;
(define-struct snake (direction head body))                      ;
                                                                 ;
; A Direction is one of:                                         ;
;-- "north"                                                      ; 
;-- "east"                                                       ;
;-- "south"                                                      ;
;-- "west"                                                       ;
                                                                 ;
; A Food is [List of Posn]                                       ;
                                                                 ;
; A Head is a Posn                                               ;
                                                                 ;
; A Body is [Listof Posn]                                        ; all the way up to here: given 

;1.                                                                                            ; this was developed in lecture as an example 
                                                                                               ; later it was provided as is for Homework 06 
(define s1 (make-snake "north" (make-posn 200 200) '()))                                       ;
                                                                                               ;
;2.                                                                                            ;
                                                                                               ;
(define f1 (list (make-posn 300 300) (make-posn 151 327)))                                     ;
                                                                                               ;
;3.                                                                                            ;
                                                                                               ;
(define w1 (make-world s1 f1))                                                                 ;
                                                                                               ;
;4.                                                                                            ;
                                                                                               ; 
(define R 5)                                                                                   ;
(define s2 (make-snake "north" (make-posn 200 200) (list (make-posn 200 (+ 200 (* 2 R)))       ;
                                                       (make-posn 200 (+ 200 (* 4 R)))         ;
                                                       (make-posn 200 (+ 200 (* 6 R)))         ;
                                                       (make-posn 200 (+ 200 (* 8 R)))         ;
                                                       (make-posn 200 (+ 200 (* 10 R)))        ;
                                                       (make-posn 200 (+ 200 (* 12 R))))))     ;
                                                                                               ;
;5.                                                                                            ;
                                                                                               ;
(define f2 (list (make-posn 123 21)                                                            ;
                 (make-posn 178 239)                                                           ;
                 (make-posn 98 51)                                                             ;
                 (make-posn 259 371)                                                           ;
                 (make-posn 309 108)))                                                         ;
                                                                                               ;
;6.                                                                                            ;
                                                                                               ;
(define w2 (make-world s2 f2))                                                                 ; all of this: done in class (lecture) 
                                                                                               ; 
;7.                                                                 ;
                                                                    ; this was also designed in class but not posted
; render-food : Food Image -> Image                                 ; I told you not to take pictures or notes
;                                                                   ; however I wanted you to watch, think, ask questions
(define (render-food food image)                                    ; later on we posted huge clues as part of Homework 06
  (cond                                                             ; in which we reminded you how these functions should work
    [(empty? food) image]                                           ;
    [else (place-image (circle 5 "solid" "gold")                    ;
                       (posn-x (first food)) (posn-y (first food))  ;
                       (render-food (rest food) image))]))          ;
                                                                    ;
; render-snake-body : Body Image -> Image                           ;
;                                                                   ;
(define (render-snake-body body image)                              ;
  (cond                                                             ;
    [(empty? body) image]                                           ;
    [else (place-image (circle 5 "solid" "red")                     ;
                       (posn-x (first body)) (posn-y (first body))  ;
                       (render-snake-body (rest body) image))]))    ;
                                                                    ;
; render-snake-head : Head Image -> Image                           ;
;                                                                   ;
(define (render-snake-head head image)                              ;
        (place-image (circle 5 "solid" "blue")                      ;
                                   (posn-x head) (posn-y head)      ;
                                   image))                          ;
; render-world : World -> Image                                     ;
;                                                                   ;
(define (render-world world)                                        ;
       (render-snake-head (snake-head (world-snake world))          ;
         (render-snake-body (snake-body (world-snake world))        ;
          (render-food (world-food world) (empty-scene 400 400))))) ;
                                                                    ; so up to here: should be pretty clear

; HOMEWORK 6                                ; this is where the new stuff starts (more or less) 
                                            ;
;8, 10, 11                                  ;
                                            ; 
; DistanceHelp : Posn Posn -> Number        ;
;                                           ;
(define (DistanceHelp a b)                  ; this is something we discussed in Lab 07 (helps with overlaps?)
  (sqrt (+ (sqr (- (posn-x a) (posn-x b)))  ;
           (sqr (- (posn-y a) (posn-y b))))))
                                            ;
; FoodClose? Posn Posn : Boolean            ;
; will be called with a food item and the position of the head and determines if the item vanishes or not
(define (FoodClose? a b)                    ;
;  (cond                                    ;
;    [(empty? b) "false"]                   ; and this is a legacy function Joel had in his code
;    [(list? b)                             ;
     (if (<= (DistanceHelp a b) ; (first a));
                           10) true false)) ; (DistanceHelp a (rest a)))) ; )) so up to here: still easy 
                                            ; 
; new-head : Snake Number Number -> Head                                            ; from here on we refactored something designed/developed in lecture
; based on displacements (which reflect direction of movement) generate new head    ; if you want to review the original code go to May 25 What's New?
(define (new-head s dx dy)                                                          ; here's the page:
  (make-posn (+ dx (posn-x (snake-head s)))                                         ;   http://silo.cs.indiana.edu:8346/c211/sum2017/0525a.phps
             (+ dy (posn-y (snake-head s)))))                                       ; 
                                                                                    ; 
; new-body : World -> Body                                                          ; however below we grow the snake if needed 
; produces the new body of the moving snake                                         ; that part is new
(define (new-body w)                                                                ;
  (if (not (ormap (lambda (item)                                                    ;
                    (FoodClose? item (snake-head (world-snake w))))                 ;         <----      here's when it needs to happen 
                  (world-food w)))                                                  ; 
      (cons (make-posn (posn-x (snake-head (world-snake w))) ; if true I don't get longer 
                       (posn-y (snake-head (world-snake w))))                       ;
            (reverse (rest (reverse (snake-body (world-snake w))))))                ; 
      (cons (make-posn (posn-x (snake-head (world-snake w))) ; else I grow by one segment     <-----     here's how it happens
                       (posn-y (snake-head (world-snake w))))                       ; 
            (snake-body (world-snake w)))))                                         ; so there's one new thing here
                                                                                    ; outside of the refactoring 
                                                                                    ; (which was optional but benefic)
; move-snake : World -> Snake                                                       ;
;                                                                                   ;
(define (move-snake w)                                                              ; look how simple this becomes
  (cond                                                                             ; we wrote this in class on 5/25
    [(string=? "north" (snake-direction (world-snake w)))                           ; but it's so much shorter with
     (make-snake "north" (new-head (world-snake w)   0 -10) (new-body w))]          ; the new functions new-head/body
    [(string=? "south" (snake-direction (world-snake w)))                           ;
     (make-snake "south" (new-head (world-snake w)   0  10) (new-body w))]          ;
    [(string=?  "east" (snake-direction (world-snake w)))                           ;
     (make-snake  "east" (new-head (world-snake w)  10   0) (new-body w))]          ;
    [(string=?  "west" (snake-direction (world-snake w)))                           ;
     (make-snake  "west" (new-head (world-snake w) -10   0) (new-body w))]          ;
    (else (error "What's going on?"))))                                             ; so so far: just one new thing, growing
                                                                                    ;
(define (change s a-key)                                                 ;
  (cond                                                                  ;
        [(key=? a-key "left")                                            ; this was not done in class
         (make-world (make-snake "west" (snake-head (world-snake s))     ; I may have told you it's easy
                                        (snake-body (world-snake s)))    ; (since it obviously is) 
                     (world-food s))]                                    ; and how easy it is and why
        [(key=? a-key "up")                                              ; but you were to develop and 
         (make-world (make-snake "north" (snake-head (world-snake s))    ; integrate this yourselves 
                                         (snake-body (world-snake s)))   ; so that was something to do
                     (world-food s))]                                    ;
        [(key=? a-key "right")                                           ; 
         (make-world (make-snake "east" (snake-head (world-snake s))     ;
                                        (snake-body (world-snake s)))    ;
                     (world-food s))]                                    ; 
        [(key=? a-key "down")                                            ; it feels good when the snake moves
         (make-world (make-snake "south" (snake-head (world-snake s))    ; it feels even better when it turns
                                         (snake-body (world-snake s)))   ;
                     (world-food s))]))                                  ; now you can control the snake! 

; remaining-food : World -> Food                   ;
;                                                  ; now this is something I helped many of you with
(define (remaining-food w)                         ; during office hours. In all cases I encouraged you
  (filter (lambda (item)                           ; to switch to ISL/+ since you get to use filter. We
            (not (FoodClose? item                  ; postponed this homework many times and by the time
                             (snake-head           ; it became urgent (as we were approaching the final
                              (world-snake w)))))  ; deadline) you were already relatively fluent in ISL
          (world-food w)))                         ; and even ISL/+ where we don't need to do anything too
                                                   ; fancy with lambdas just use them anonymously in place
; update-world : World -> World                    ;
;                                                  ; the function above is a helper, it helps filter food
(define (update-world w)                           ;
  (make-world                                      ; remaining food is what isn't too close to the snake's head
   (move-snake w)                                  ;
   (let ((a (remaining-food w)))                   ; see how we calculate it here and remember it with a let 
     (if (< (length a)                             ; then compare it's length with it's previous length...
            (length (world-food w)))               ;             ... if we lose at least one food item (and
         (cons (make-posn (random 400) (random 400)) a) ;            since the distribution is entirely random
         a))))                                     ;                 we might lose multiple if they're placed
                                                   ;                 too closely apart (like in a cluster)
                                                   ; then we need to add a new item randomly placed.
                               ; 
(define initialworld w2)       ; getting ready to start big-bang                    
                               ; 
;9.                                                ; there's a small chance one can eat all the food    
                                                   ; very unlikely but in that rare case we can maybe
(require 2htdp/universe)                           ; consider the user actually won the game (code not included for that )
                                          ;               
;ending scene                             ; this is the ending scene. One of the few that used it well was
(define (say-goodbye world)               ; Kristopher. I changed what he had though, but not in essence. His
  (place-image (text "GAME" 70 "black")   ; game is played in a much bigger window, that's basically all. 
                200 150                   ;
               (place-image (text "OVER" 70 "black")
                             200 250      ;
                            (render-world world))))
                                          ;
                                          ;
; it-ends : World -> Boolean                                    ; this predicate determines if the game ends or not
;                                                               ; it checks for two things: 
(define (it-ends world)                                         ;
  (or (< (posn-x (snake-head (world-snake world))) -400)        ; (a) if the snake goes too far the game ends
      (< (posn-y (snake-head (world-snake world))) -400)        ;
      (> (posn-x (snake-head (world-snake world)))  800)        ; 
      (> (posn-y (snake-head (world-snake world)))  800)        ;
      (ormap (lambda (body-element)                             ; (b) if the snake trips over itself that's fatal too
               (overlaps? (snake-head (world-snake world))      ; 
                           body-element))                       ; so in my view here the snake is allowed to get
             (snake-body (world-snake world)))))                ; out of the game scene, sometimes that's useful
                                                                ; but it can't get too far (-800 < x, y < 800). 
; overlaps : Posn Posn -> Boolean     ; I wrote a second 
;                                     ; function to determine 
(define (overlaps? a b)               ; overlapping because Joel's 
  (<= (DistanceHelp a b) 8))          ; was a bit too greedy (and snake could not survive it)
      
(big-bang initialworld                         ; and that's it
          (to-draw render-world)               ; you know this 
          (on-tick update-world)               ; variation: (on-tick update-world 0.5) 0.5 is in seconds
          (on-key change)                      ; you also know this
          (stop-when it-ends say-goodbye))     ; this is new, there's a predicate and a scene function 


; -- you can just copy and paste the above in DrRacket/ISL+ and run it. 

https://www.cs.indiana.edu/classes/c212-dgerman/fall2016/resources/rctmpx/toc.html

We use DrJava in this class. 

--

I'll send everybody a note tomorrow with an update. 

https://www.khanacademy.org/science/physics/review-for-ap-physics-1-exam