




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from a computer science course for engineers, focusing on linear search, binary search, and selection sort algorithms used in a shark and goldfish simulator project. Function definitions, project details, and explanations of the sorting algorithms. Students are expected to form teams, implement functions, and complete the project by a certain deadline.
Typology: Study Guides, Projects, Research
1 / 8
This page cannot be seen from the preview
Don't miss anything!





%Make the board. Make the shark and position the shark. %Calls play and makeBoard function [] = startShark(rows, cols) %Recursive function that implements top-level algorithm. %oldShark is a shark with the previous position. %Calls: print, plotBoard, getClosestGoldfish, moveToGoldfish, eatGoldfish function [] = play(board, shark, oldShark) %Goldfish disappears from board, shark moves into former goldfish location. %Calls: function [newBoard newShark] = eatGoldfish(board, goldfishCoords, shark) %Prints an ascii version of board at interpreter prompt, showing all %simulated items. function [] = print(board, shark) %Plots board, showing all simulated items. %Calls: plotSquare function [] = plotBoard(board, shark, oldShark)
%Plots a single square on board. %Calls: patch function [] = plotSquare(row, col, color) %Shark moves one square at a time, horizontally or vertically, until %shark is adjacent to goldfish. Returns updated copy of shark. %Calls: isAdjacent, moveOneSquare, print, plotBoard function newShark = moveToGoldfish(board, goldfishCoords, shark) %Move shark one square closer to coords. New shark location must be a %legal, unoccupied square. %Calls: isLegalMove function [canMove newShark] = moveOneSquare(board, coords, shark) %Returns true iff board is empty at proposed position and position is %valid for this board. %Calls: function legal = isLegalMove(board, proposedMove)