Home › Forums › General Chat › YESSSSSSSSSSSSSSSSSSSSSSS
- This topic has 22 replies, 14 voices, and was last updated 15 years ago by
tarheel91.
-
AuthorPosts
-
31 March 2009 at 00:44 #2807
David
ParticipantFINALLY, AFTER ALL THIS WHILE, FINALLY FIXED IT.
I just wanna post this for no reason whatsoever, if you’re learning Java, you should know this. It’s the basic stuff! OMG, TOOK ME 30 MINUTES TO SCRIPT THIS. T___T I SUCK.
Script said:
/*
* File: StoneMasonKarel.java
* ————————–
* Cleans any world with rows that has spaces of 4.
* Repairs the stones where needed.
* Written by David G.
*/
import stanford.karel.*;public class StoneMasonKarel extends SuperKarel {
/*
* Start code, run defines the entire process. Repeats 5 times
*/
public void run() {
while (frontIsClear()) {
cleanWorld();
}
}private void cleanWorld() {
if (facingEast()) {
cleanWestRow();
}
if (facingWest()) {
cleanEastRow();
}
}
/*
* Cleans the entire row.
*/
private void cleanWestRow() {
while (frontIsClear()) {
placeBeeper();
}
if (frontIsBlocked()) {
turnLeft();
checkWall();
move();
goLeft();
}
}
/*
* Puts a beeper if no beeper is present
*/
private void placeBeeper() {
if (noBeepersPresent()) {
putBeeper();
} else {
moveFour();
doubleBeeper();
}
}private void doubleBeeper() {
if (noBeepersPresent()) {
putBeeper();
}
}
/*
* Moves four spaces to avoid long code
*/
private void moveFour() {
move();
move();
move();
move();
}private void cleanEastRow() {
while (frontIsClear()) {
placeBeeper();
}
if (frontIsBlocked()) {
turnRight();
checkWall();
move();
goRight();
}
}private void goRight() {
if (noBeepersPresent()) {
putBeeper();
turnRight();
} else {
turnRight();
}
}private void goLeft() {
if (noBeepersPresent()) {
putBeeper();
turnLeft();
} else {
turnLeft();
}
}private void checkWall() {
if (frontIsBlocked()) {
turnAround();
}
}
}Ew. It looks messy because tabs don’t work. :3
Video of what it does coming soon. :3
EDIT: Uploaded, might be processing.
Problem definition:
Karel has been hired to repair the damage done to the Quad in the 1989 earthquake. In
particular, Karel is to repair a set of arches where some of the stones (represented by
beepers, of course) are missing from the columns supporting the arches.
Your program should work on the world shown above, but it should be general enough to
handle any world that meets certain basic conditions as outlined at the end of this
problem. There are several example worlds in the starter folder, and your program should
work correctly with all of them.
When Karel is done, the missing stones in the columns should be replaced by beepers, so
that the final picture resulting from the world shown above would look like complete arches.Karel may count on the following facts about the world:
• Karel starts at 1st Avenue and 1st Street, facing east, with an infinite number of
beepers.
• The columns are exactly four units apart, on 1st, 5th, 9th Avenue, and so forth.
• The end of the columns is marked by a wall immediately after the final column. This
wall section appears after 13th Avenue in the example, but your program should work
for any number of columns.
• The top of the column is marked by a wall, but Karel cannot assume that columns are
always five units high, or even that all columns are the same height.
• Some of the corners in the column may already contain beepers representing stones31 March 2009 at 00:48 #6821Nass
Participant*victory music*
Level Up!
31 March 2009 at 00:58 #6822David
ParticipantUploaded video. 😀 Might be processing.
Moving on to Java.
31 March 2009 at 01:22 #6823SilverFx
Participant*blink* That’s cool. If I knew what it meant. XD
31 March 2009 at 01:23 #6825David
ParticipantJust look at the video. =) It matches up evenly I think… ;-;
31 March 2009 at 01:24 #6826SilverFx
ParticipantI know, I’ve watched the video. So it.. goes around placing.. diamonds on .. empty spaces..? *Squints*
31 March 2009 at 01:26 #6829David
ParticipantRawr. Yeah. It checks if there’s a Beeper present, if there is, it places a beeper, then moves 4 spaces.
It also checks if the walls are blocking it, if it they are, he either turns around and goes for the next row, or just stop entirely because both his top and bottom are blocked.
o.O Hope that made sense.
31 March 2009 at 01:29 #6831SilverFx
ParticipantOh. ^_^; Yeah, that made sense. It’s just a coding exercise, I gather?
31 March 2009 at 01:31 #6832David
ParticipantYep. There was also a contest to see if you can do mundane stuff, but in an extraordinary way, sort of like a Rube Goldberg Machine. 😉
So for example, the task would be to carry a stone from Point A to Point C, but instead, you make the robot jump over invisible hurdles before doing so, and not just in a set world, but in any general world.
So math gets in the way sometimes. XD
31 March 2009 at 01:48 #6833SilverFx
ParticipantI see. I love Rube Goldberg Machines 😀
^_^
31 March 2009 at 02:06 #6834Aaron
Participant@Silver: THAT WUZ AWSUM!
Wish I knew how to Java….
31 March 2009 at 03:34 #6846FunnyFroggy
Participantlul your Karel looks like some old version or something. o_O
31 March 2009 at 05:03 #6853MasterCheeze
ParticipantI don’t see a whale anywhere. What gives?
31 March 2009 at 06:32 #6868Ezyan
Participant…lol I remember now why I can’t code.
^__________^
31 March 2009 at 14:14 #6888Blackboy0
ParticipantCongrats David. That’s more than I can do in Java 😛 Just learning it though…
I’m more into C++ and Python, since WoW servers need ’em to run 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.