시뮬레이티드 세계(Simulated World)의 구현과 문제점
暂无分享,去创建一个
In this assignment you will work in pairs to simulate critters that behave according to some well-defined set of instructions. Your task consists of three components. First, you will write a simple interpreter that reads a set of instructions and performs the appropriate behavior for one critter. Second, you will create a test harness and explain how you used it to test your interpreter. Third, you will design and submit one critter to participate in the annual CritterFest competition. Each team needs to submit one critter by the due date, but you will have additional time to revise your critters before the actual competition (we will provide details about the contest later). This assignment requires a bit more code than the previous ones, so we suggest that you develop and test your code in pieces to minimize debugging time. We strongly encourage you to read the submission directions carefully before you start working. The simulated world is a 2D grid of squares, where each square can hold one critter. Each critter has a graphical representation , has a heading, belongs to a particular species, and behaves according to a set of species-specific instructions. After some random initial placement of critters, each critter takes a turn at performing some actions, such as moving to another square or eating another critter. A heading is the direction a critter is facing. A bearing is an angular difference between two headings, measured in degrees clockwise. An enemy of a critter is any critter of a different species. An ally of a critter is any critter of the same species. A behavior file is a file that contains the specification of a critter species' behavior. Similarly, the behavior code is the set of instructions in a behavior file that controls the species' behavior. A register is one of ten registers, named r1 though r10, that can hold an integral value. Note: If you do not name your registers as specified, your program will be incorrect. In particular, the r is part of the register name. The behavior of each species is defined by a simple program that consists of the following instructions. hop The critter moves forward if the square that it's facing is empty. left The critter turns left 45 degrees to face a new direction. right The critter turns right 45 degrees to face a new direction. infect n If the square immediately …