Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Lua: Problem #5: Three-of-a-crime Three-of-a-crime is a simple logic game for

ID: 3598291 • Letter: I

Question

In Lua: Problem #5: Three-of-a-crime Three-of-a-crime is a simple logic game for up to 3 pl randomly chooses three of these (the " computer then puts down three random criminols. O, 1, or 2 of these may b computer also tells the player how many (but not which) of the three players may either guess which three criminals are the actual perpetrators or guesses wrong, she is out of the other play computer puts down another three randomly chosen criminals perpetrators) and tells the players how many (but not which) of these are ayers. There are 7 different criminals. The computer perpetrators"), but doesn't tell the players which are the actual perpetrators. The criminals are perpetrators. The the game and the other players continue. If no player chooses to guess, (O, 1, or 2 of which may be actual actual perpetrators. Players can again use logic to deduce the three actual criminals and may guess. Play continues until some player quesses correctly or until all players have guessed incorrectly An example play Assume the criminals are called ""b d e, and"g". The computer chooses three of these randomly, say "b","" and . These criminals are the actual perpetrators.The computer does not reveal this to the players The Now the computer chooses three criminals randomly and displays them to the players. Say d dn and are chosen and displayed. The computer also tells the players that 1 of these criminals is an actual perpetrator. The players may guess who the actual three perpetrators are. Of course, at this point it's not possible to deduce who the actual perpetrators are, so no player should guess. Since no player guessed, the computer again chooses three them to the players. Say "a", "b", and "f". The computer tells the players tat woo criminals randomly and reveals criminals are actual perpetrators, but does not reveal which ones are the real perpetrors. Using logic, the players try to deduce who the actual three perpetrators are. Etc. Your program should be visual if possible with your language. Only if your language does not supp GUl interactions may you use a text based interface.

Explanation / Answer

Please find the code below:

;;;;;;;;;;;;;;;;;;;;
(load "ltk/ltk") ;load ltk package for gui
(in-package :ltk) ; use ltk
(defvar *criminals* nil); global variable
(defvar *actppts* nil); global variable
(defvar *temp* nil); global variable
(defvar *try* nil); gloval variable
(setf *criminals* '(a b c d e f g)); creat list 7 elemetns of potential perpetrators
(defun getRC(x s) (nth (random x) s)) ; define a function to get a ramdom element of list s.
; main function
(defun getran (a s b)
(let ((alist '()))
(loop while (< (length alist) b) do
(pushnew (getrc a s) alist))
(return-from getran alist)))
;get random criminals as the actual perpetrators.
(setf *actppts* (getran 7 *criminals* 3)) ; get 3 random criminals as the actural perpetrators and assign them to actppts)
;;;;;;;;;;;;GUI
(defun builder()
(with-ltk ()
(let* ((f (make-instance 'frame))
(l1 (make-instance 'label
:master f
:text "Three-of-crime Game: A B C D E F G"))
(t1 (make-instance 'text :master f :width 100 :height 45))
(e (make-instance 'entry :master f))
(b1 (make-instance 'button
:master f
:text "Guess"
:command (lambda () (setf *try* (with-input-from-string (s (text e)) (read s)))
(append-text t1 (format nil "Your guess: ~s~%" *try*))
(if (and (subsetp *actppts* *try*) (subsetp *try* *actppts*))
(append-text t1 (format nil "~s~%" "You are the winner Congratulations!"))
(append-text t1 (format nil "~s~%" "Nice try but you are out!")))
)))
(b2 (make-instance 'button
:master f
:text "Show"
:command (lambda () (setf *temp* (getran 7 *criminals* 3)) (append-text t1 (format nil "~s~% Actural Perpetrators: ~D~%" *temp*
(length (intersection *temp* *actppts* ))))))))
(pack f)
(pack t1 :fill :both :expand t)
(pack l1)
(pack b2 :side :left)
(pack e :side :left)
(pack b1 :side :left)
(configure l1 :background :Green)
(configure l1 :font :20)
(configure t1 :font :18)
(configure f :borderwidth 1)
)))
;;;;;;;;;;;;;;;;;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote