Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priyamapara #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# CMSC 388Q
Course material for CMSC 388Q
Course material for CMSC 388Q\
Coded by: Priya Mapara, Myckell Ronquillo, and Maya Narayanasamy

Guessing game code: specified number, random number generator, with a GUI

Find leap year code
65 changes: 65 additions & 0 deletions guessing-gui.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
; This program is a simple guessing game with a gui
; Coded by Myckell Ronquillo

#lang racket
(require 2htdp/universe 2htdp/image)

; Guessing range
(struct range (min max))

; Help text
(define TOP-TEXT
(text "Up Arrow if # > current, Down Arrow if # < current"
20
"black"))
(define BOTTOM-TEXT
(text "Press SPACE if curr # is correct"
20
"black"))

; Screen display settings
(define SCREEN-DISP
(place-image/align
TOP-TEXT 3 10 "left" "top"
(place-image/align
BOTTOM-TEXT 3 130 "left" "bottom"
(empty-scene 475 150))))

; Key-Events
(define (deal-with-guess n key)
(cond [(key=? key "up") (bigger n)]
[(key=? key "down") (smaller n)]
[(key=? key " ") (stop-with n)]
[else n]))

; If number is less than current
(define (smaller n)
(range (range-min n)
(max (range-min n) (sub1 (guess n)))))

; If number is greater than current
(define (bigger n)
(range (min (range-max n) (add1 (guess n)))
(range-max n)))

; Does the binary search
(define (guess n)
(quotient (+ (range-min n) (range-max n)) 2))

; Rendering
(define (render n)
(overlay (text (number->string (guess n)) 32 "red") SCREEN-DISP))

(define (render-last-scene n)
(overlay (text (string-append "Your number is: " (number->string (guess n))) 32 "green") SCREEN-DISP))

; If number is found
(define (single? n)
(= (range-min n) (range-max n)))

; Main
(define (start lower upper)
(big-bang (range lower upper)
(on-key deal-with-guess)
(to-draw render)
(stop-when single? render-last-scene)))
29 changes: 29 additions & 0 deletions intro-racket.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#lang slideshow
;; the racket tutorial // playing around with racket
(define c (circle 10))
(define r (rectangle 10 20))

(define (four p)
(define two-p (hc-append p p))
(vc-append two-p two-p))

(define (checker p1 p2)
(let ([p12 (hc-append p1 p2)]
[p21 (hc-append p2 p1)])
(vc-append p12 p21)))
(define (square n)
; A semi-colon starts a line comment.
; The expression below is the function body.
(filled-rectangle n n))

(define (checkerboard p)
(let* ([rp (colorize p "red")]
[bp (colorize p "black")]
[c (checker rp bp)]
[c4 (four c)])
(four c4)))

(define x 10) ;; x = 10



19 changes: 19 additions & 0 deletions is-leap-year.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#lang racket

;; Coded by: Myckell Ronquillo, Maya Narayanasamy, and Priya Mapara

(displayln "Is leap year? ")
(newline)
(displayln "A simple program that checks if the year entered is a leap year.")
(displayln "To use this function, simply type in 'is-leap-year' and add the year")
(displayln "you would like to check to see whether it is a leap year or not.")
(newline)

(define (is-leap-year year)
(if (equal? 0 (modulo year 400)) "This is a leap year" "This is not a leap year")
(if (equal? 0 (modulo year 100)) "This is not a leap year" "This is not a leap year")
(if (equal? 0 (modulo year 4)) "This is a leap year" "This is not a leap year"))




39 changes: 39 additions & 0 deletions number guessing game with random generator.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#lang racket

;; coded by: Maya Narayanasamy & Priya Mapara
;; used https://medium.com/@gjorgigjorgiev/guess-my-number-game-in-racket-3b47fe15a652 as a reference.
;; includes a random number generator

(displayln "Number Guessing Game ")
(newline)
(displayln "A simple program that will allow a user to enter a number.")
(displayln "The user wil try to guess the number that is predetermined.")
(displayln "If the number entered by the user is higher than the correct number,")
(displayln "the phrase 'Too high. Try Again.' will be printed. If the number is lower ")
(displayln "'Too Low. Try Again. will be printed.")
(displayln "the number.")
(newline)

;; holds the content of the messages that will be displayed.
(struct m (start-game guess-high guess-low win lose))
(define messages(m "Enter a number from 1-100: " "\nThe number you guessed is too high. Try Again. ""\nThe number you guessed is too low. Try Again. "
"\n You gussed correctly!\n" "\nYou reached the maximum limit of guesses\n"))


;; max number of tries
(define (max-tries . args) 5)
;; the number to be guessed
(define (number . args) (random 100))
;; scanning user input
(define (user-guess . args)(read))
;; displaying the messages and check cases
(define (display-msg msg)(display msg))(define (make-game number guesses)(define (curr-game curr-guesses)
(let ((curr-guess (user-guess)))
(cond
[(> number curr-guess )(display-msg (m-guess-low messages))(curr-game (+ 1 curr-guesses))]
[(< number curr-guess)(display-msg (m-guess-high messages))(curr-game (+ 1 curr-guesses))]
[(equal? curr-guess number)(display-msg (m-win messages))]
[(= curr-guesses guesses) (display-msg (m-lose messages))])))
curr-game)
;; starts the game
(module* main #f (m-start-game messages)((make-game (number)(max-tries)) 1))
37 changes: 37 additions & 0 deletions number-guessing-game.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#lang racket

;; Coded by: Priya Mapara
;; used https://medium.com/@gjorgigjorgiev/guess-my-number-game-in-racket-3b47fe15a652 as a reference.

(displayln "Number Guessing Game ")
(newline)
(displayln "A simple program that will allow a user to enter a number.")
(displayln "The user wil try to guess the number that is predetermined.")
(displayln "If the number entered by the user is higher than the correct number,")
(displayln "the phrase 'Too high. Try Again.' will be printed. If the number is lower ")
(displayln "'Too Low. Try Again. will be printed.")
(displayln "the number.")
(newline)

;; holds the content of the messages that will be displayed.
(struct m (start-game guess-high guess-low win lose))
(define messages(m "Enter a number from 1-100: " "\nThe number you guessed is too high. Try Again. ""\nThe number you guessed is too low. Try Again. "
"\n You gussed correctly!\n" "\nYou reached the maximum limit of guesses\n"))

;; max number of tries
(define (max-tries . args) 5)
;; the number to be guessed
(define (number . args) 68)
;; scanning user input
(define (user-guess . args)(read))
;; displaying the messages and check cases
(define (display-msg msg)(display msg))(define (make-game number guesses)(define (curr-game curr-guesses)
(let ((curr-guess (user-guess)))
(cond
[(> number curr-guess )(display-msg (m-guess-low messages))(curr-game (+ 1 curr-guesses))]
[(< number curr-guess)(display-msg (m-guess-high messages))(curr-game (+ 1 curr-guesses))]
[(equal? curr-guess number)(display-msg (m-win messages))]
[(= curr-guesses guesses) (display-msg (m-lose messages))])))
curr-game)
;; starts the game
(module* main #f (m-start-game messages)((make-game (number)(max-tries)) 1))