Question

In: Computer Science

Write a LISP program to play either the game "Connect Three" on a size 4x4 game...

Write a LISP program to play either the game "Connect Three" on a size 4x4 game board.

Your program must use min-max search and should be invoked by the function call:

> (connect-3)

The game is single player, human vs the computer AI.

Solutions

Expert Solution

;;;; @file connect4.lisp
;;; Variable difficulty Connect 4
;;; A verison of the popular board game which involves an AI player
;;; vs. one human player.


(defun load-relative(filename)
   "Loads files using relative file paths."
  
; Turn off load and compile messages.
   (setf *load-verbose* nil)
(setf *load-print* nil)
(setf *compile-verbose* nil)
(setf *compile-print* nil)

; Compiles and loads relative file paths.
(load (compile-file (merge-pathnames filename *load-truename*))))

;; Ensure necessary global variables are set to supress potential compiler warnings.
(defun reset-game()
(setf game '())
(setf first 0)
(setf difficulty 0)
(setf move-positions '())
(setf win nil)
(setf gameover nil)
)

(defvar move-positions)
(defvar difficulty)
(defvar first '())
(defvar game '())
(defvar firstElem)
(defvar *compMoves*)
(defvar *playerMoves*)
(defvar *oponent*)
(defvar *win*)
(defvar testList)
(defvar winDiagonalDown)
(defvar winDiagonal_up)
(defvar winHorizontal)
(defvar winVertical)
(defvar win)
(defvar firstA)
(defvar firstB)
(defvar nextElem)
(defvar newA)
(defvar newB)
(defvar input)
(defvar play)
(defvar ai-last-move)
(defvar gameover)

; Call reset-game to ensure clean vars.
(reset-game)


;; ------------------------------ LOAD THE NECESSARY FILES ------------------------------
(let ((*error-output* (make-string-output-stream)))
;; Compile & load helper functions.
(load-relative "inc/helper.lisp")

;; Compile & load AI engine file.
(load-relative "inc/ai.lisp")

;; Compile & load output file.
(load-relative "inc/output.lisp")

;; Compile & load file that checks gameplay for wins.
(load-relative "inc/winCheck2.lisp")

;; Compile & load helper main program control file.
;; Load main.lisp last, so it has all its dependencies.
(load-relative "inc/main.lisp")

;; Print compile errors to file, rather than to the std-out.
(with-open-file (str (merge-pathnames "tmp/compile.log" *load-truename*)
:direction :output
:if-exists :append
:if-does-not-exist :create)
(format str (concatenate 'string "~%Compile Time " (write-to-string (get-universal-time))
" Results:~%------------------------------------------------------~%"
(get-output-stream-string *error-output*)) "~%~%")))

;; --------------------------- CALL MAIN AND EXECUTE PROGRAM ----------------------------

;;; If main is specified outside of a function nothing is required here. If specified
;;; inside a function then call the function. Ex: (main).


Related Solutions

Write a LISP program to play the game Tic-Tac-Toe on a size 4x4 game board. Your...
Write a LISP program to play the game Tic-Tac-Toe on a size 4x4 game board. Your program must use min-max search and should be invoked by the function call: > (Tic-Tac-Toe) The game is single player, human vs the computer AI.
Write a program in Basic to play the game of Nim with acom­puter.
Write a program in Basic to play the game of Nim with acom­puter.
Write a program where a user of this program will play a game in which he/she...
Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
IN C++ Write a program to play the Card Guessing Game. Your program must give the...
IN C++ Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. -Guess only the suit of the card. -Guess both the face value and suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
Write a program with at least 2 functions that play the game of “guess the number”...
Write a program with at least 2 functions that play the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. The program then displays the following: I have a number between 1 and 1000. Can you guess my number? Please type in your first guess. The player then types the first guess. The program then responds with one of the following: 1.      ...
Write a program to allow a user to play the game Hangman. DO NOT USE AN...
Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess. Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
The following is a C program that is a video game version of Connect 4. The...
The following is a C program that is a video game version of Connect 4. The code works fine as is now but I want to change the way you input which column you drop a disk into. Currently, you type in 1 and it goes into column 1. If you type in 6, it goes into column 6 and so on. But I want to make it so you input A or a, then it goes into column 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT