View on GitHub

Chess-mates-josh-and-connor-

Download this project as a .zip file Download this project as a tar.gz file

FP7-ChessNuts

Authors

Conor Finegan and Joshua Blanchette

Overview

Conor and I have recreated the classic game of Chess. We as a team have incorporated a stable, high-performing back end and a visually appealing UI.

Screenshot

Here is a screenshot of our chessboard.

alt-tag

Concepts Demonstrated

Chess is a highly stateful game, therefor our project is very object-oriented. The pieces, tiles, and board are all seperated into classes. High-order procedures like map and filter were very helpful when trying to find the valid moves that a piece can make.

External Technology and Libraries

We imported various sprite images to use for our pieces. We used two libraries throughout our project, racket/GUI and racket/Draw. Racket/GUI and racket/Draw to create the chessboard and instantiate the window, and racket/draw again to draw the Chess pieces.

Favorite Scheme Expressions

Josh

The code linked below is my favorite scheme expression. It's so simple, yet it embodies almost all of the mobility of a pawn. A pawn can move up two tiles if it has not moved yet. So the code checks if the Y coordinate is equal to its start-y, and if it is, then it will allow the pawn to move two spaces. Again, so simple, yet creative.

; if y-pos = start-pos, then piece hasn't moved and allow double move
          (if (and (= y start-y)
                   (call (call board 'tile-at x (op y 1)) 'is-empty)
                   (call (call board 'tile-at x (op y 2)) 'is-empty))
              (set! moves (cons (call board 'tile-at x (op y 2)) moves))
              void)

Conor

I'm particularly proud of this procedure from `accum-tiles.rkt`, which is a 2-dimensional accumulate procedure that iterates over a matrix of tiles, saving valid moves until it reaches an obstical (or the end of the board). This function embodies the spirit of functional programming because it's a higher-order procedure that breaks down a complicated problem (accumulating moves for rook, bishop, and queen) into a simple solution that can be customized with different parameters.

;; baseline procedure for accumulating tiles with a given pattern
;; of transforming x and y. Respects line of sight, and makes
;; the distinction between a valid move onto an enemy tile and
;; an invalid move onto a friendly tile
(define (accum-tiles
         x-transform
         y-transform
         board
         start-tile
         team)
  
  (define (iter tile out-lst)
    (cond
      ; if tile is null or same team, return current list
      ((or (eq? tile '())
           (and (not (call tile 'is-empty))
                (eq? team (call (call tile 'get-piece) 'get-team))))
       out-lst)
      
      ; if tile contains enemy piece, return current list + current tile
      ((and (not (call tile 'is-empty))
            (not (eq? team (call (call tile 'get-piece) 'get-team))))
       (cons tile out-lst))
      
      ; otherwise store current tile and make recursive call
      (else
       (let ((x (call tile 'get-x))
             (y (call tile 'get-y)))
         (iter (call board 'tile-at (x-transform x) (y-transform y))
               (cons tile out-lst))))))
  
  ; baseline call to iter, starts with
  ; a transform because the start tile
  ; is not considered to be a valid move
  (let ((x (call start-tile 'get-x))
        (y (call start-tile 'get-y)))
    (iter (call board 'tile-at (x-transform x) (y-transform y))
          '())))

How to Download and Run

To open ChessNuts, download the zip file at the top of this page and run src/main.rkt. Use left click to select/move a piece, and right click to cancel a selection.