Add files via upload
This commit is contained in:
parent
e0a15dae86
commit
9e15516663
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,105 @@
|
|||
(require 2htdp/universe)
|
||||
(require 2htdp/image)
|
||||
|
||||
;; Space Invaders
|
||||
|
||||
|
||||
;; Constants:
|
||||
|
||||
(define WIDTH 300)
|
||||
(define HEIGHT 500)
|
||||
|
||||
(define INVADER-X-SPEED 1.5) ;speeds (not velocities) in pixels per tick
|
||||
(define INVADER-Y-SPEED 1.5)
|
||||
(define TANK-SPEED 2)
|
||||
(define MISSILE-SPEED 10)
|
||||
|
||||
(define HIT-RANGE 10)
|
||||
|
||||
(define INVADE-RATE 100)
|
||||
|
||||
(define BACKGROUND (empty-scene WIDTH HEIGHT))
|
||||
|
||||
(define INVADER
|
||||
(overlay/xy (ellipse 10 15 "outline" "blue") ;cockpit cover
|
||||
-5 6
|
||||
(ellipse 20 10 "solid" "blue"))) ;saucer
|
||||
|
||||
(define TANK
|
||||
(overlay/xy (overlay (ellipse 28 8 "solid" "black") ;tread center
|
||||
(ellipse 30 10 "solid" "green")) ;tread outline
|
||||
5 -14
|
||||
(above (rectangle 5 10 "solid" "black") ;gun
|
||||
(rectangle 20 10 "solid" "black")))) ;main body
|
||||
|
||||
(define TANK-HEIGHT/2 (/ (image-height TANK) 2))
|
||||
|
||||
(define MISSILE (ellipse 5 15 "solid" "red"))
|
||||
|
||||
|
||||
|
||||
;; Data Definitions:
|
||||
|
||||
(define-struct game (invaders missiles tank))
|
||||
;; Game is (make-game (listof Invader) (listof Missile) Tank)
|
||||
;; interp. the current state of a space invaders game
|
||||
;; with the current invaders, missiles and tank position
|
||||
|
||||
;; Game constants defined below Missile data definition
|
||||
|
||||
#;
|
||||
(define (fn-for-game s)
|
||||
(... (fn-for-loinvader (game-invaders s))
|
||||
(fn-for-lom (game-missiles s))
|
||||
(fn-for-tank (game-tank s))))
|
||||
|
||||
|
||||
|
||||
(define-struct tank (x dir))
|
||||
;; Tank is (make-tank Number Integer[-1, 1])
|
||||
;; interp. the tank location is x, HEIGHT - TANK-HEIGHT/2 in screen coordinates
|
||||
;; the tank moves TANK-SPEED pixels per clock tick left if dir -1, right if dir 1
|
||||
|
||||
(define T0 (make-tank (/ WIDTH 2) 1)) ;center going right
|
||||
(define T1 (make-tank 50 1)) ;going right
|
||||
(define T2 (make-tank 50 -1)) ;going left
|
||||
|
||||
#;
|
||||
(define (fn-for-tank t)
|
||||
(... (tank-x t) (tank-dir t)))
|
||||
|
||||
|
||||
|
||||
(define-struct invader (x y dx))
|
||||
;; Invader is (make-invader Number Number Number)
|
||||
;; interp. the invader is at (x, y) in screen coordinates
|
||||
;; the invader along x by dx pixels per clock tick
|
||||
|
||||
(define I1 (make-invader 150 100 12)) ;not landed, moving right
|
||||
(define I2 (make-invader 150 HEIGHT -10)) ;exactly landed, moving left
|
||||
(define I3 (make-invader 150 (+ HEIGHT 10) 10)) ;> landed, moving right
|
||||
|
||||
|
||||
#;
|
||||
(define (fn-for-invader invader)
|
||||
(... (invader-x invader) (invader-y invader) (invader-dx invader)))
|
||||
|
||||
|
||||
(define-struct missile (x y))
|
||||
;; Missile is (make-missile Number Number)
|
||||
;; interp. the missile's location is x y in screen coordinates
|
||||
|
||||
(define M1 (make-missile 150 300)) ;not hit U1
|
||||
(define M2 (make-missile (invader-x I1) (+ (invader-y I1) 10))) ;exactly hit U1
|
||||
(define M3 (make-missile (invader-x I1) (+ (invader-y I1) 5))) ;> hit U1
|
||||
|
||||
#;
|
||||
(define (fn-for-missile m)
|
||||
(... (missile-x m) (missile-y m)))
|
||||
|
||||
|
||||
|
||||
(define G0 (make-game empty empty T0))
|
||||
(define G1 (make-game empty empty T1))
|
||||
(define G2 (make-game (list I1) (list M1) T1))
|
||||
(define G3 (make-game (list I1 I2) (list M1 M2) T1))
|
|
@ -0,0 +1,87 @@
|
|||
;; ta-solver-starter.rkt
|
||||
|
||||
|
||||
|
||||
; PROBLEM 1:
|
||||
;
|
||||
; Consider a social network similar to Twitter called Chirper. Each user has a name, a note about
|
||||
; whether or not they are a verified user, and follows some number of people.
|
||||
;
|
||||
; Design a data definition for Chirper, including a template that is tail recursive and avoids
|
||||
; cycles.
|
||||
;
|
||||
; Then design a function called most-followers which determines which user in a Chirper Network is
|
||||
; followed by the most people.
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
; PROBLEM 2:
|
||||
;
|
||||
; In UBC's version of How to Code, there are often more than 800 students taking
|
||||
; the course in any given semester, meaning there are often over 40 Teaching Assistants.
|
||||
;
|
||||
; Designing a schedule for them by hand is hard work - luckily we've learned enough now to write
|
||||
; a program to do it for us!
|
||||
;
|
||||
; Below are some data definitions for a simplified version of a TA schedule. There are some
|
||||
; number of slots that must be filled, each represented by a natural number. Each TA is
|
||||
; available for some of these slots, and has a maximum number of shifts they can work.
|
||||
;
|
||||
; Design a search program that consumes a list of TAs and a list of Slots, and produces one
|
||||
; valid schedule where each Slot is assigned to a TA, and no TA is working more than their
|
||||
; maximum shifts. If no such schedules exist, produce false.
|
||||
;
|
||||
; You should supplement the given check-expects and remember to follow the recipe!
|
||||
|
||||
|
||||
|
||||
;; Slot is Natural
|
||||
;; interp. each TA slot has a number, is the same length, and none overlap
|
||||
|
||||
(define-struct ta (name max avail))
|
||||
;; TA is (make-ta String Natural (listof Slot))
|
||||
;; interp. the TA's name, number of slots they can work, and slots they're available for
|
||||
|
||||
(define SOBA (make-ta "Soba" 2 (list 1 3)))
|
||||
(define UDON (make-ta "Udon" 1 (list 3 4)))
|
||||
(define RAMEN (make-ta "Ramen" 1 (list 2)))
|
||||
|
||||
(define NOODLE-TAs (list SOBA UDON RAMEN))
|
||||
|
||||
|
||||
|
||||
(define-struct assignment (ta slot))
|
||||
;; Assignment is (make-assignment TA Slot)
|
||||
;; interp. the TA is assigned to work the slot
|
||||
|
||||
;; Schedule is (listof Assignment)
|
||||
|
||||
|
||||
;; ============================= FUNCTIONS
|
||||
|
||||
|
||||
;; (listof TA) (listof Slot) -> Schedule or false
|
||||
;; produce valid schedule given TAs and Slots; false if impossible
|
||||
|
||||
(check-expect (schedule-tas empty empty) empty)
|
||||
(check-expect (schedule-tas empty (list 1 2)) false)
|
||||
(check-expect (schedule-tas (list SOBA) empty) empty)
|
||||
|
||||
(check-expect (schedule-tas (list SOBA) (list 1)) (list (make-assignment SOBA 1)))
|
||||
(check-expect (schedule-tas (list SOBA) (list 2)) false)
|
||||
(check-expect (schedule-tas (list SOBA) (list 1 3)) (list (make-assignment SOBA 3)
|
||||
(make-assignment SOBA 1)))
|
||||
|
||||
(check-expect (schedule-tas NOODLE-TAs (list 1 2 3 4))
|
||||
(list
|
||||
(make-assignment UDON 4)
|
||||
(make-assignment SOBA 3)
|
||||
(make-assignment RAMEN 2)
|
||||
(make-assignment SOBA 1)))
|
||||
|
||||
(check-expect (schedule-tas NOODLE-TAs (list 1 2 3 4 5)) false)
|
||||
|
||||
|
||||
(define (schedule-tas tas slots) empty) ;stub
|
Loading…
Reference in New Issue