I want code in GO programming language and with some GUI interfaces too in the c
ID: 3567766 • Letter: I
Question
I want code in GO programming language and with some GUI interfaces too in the code......
Three-of-a-crime is a simple logic game for up to 3 players. There are 7 different criminals. The computer randomly chooses three of these (the "perpetrators"), but doesn't tell the players which are chosen. The computer then puts down three random criminals. 0, 1, or 2 of these may be the actual perpetrators. The computer also tells the player how many (but not which) of the three criminals are perpetrators. The players may either guess which three criminals are the actual perpetrators or they may pass. If a player guesses wrong, she is out of the game and the other players continue. If no player chooses to guess, the computer puts down another three randomly chosen criminals (0, 1, or 2 of which may be actual perpetrators) and tells the players how many (but not which) of these are actual perpetrators. Players can again use logic to deduce the three actual criminals and may guess. Play continues until some player guesses correctly or until all players have guessed incorrectly...
Explanation / Answer
;;;;;;;;;;;;;;;;;;;;
(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)
)))
;;;;;;;;;;;;;;;;;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.