CMU 15-112: Fundamentals of Programming and Computer Science
Week 5 Practice (Due never)


Worked Examples:
  1. Word Search
  2. Word Search Redux
  3. Connect4
  4. Othello

Free Response (Problem Solving) - Lists

  1. makeMagicSquare(n)
    Write the function makeMagicSquare(n) that takes a positive odd integer n and returns an nxn magic square by following De La Loubere's Method as described here. If n is not a positive odd integer, return None.

  2. isLatinSquare(a)
    Write the function isLatinSquare(a) that takes a 2d list and returns True if it is a Latin square and False otherwise.

  3. nQueensChecker(a)
    Background: The "N Queens" problem asks if we can place N queens on an NxN chessboard such that no two queens are attacking each other. For most values of N, there are many ways to solve this problem. Here, you will write the function nQueensChecker(board) that takes a 2d list of booleans where True indicates a queen is present and False indicates a blank cell, and returns True if this NxN board contains N queens all of which do not attack any others, and False otherwise.

  4. makeOthelloMove(board, row, col, player)
    Background: read about the game of Othello (also known as Reversi).  Maybe even play it briefly (say, here).  We can represent an Othello board as an NxN list of values -- 'w' for white, 'b' for black, and the empty string for empty (of course).  If we number the rows from the top and columns from the left, write the function makeOthelloMove(board, row, col, player) that takes such a board, a row, a col, and a player ('w' or 'b'), and, if it is legal for the given player to place a piece at the given position, the function destructively modifies the board to reflect this move (flipping pieces as needed), and it returns the number of pieces flipped.  If the move is not legal, the function does not modify the board and returns 0.

Free Response (Problem Solving) - Animation

  1. runDotsAndBoxes
    First, read the Wikipedia page on Dots and Boxes. Then, write the function runDotsAndBoxes(rows, cols, maxSecondsPerTurn) which will play a human-human Dots and Boxes game on a rows x cols board, but also not allowing more than maxSecondsPerTurn time to elapse on any give turn. If the time elapses, the screen should visibly flash and the player should lose that turn (though not the game). Your user interface can be simple, even quite plain, but it should be functional so two people can use it to play. It must display the board, make clear whose turn it is and where legal moves are, make it easy for players to enter moves, actually make those moves if legal (or reject them if illegal), display who has captured which boxes, alternate turns, display the score, detect game over, and print a suitable game over message. Don't forget about the maximum time per turn, too!

  2. Clicker Game
    Feel like tackling something more complex? Check out the clicker game from Fall 2018 HW6! Since it's not a homework assignment, you can decide how many features you want to implement. This is great practice for MVC, scrolling, 2D lists, and time-based animation. Check the link for more details, or watch the video overview below.




Even more animation!
Creating basic arcade or mobile games is an excellent way to practice time-based animation. These can include:

  1. Bejeweled
  2. Flappy Bird
  3. Agar.io
  4. Pong
  5. Frogger
  6. Breakout
  7. More here and here