Luet oppimateriaalin englanninkielistä versiota. Mainitsit kuitenkin taustakyselyssä osaavasi suomea. Siksi suosittelemme, että käytät suomenkielistä versiota, joka on testatumpi ja hieman laajempi ja muutenkin mukava.
Suomenkielinen materiaali kyllä esittelee englanninkielisetkin termit. Myös suomenkielisessä materiaalissa käytetään ohjelmaprojektien koodissa englanninkielisiä nimiä kurssin alkupään johdantoesimerkkejä lukuunottamatta.
Voit vaihtaa kieltä A+:n valikon yläreunassa olevasta painikkeesta. Tai tästä: Vaihda suomeksi.
Chapter 8.1: Robots
About This Page
Questions Answered: Can I apply what I’ve learned on a larger program?
Topics: A particular simulator app. There are no new topics per se, but we will discuss a program that is more complex than any of the previous ones.
What Will I Do? Program.
Rough Estimate of Workload:? A couple of hours?
Points Available: B50.
Related Projects: Robots (new).
Much of Week 8 revolves around a programming assignment in which you construct a robot simulator. In this simulator, a “robot world” is essentially a grid where “robots” of very little brain conduct their virtual existence.
Before we get started in earnest, let’s form an overview of the project that you’ll be working on.
The Robots Project
The Robots project contains two packages. The classes in
o1.robots constitute the
robot simulator’s internal model;
o1.robots.gui provides a user interface. The user
interface is ready for use as given and we won’t discuss it further here.
The following table briefly describes each of the simulator’s main components. Below the table, you’ll find a diagram of the components’ relationships.
||Represents pairs of coordinates. (Familiar from Chapter 6.3 and Week 7.)||ready|
||Represents grids in general. (Familiar from Week 7.)||ready|
||sealed abstract class
||Represents the main compass directions. There are exactly four instances of this class, which stand for north, east, south, and west. (Familiar from Chapter 6.3.)||ready|
||Represents the robots’ physical form. Each instance
||Represents the general properties of the robots’ “artificial intelligence”.||partially implemented|
||Represents a single square of a robot world in general terms.||ready|
||A subclass of
Part 0 of 10: Answer Some Questions
Before you go on
Try to get a general sense of the Robots project by reading the description above and the Scaladocs. Browse the source code, too.
Part 1 of 10: Fundamental Repairs to
You’ve been given a whole bunch of code, much of which works in principle, but the program is not ready to run. Eclipse spews a stream of errors.
RobotWorld has been only partially implemented. Fix it:
- The error messages indicate that
RobotWorlddoesn’t have the variables
heightas expected. It should inherit these methods from
Grid. Add an
extendsclause that makes
RobotWorlda subclass of
- You may wish to look at
GameBoardin the Viinaharava game for inspiration.
- Read the documentation carefully. Make sure you pass in the right numbers as constructor parameters to the superclass.
- Once you’re done with this step, try launching
the program via
o1.robots.gui.RobotApp. You should see a robot world that’s completely dark.
- Be sure to give
Gridthe type parameter it needs. (If you receive error messages that feature
Nothingas the type of the grid’s squares, you probably overlooked this.)
- You may wish to look at
- Repair the
initialSquare, which now fills the entire world with walls. The method is private and not detailed in the Scaladocs, but there’s a comment in the given code that explains what it should do: put walls on the edges and floors in the middle.
- That is, you’ll need to check the coordinates
to determine whether you should create a
Flooror use a reference to the
- That is, you’ll need to check the coordinates to determine whether you should create a
- Relaunch the application. You should be able to create empty robot worlds, but clicking the floor squares won’t let you add robots or walls.
Part 2 of 10: Adding Content
- Implement the
- Hint: use
- Hint: use
- Run the program again and try right-clicking floors to add walls.
addRobotin the same class.
- Note that
addRobotneeds to handle several interrelated subtasks. Make sure you attend to each of the things mentioned in the Scaladoc.
- Note that
- Try adding
Spinbots in the GUI. They should appear in the robot world, but they don’t do anything yet. You can break them and repair them, though.
Use this form to submit your solution to Parts 1 and 2.
A+ presents the exercise submission form here.
The assignment continues in upcoming chapters.
Please note that this section must be completed individually. Even if you worked on this chapter with a pair, each of you should submit the form separately.
Thousands of students have given feedback that has contributed to this ebook’s design. Thank you!
Weeks 1 to 13 of the ebook, including the assignments and weekly bulletins, have been written in Finnish and translated into English by Juha Sorva.
Weeks 14 to 20 are by Otto Seppälä. That part of the ebook isn’t available during the fall term, but we’ll publish it when it’s time.
The automatic assessment of the assignments has been developed by: (in alphabetical order) Riku Autio, Nikolas Drosdek, Joonatan Honkamaa, Jaakko Kantojärvi, Niklas Kröger, Teemu Lehtinen, Strasdosky Otewa, Timi Seppälä, Teemu Sirkiä, and Aleksi Vartiainen.
The illustrations at the top of each chapter, and the similar drawings elsewhere in the ebook, are the work of Christina Lassheikki.
The animations that detail the execution Scala programs have been designed by Juha Sorva and Teemu Sirkiä. Teemu Sirkiä and Riku Autio have done the technical implementation, relying on Teemu’s Jsvee and Kelmu toolkits.
The other diagrams and interactive presentations in the ebook are by Juha Sorva.
The pedagogy behind O1Library’s tools for simple graphical programming (such as
is inspired by the textbooks How to Design Programs by Flatt, Felleisen, Findler, and
Krishnamurthi and Picturing Programs by Stephen Bloch.
The course platform A+ has been created by Aalto’s LeTech research group and is largely developed by students. The current lead developer is Jaakko Kantojärvi; many other students of computer science and information networks are also active on the project.
For O1’s current teaching staff, please see Chapter 1.1.
Additional credits appear at the ends of some chapters.