Hướng Dẫn Nghiên Cứu Trường Hợp GridWorld Trong Lập Trình Máy Tính

Tài liệu nghiên cứu 5886 2 computer science pp ii 76 indd, tổng hợp lý thuyết và thực hành, cung cấp kiến thức chuyên sâu về ., phục vụ nghiên cứu và ứng dụng thực tiễn

Trường đại học

San Jose State University

Chuyên ngành

Computer Science

Người đăng

Ẩn danh

Thể loại

Professional Development Workshop Materials

2007-2008

80
1
0

Phí lưu trữ

30 Point

Mục lục chi tiết

Table of Contents

1. I. “Content-Enrichment” Articles

1.1. A. The Design of the GridWorld Case Study

1.2. Instructional Units/Lessons

1.2.1. A. Early Exercises with GridWorld

1.2.2. Board Game Projects

1.2.3. Ant Farm Project

1.2.4. Save My Heart

1.3. About the Authors

2. Introduction

3. Special Focus: GridWorld Case Study

3.1. The Design of the GridWorld Case Study

3.1.1. Abstract

3.1.2. A Brief History of GridWorld

3.1.3. Design Decisions

3.1.3.1. Actors Store Their Location
3.1.3.2. The Out-Of-Subset instanceof Operator
3.1.3.3. Grid Types are Generic
3.1.3.4. No Direction class
3.1.3.5. Eight neighbors
3.1.3.6. No Random Singleton
3.1.3.7. You Can’t Save the World
3.1.3.8. Actors Are Concrete
3.1.3.9. Critter Methods Have Restrictive Postconditions

3.1.4. Under the Hood

3.1.4.1. How a World Is Displayed
3.1.4.2. How Grid Occupants Are Painted

Tóm tắt

I. Hướng Dẫn Nghiên Cứu Trường Hợp GridWorld Trong Lập Trình Máy Tính

Nghiên cứu trường hợp GridWorld là một phần quan trọng trong chương trình AP® Computer Science. Nó cung cấp một môi trường đồ họa cho phép sinh viên thực nghiệm với các loại đối tượng khác nhau. Bài viết này sẽ hướng dẫn chi tiết về cách nghiên cứu và áp dụng GridWorld trong lập trình máy tính.

1.1. Tổng Quan Về GridWorld Và Lập Trình Máy Tính

GridWorld là một mô hình học tập giúp sinh viên hiểu rõ hơn về lập trình máy tính. Nó cho phép sinh viên tương tác với các đối tượng trong một lưới, từ đó quan sát cách mà các thay đổi trong mã lập trình ảnh hưởng đến hành vi của các đối tượng.

1.2. Tại Sao Nên Nghiên Cứu GridWorld

Nghiên cứu GridWorld giúp sinh viên phát triển kỹ năng lập trình và tư duy phản biện. Nó cũng giúp sinh viên làm quen với các khái niệm như thuật toán tìm kiếm và mô hình hóa môi trường.

II. Những Thách Thức Khi Nghiên Cứu GridWorld Trong Lập Trình

Mặc dù GridWorld mang lại nhiều lợi ích, nhưng cũng tồn tại một số thách thức trong quá trình nghiên cứu. Việc hiểu rõ các khái niệm cơ bản và cách thức hoạt động của GridWorld là rất quan trọng.

2.1. Khó Khăn Trong Việc Hiểu Các Đối Tượng

Một trong những thách thức lớn nhất là việc sinh viên có thể gặp khó khăn trong việc hiểu cách mà các đối tượng tương tác với nhau trong GridWorld. Điều này đòi hỏi sinh viên phải có kiến thức vững về lập trình hướng đối tượng.

2.2. Vấn Đề Về Tính Tương Tác Giữa Các Đối Tượng

Tính tương tác giữa các đối tượng trong GridWorld có thể gây khó khăn cho sinh viên. Việc lập trình các hành vi phức tạp cho các đối tượng yêu cầu sinh viên phải có khả năng tư duy logic và giải quyết vấn đề.

III. Phương Pháp Nghiên Cứu GridWorld Hiệu Quả

Để nghiên cứu GridWorld một cách hiệu quả, sinh viên cần áp dụng một số phương pháp nhất định. Những phương pháp này sẽ giúp tối ưu hóa quá trình học tập và nghiên cứu.

3.1. Sử Dụng Tài Nguyên Học Tập Đầy Đủ

Việc sử dụng tài nguyên học tập như sách, video hướng dẫn và tài liệu trực tuyến sẽ giúp sinh viên nắm vững các khái niệm trong GridWorld. Các tài liệu này cung cấp thông tin chi tiết về cách hoạt động của GridWorld và các thuật toán liên quan.

3.2. Thực Hành Thông Qua Các Dự Án Thực Tế

Thực hành thông qua các dự án thực tế là một cách tuyệt vời để củng cố kiến thức. Sinh viên có thể tạo ra các trò chơi hoặc mô phỏng dựa trên GridWorld để áp dụng những gì đã học.

IV. Ứng Dụng Thực Tiễn Của GridWorld Trong Lập Trình

GridWorld không chỉ là một công cụ học tập mà còn có nhiều ứng dụng thực tiễn trong lập trình máy tính. Việc áp dụng GridWorld có thể giúp sinh viên phát triển các kỹ năng cần thiết cho sự nghiệp tương lai.

4.1. Phát Triển Kỹ Năng Lập Trình Hướng Đối Tượng

GridWorld giúp sinh viên phát triển kỹ năng lập trình hướng đối tượng, một trong những kỹ năng quan trọng trong ngành công nghệ thông tin. Sinh viên sẽ học cách tạo ra và quản lý các đối tượng trong một môi trường lập trình.

4.2. Ứng Dụng Trong Các Dự Án Lập Trình Thực Tế

Nhiều dự án lập trình thực tế có thể được phát triển dựa trên mô hình GridWorld. Điều này không chỉ giúp sinh viên áp dụng kiến thức mà còn tạo ra các sản phẩm có giá trị thực tiễn.

V. Kết Luận Về Nghiên Cứu GridWorld Trong Lập Trình Máy Tính

Nghiên cứu GridWorld là một phần quan trọng trong việc học lập trình máy tính. Nó không chỉ giúp sinh viên nắm vững các khái niệm cơ bản mà còn phát triển các kỹ năng cần thiết cho sự nghiệp tương lai.

5.1. Tương Lai Của GridWorld Trong Giáo Dục

GridWorld sẽ tiếp tục đóng vai trò quan trọng trong giáo dục lập trình máy tính. Với sự phát triển của công nghệ, GridWorld có thể được cải tiến để đáp ứng nhu cầu học tập của sinh viên.

5.2. Khuyến Khích Sinh Viên Khám Phá Thêm

Khuyến khích sinh viên khám phá thêm về GridWorld và các ứng dụng của nó trong lập trình sẽ giúp họ phát triển tư duy sáng tạo và khả năng giải quyết vấn đề.

24/07/2025

Trích đoạn nội dung tài liệu

AP ® Computer Science 2007–2008 Professional Development Workshop Materials Special Focus: GridWorld Case Study The College Board: Connecting Students to College Success The College Board is a not-for-profit membership association whose mission is to connect students to college success and opportunity. Founded in 1900, the association is composed of more than 5,000 schools, colleges, universities, and other educational organizations. Each year, the College Board serves seven million students and their parents, 23,000 high schools, and 3,500 colleges through major programs and services in college admissions, guidance, assessment, financial aid, enrollment, and teaching and learning. Among its best-known programs are the SAT®, the PSAT/ NMSQT®, and the Advanced Placement Program® (AP®).

The College Board is committed to the principles of excellence and equity, and that commitment is embodied in all of its programs, services, activities, and concerns. For further information, visit www. © 2007 The College Board. All rights reserved.

College Board, Advanced Placement Program, AP, AP Central, AP Vertical Teams, Pre-AP, SAT, and the acorn logo are registered trademarks of the College Board. AP Potential and connect to college success are trademarks owned by the College Board. All other products and services may be trademarks of their respective owners. Visit the College Board on the Web: www.

ii Table of Contents AP® Computer Science Special Focus Materials for 2007–08 GridWorld Case Study Table of Contents I. “Content-Enrichment” Articles A. The Design of the GridWorld Case Study. Instructional Units/Lessons A.

Early Exercises with GridWorld. Board Game Projects. Ant Farm Project. Save My Heart.

About the Authors .75 1 Introduction Introduction Debbie Carter, editor Lancaster Country Day School Lancaster, Pennsylvania Starting with the 2007–08 academic year, a new case study based on a grid—called “GridWorld”—will be a required part of the AP® Computer Science A and AB curricula. GridWorld provides a graphical environment in which students can experiment with different types of objects, observing the ways in which programming changes affect the objects’ behavior. Questions related to this case study will first appear on the 2008 AP Computer Science Exams. (AP Computer Science Newsletter, No.

We have commissioned a group of articles and instructional materials to help you prepare to use the GridWorld case study to teach computer science. Those of us who are familiar with the Marine Biology Simulation (MBS), the previous AP Computer Science case study, will find some familiar features in GridWorld. As Cay Horstmann explains in his article, “The Design of the GridWorld Case Study,” GridWorld’s design grew from what we learned from our experiences with the MBS in the classroom. We wanted more flexibility in the types of objects that could populate the world, as well as in the ways that they could be displayed.

An object in the world can • be displayed using an external graphic or via a graphics display class; • examine a list of other objects in the world and respond to one or more of them; • behave independently of other objects (or not at all). In “Integrating GridWorld,” Jill Kaminski gives us both an overview and some detailed practical advice about how we might effectively weave the case study throughout our AP Computer Science courses. Four additional authors, all computer science educators, have contributed hands-on instructional materials, with complete solutions, descriptions of teaching strategies, and suggestions for differentiation for students of varying needs. I would like to thank the contributors for their hard work and cooperation, as well as their continuing commitment to the AP Computer Science community.

We know that you’ll find many treasures in the next several pages, ready to be used to excite your AP Computer Science students! 3 Special Focus: GridWorld Case Study References College Board. AP Computer Science Course Description, May 2007, May 2008. AP Computer Science A and AB Newsletter.com/email/ap_compsci_n8490.html 4 The Design of the GridWorld Case Study The Design of the GridWorld Case Study Cay S. Horstmann San Jose State University San Jose, California Abstract In this article, I describe the rationale behind decisions that were made in the design of the GridWorld case study.

Knowing about these decisions can be useful to address student questions, or simply to satisfy your own curiosity. I also give information about the inner workings of the GUI that is helpful for designing your own worlds. A Brief History of GridWorld In 2004, the AP Computer Science Development Committee solicited proposals for a new case study. The committee received a number of interesting suggestions, but none of them had the flexibility of the Marine Biology Simulation (MBS) case study for producing exam questions.

Instead, we decided to make the MBS code more generic, to easily handle creatures other than fish, and to remove inessential classes. The redesign was governed by four themes: • Continuity. Teachers who are familiar with MBS should feel right at home in GridWorld. Students who see GridWorld for the first time should not be overwhelmed.

The framework should give rise to many kinds of exam questions. Enthusiasts should be able to design grid-based games, mazes, puzzles, simulations, and so on, without GUI programming. The first prototype of GridWorld appeared in March 2005. It consisted of the MBS code, with one important change—the ability to add GIF images instead of having to use Java graphics for drawing occupants.

It turns out that this ability was already present in the MBS GUI code, but it was well hidden. Figure 1 shows the very first GridWorld screen capture; note the cuddly critter and the frame title. The next months were the “Cambrian explosion” of GridWorld, with numerous exotic life forms appearing rapidly: rock hounds that search for rocks by recursively asking their neighbors, robots that drop flowers, potato-shaped cells, flocks of “boids,” and aliens. They became extinct, to be replaced with the bugs and critters that we know today.

5 Special Focus: GridWorld Case Study Figure 1—First GridWorld screen capture. The other major innovation was the direct manipulation interface that allows students to invoke constructors and methods. I had always admired this capability in BlueJ and experimented with controlling grid occupants from the BlueJ workbench. That proved too cumbersome, and I ended up implementing direct manipulation inside GridWorld.

Figure 2 shows another historic first—the first screen capture of the method menu. Note the method names and parameters! Figure 2—First screen capture of the method menu. 6 The Design of the GridWorld Case Study Chris Nevison and Barbara Cloud Wells joined in September 2005 to produce the narrative. They invented the crab and chameleon critters that show off the template method pattern.

Shortly after the narrative was released, we were delighted to receive a beautiful set of icons from Chris Renard, a student at the School for the Talented and Gifted of the Dallas Independent School District. The design of GridWorld has now been finalized, and the case study is ready for use in the 2007–08 school year. In this article, I will discuss some of the design decisions behind GridWorld and give tips for advanced users. Design Decisions In this section, I discuss some of the design decisions that were made during the development of GridWorld.

You may disagree with some decisions; some of your colleagues have done so rather vocally. You may want to discuss the pros and cons of some decisions with your class. Actors Store Their Location The MBS case study used an Environment that holds Locatable objects. This proved to be restrictive when writing exam questions.

We decided that we wanted a grid that can hold objects of any type. That means that the grid cannot ensure that the grid location and the occupant location are synchronized—the grid doesn’t know whether its occupants have locations. We attempted to solve this problem in an ingenious way, by passing the current location to the act method. public void act(Location loc, Grid<E> gr) The actors didn’t have to remember their location; the world reminded them.

Unfortunately, the location and grid ended up being passed into many other helper methods, leading to tedious code. In the end, we settled for actors that store their location, and supplied the putSelfInGrid and removeSelfFromGrid methods for synchronizing the actor and grid locations. As your students will undoubtedly find out, the put and remove methods of the Grid interface do not work for actors. The actors will throw exceptions when they find that their locations are not properly set.

The Out-Of-Subset instanceof Operator The instanceof operator is not in the AP Java subset, but it is used to sense the type of actors that are being processed. For example, a bug decides that it can move to a location by testing (neighbor == null) || (neighbor instanceof Flower) 7 Special Focus: GridWorld Case Study Going beyond the AP Java subset for the case study has precedent. The MBS case study used the protected modifier that is not in the subset. Nevertheless, it is not an ideal situation, and we explored alternatives.

Unfortunately, all of the alternatives required students to write code that was more cumbersome than the instanceof test. There is no point in making students learn cumbersome custom code when they could instead learn a Java feature. Note that we use the instanceof test in its most benign form, without the dreaded cast. That is, we do not have code of the form if (myActor instanceof Critter) { Critter myCritter = (Critter) myActor; //we don’t do in //GridWorld.

} Will other GridWorld users exhibit the same good taste and restraint? Only time will tell. Grid Types are Generic In the AB course, students look at the Grid interface and the AbstractGrid, BoundedGrid, and UnboundedGrid classes. They will see implementations of generic types, even though the implementation of generic types is not currently in the AP Java subset. In the A course, of course, there is no problem.

Students use Grid<E> much like ArrayList<E>. An old-style Grid that stores Object references requires unsightly casts. We felt that this advantage outweighed the slight complexity of type variables in the AB course. No Direction class The MBS case study had a Direction class for compass directions such as Direction.

The class had few interesting methods, and we eliminated it to minimize the number of classes that students see when they encounter GridWorld for the first time. Now the constants are placed in the Location class, which is admittedly not optimal. Eight neighbors A location in the grid has eight neighbors. In contrast, the MBS environment could be configured so that a location had four or eight neighbors, and some people even produced triangular or hexagonal grids.

This led to cumbersome exam questions since we always had to be explicit about the number of neighbors. We decided that hexagonal grids were cute but not useful enough to pay for the added complexity. 8 The Design of the GridWorld Case Study No Random Singleton Naive users often try to generate random numbers like this: int r = new Random().nextInt(n); // DON’T DO THAT! However, constructing many random number generators will lead to poorly distributed random numbers. The MBS case study had its own provider for a singleton random generator.

That is the right design if you are serious about controlling random number generation. In the context of the MBS narrative, it made sense to have repeatable sequences of pseudo-random numbers. However, the subtleties of random number generation are clearly not a central part of the AP Computer Science curriculum. In GridWorld, we simply generate random numbers with the call int r = (int) (n * Math.random()); You Can’t Save the World The MBS case study had a mechanism for saving and reloading simulation data, in files with contents such as bounded 7 5 Fish 3 2 North In GridWorld, that’s a lot harder since grid occupants can be arbitrary objects.

I solved the problem by using the XML file format for a specialized Java feature called “long-term beans persistence.” However, that led to a harder problem.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ